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', () => { this.ckEditorInstance.model.document.on('change:data', () => {
const differ = this.ckEditorInstance.model.document.differ const differ = this.ckEditorInstance.model.document.differ
const changes = Array.from(differ.getChanges()) 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) { for (const entry of changes) {
if (entry.type === 'insert' || entry.type === 'remove') { if (entry.type === 'insert' || entry.type === 'remove') {
const insertedElement = entry.name const insertedElement = entry.name
if (['paragraph', 'blockQuote'].includes(insertedElement)) { if (['paragraph', 'blockQuote'].includes(insertedElement)) {
if ( if (
entry.attributes.has('listIndent') || entry.attributes.has('listIndent') ||
@ -694,18 +692,10 @@ class BesCKService extends BesService {
} }
}) })
this.ckEditorInstance.commands.get('undo').on('execute', () => { this.ckEditorInstance.commands.get('undo').on('execute', () => {
this.clearAllMistakes(this.scrollPanel) this.handlePluginChanges()
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
}) })
this.ckEditorInstance.commands.get('redo').on('execute', () => { this.ckEditorInstance.commands.get('redo').on('execute', () => {
this.clearAllMistakes(this.scrollPanel) this.handlePluginChanges()
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
}) })
this.ckEditorInstance.commands.get('bold').on('execute', () => { this.ckEditorInstance.commands.get('bold').on('execute', () => {
setTimeout(() => { setTimeout(() => {
@ -720,32 +710,16 @@ class BesCKService extends BesService {
}, 500) }, 500)
}) })
this.ckEditorInstance.commands.get('indent').on('execute', () => { this.ckEditorInstance.commands.get('indent').on('execute', () => {
this.clearAllMistakes(this.scrollPanel) this.handlePluginChanges()
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
}) })
this.ckEditorInstance.commands.get('outdent').on('execute', () => { this.ckEditorInstance.commands.get('outdent').on('execute', () => {
this.clearAllMistakes(this.scrollPanel) this.handlePluginChanges()
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
}) })
this.ckEditorInstance.commands.get('numberedList').on('execute', () => { this.ckEditorInstance.commands.get('numberedList').on('execute', () => {
this.clearAllMistakes(this.scrollPanel) this.handlePluginChanges()
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
}) })
this.ckEditorInstance.commands.get('bulletedList').on('execute', () => { this.ckEditorInstance.commands.get('bulletedList').on('execute', () => {
this.clearAllMistakes(this.scrollPanel) this.handlePluginChanges()
this.clearChildren()
setTimeout(() => {
this.proof(hostElement)
}, 500)
}) })
} }
@ -771,10 +745,7 @@ class BesCKService extends BesService {
let blockElements = new Set() let blockElements = new Set()
event.getTargetRanges().forEach(range => { event.getTargetRanges().forEach(range => {
BesService.getNodesInRange(range).forEach(el => { BesService.getNodesInRange(range).forEach(el => {
if ( if (el === hostElement || hostElement?.contains(el)) {
el === hostElement ||
Array.from(hostElement.childNodes).includes(el)
) {
blockElements.add(service.getBlockParent(el)) blockElements.add(service.getBlockParent(el))
} }
}) })
@ -806,32 +777,13 @@ class BesCKService extends BesService {
this.children = [] this.children = []
} }
handleCKInput(hostElement, ckEditorInstance) { handlePluginChanges() {
let service = besServices.find(e => e.hostElement === hostElement) this.clearAllMistakes(this.scrollPanel)
if (!service) return this.clearChildren()
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)
})
setTimeout(() => { setTimeout(() => {
service.repositionMistakes() this.proof(this.hostElement)
}, 0) }, 500)
service.timer = setTimeout(function () {
service.abortController = new AbortController()
service.proof(hostElement)
}, 1000)
} }
/** /**
* This function disables the CKEditor spellcheck. * This function disables the CKEditor spellcheck.
* *