Improve event handling and refactor clear children in CKEditor

This commit is contained in:
Aljaž Grilc 2024-04-18 11:18:50 +02:00
parent 1e46ef97ea
commit 05b1b04012

View File

@ -695,12 +695,14 @@ class BesCKService extends BesService {
}) })
this.ckEditorInstance.commands.get('undo').on('execute', () => { this.ckEditorInstance.commands.get('undo').on('execute', () => {
this.clearAllMistakes(this.scrollPanel) this.clearAllMistakes(this.scrollPanel)
this.clearChildren()
setTimeout(() => { setTimeout(() => {
this.proof(hostElement) this.proof(hostElement)
}, 500) }, 500)
}) })
this.ckEditorInstance.commands.get('redo').on('execute', () => { this.ckEditorInstance.commands.get('redo').on('execute', () => {
this.clearAllMistakes(this.scrollPanel) this.clearAllMistakes(this.scrollPanel)
this.clearChildren()
setTimeout(() => { setTimeout(() => {
this.proof(hostElement) this.proof(hostElement)
}, 500) }, 500)
@ -717,6 +719,34 @@ class BesCKService extends BesService {
window.dispatchEvent(new Event('resize')) window.dispatchEvent(new Event('resize'))
}, 500) }, 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,11 +797,13 @@ class BesCKService extends BesService {
} }
clearAllMistakes(el) { clearAllMistakes(el) {
if (el.children.length) { while (el.firstChild) {
for (let i = 0; i < el.children.length; i++) { el.removeChild(el.firstChild)
el.children[i].remove()
} }
} }
clearChildren() {
this.children = []
} }
handleCKInput(hostElement, ckEditorInstance) { handleCKInput(hostElement, ckEditorInstance) {