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.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