From 05b1b0401297c4c59b4a49136ce4e2b9fea08d0b Mon Sep 17 00:00:00 2001 From: Aljaz Grilc Date: Thu, 18 Apr 2024 11:18:50 +0200 Subject: [PATCH] Improve event handling and refactor clear children in CKEditor --- service.js | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/service.js b/service.js index 95f3b1b..a12ed61 100644 --- a/service.js +++ b/service.js @@ -695,12 +695,14 @@ class BesCKService extends BesService { }) this.ckEditorInstance.commands.get('undo').on('execute', () => { this.clearAllMistakes(this.scrollPanel) + this.clearChildren() setTimeout(() => { this.proof(hostElement) }, 500) }) this.ckEditorInstance.commands.get('redo').on('execute', () => { this.clearAllMistakes(this.scrollPanel) + this.clearChildren() setTimeout(() => { this.proof(hostElement) }, 500) @@ -717,6 +719,34 @@ class BesCKService extends BesService { window.dispatchEvent(new Event('resize')) }, 500) }) + this.ckEditorInstance.commands.get('indent').on('execute', () => { + this.clearAllMistakes(this.scrollPanel) + this.clearChildren() + setTimeout(() => { + this.proof(hostElement) + }, 500) + }) + this.ckEditorInstance.commands.get('outdent').on('execute', () => { + this.clearAllMistakes(this.scrollPanel) + this.clearChildren() + setTimeout(() => { + this.proof(hostElement) + }, 500) + }) + this.ckEditorInstance.commands.get('numberedList').on('execute', () => { + this.clearAllMistakes(this.scrollPanel) + this.clearChildren() + setTimeout(() => { + this.proof(hostElement) + }, 500) + }) + this.ckEditorInstance.commands.get('bulletedList').on('execute', () => { + this.clearAllMistakes(this.scrollPanel) + this.clearChildren() + setTimeout(() => { + this.proof(hostElement) + }, 500) + }) } /** @@ -767,13 +797,15 @@ class BesCKService extends BesService { } clearAllMistakes(el) { - if (el.children.length) { - for (let i = 0; i < el.children.length; i++) { - el.children[i].remove() - } + while (el.firstChild) { + el.removeChild(el.firstChild) } } + clearChildren() { + this.children = [] + } + handleCKInput(hostElement, ckEditorInstance) { let service = besServices.find(e => e.hostElement === hostElement) if (!service) return