From c14294d80d6cacca6f9b5d1e772a80d5bc82a574 Mon Sep 17 00:00:00 2001 From: Aljaz Grilc Date: Tue, 6 Feb 2024 10:59:46 +0100 Subject: [PATCH] Add support for handling editor resize events --- online-editor.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/online-editor.js b/online-editor.js index db46215..aa166a9 100644 --- a/online-editor.js +++ b/online-editor.js @@ -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)