This commit is contained in:
Aljaž Grilc 2024-04-18 13:30:06 +02:00
parent 05b1b04012
commit b8dba4bba9

View File

@ -666,11 +666,9 @@ class BesCKService extends BesService {
this.ckEditorInstance.model.document.on('change:data', () => {
const differ = this.ckEditorInstance.model.document.differ
const changes = Array.from(differ.getChanges())
// TODO: Repostion mistakes after image is inserted (need some further research on this topic)
for (const entry of changes) {
if (entry.type === 'insert' || entry.type === 'remove') {
const insertedElement = entry.name
if (['paragraph', 'blockQuote'].includes(insertedElement)) {
if (
entry.attributes.has('listIndent') ||
@ -694,18 +692,10 @@ class BesCKService extends BesService {
}
})
this.ckEditorInstance.commands.get('undo').on('execute', () => {
this.clearAllMistakes(this.scrollPanel)
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
this.handlePluginChanges()
})
this.ckEditorInstance.commands.get('redo').on('execute', () => {
this.clearAllMistakes(this.scrollPanel)
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
this.handlePluginChanges()
})
this.ckEditorInstance.commands.get('bold').on('execute', () => {
setTimeout(() => {
@ -720,32 +710,16 @@ class BesCKService extends BesService {
}, 500)
})
this.ckEditorInstance.commands.get('indent').on('execute', () => {
this.clearAllMistakes(this.scrollPanel)
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
this.handlePluginChanges()
})
this.ckEditorInstance.commands.get('outdent').on('execute', () => {
this.clearAllMistakes(this.scrollPanel)
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
this.handlePluginChanges()
})
this.ckEditorInstance.commands.get('numberedList').on('execute', () => {
this.clearAllMistakes(this.scrollPanel)
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
this.handlePluginChanges()
})
this.ckEditorInstance.commands.get('bulletedList').on('execute', () => {
this.clearAllMistakes(this.scrollPanel)
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
this.handlePluginChanges()
})
}
@ -771,10 +745,7 @@ class BesCKService extends BesService {
let blockElements = new Set()
event.getTargetRanges().forEach(range => {
BesService.getNodesInRange(range).forEach(el => {
if (
el === hostElement ||
Array.from(hostElement.childNodes).includes(el)
) {
if (el === hostElement || hostElement?.contains(el)) {
blockElements.add(service.getBlockParent(el))
}
})
@ -806,32 +777,13 @@ class BesCKService extends BesService {
this.children = []
}
handleCKInput(hostElement, ckEditorInstance) {
let service = besServices.find(e => e.hostElement === hostElement)
if (!service) return
if (service.timer) clearTimeout(service.timer)
service.abortController.abort()
const root = ckEditorInstance.model.document.getRoot()
const blockElements = Array.from(root.getChildren())
blockElements.forEach(block => {
const viewElement =
this.ckEditorInstance.editing.mapper.toViewElement(block)
const domElement =
this.ckEditorInstance.editing.view.domConverter.mapViewToDom(
viewElement
)
service.clearMistakeMarkup(domElement)
service.removeChild(domElement)
})
handlePluginChanges() {
this.clearAllMistakes(this.scrollPanel)
this.clearChildren()
setTimeout(() => {
service.repositionMistakes()
}, 0)
service.timer = setTimeout(function () {
service.abortController = new AbortController()
service.proof(hostElement)
}, 1000)
this.proof(this.hostElement)
}, 500)
}
/**
* This function disables the CKEditor spellcheck.
*