Add support for handling editor resize events

This commit is contained in:
Aljaž Grilc 2024-02-06 10:59:46 +01:00
parent a9330e50b9
commit c14294d80d

View File

@ -8,16 +8,16 @@ window.onload = () => {
let editor = {
timer: null,
children: [
{
elements: null,
isProofed: false
// matches: [
// {
// range: null,
// rects: null
// }
// ]
}
// {
// elements: null,
// isProofed: false
// matches: [
// {
// range: null,
// rects: null
// }
// ]
// }
]
}
besEditors[edit.id] = editor
@ -28,7 +28,19 @@ window.onload = () => {
false
)
edit.addEventListener('click', e => besHandleClick(e, edit))
// TODO: Handle editor resizes.
})
}
window.onresize = () => {
Object.keys(besEditors).forEach(key => {
let editor = besEditors[key]
editor.children.forEach(child => {
besClearAllMistakes(child?.elements)
child.matches.forEach(match => {
const clientRect = besAddMistake(match.range, match.message)
match.rects = clientRect
})
})
})
}
@ -202,7 +214,7 @@ function besClearProofed(el) {
// Remove all grammar mistakes markup for given block element.
function besClearAllMistakes(el) {
if (el.id.startsWith('ed')) return
if (el?.id.startsWith('ed')) return
const editorId = el.parentElement.id
const editor = besEditors[editorId]
let filteredChildren = editor?.children.filter(child => child.elements === el)