Resolve issue with handling multiple mistakes in single CKEditor block element

This commit is contained in:
Aljaž Grilc 2024-04-04 14:19:31 +02:00
parent 3af7a4da63
commit ccbd80dcb7

View File

@ -717,7 +717,11 @@ class BesCKService extends BesService {
super.markProofed(el, matches) super.markProofed(el, matches)
// This is a solution for displaying mistakes in CKEditor. It is not the best solution, but it works for now. // This is a solution for displaying mistakes in CKEditor. It is not the best solution, but it works for now.
if (this.ckEditorInstance) window.dispatchEvent(new Event('resize')) if (this.ckEditorInstance) {
setTimeout(() => {
window.dispatchEvent(new Event('resize'))
}, 100)
}
} }
/** /**
@ -751,13 +755,13 @@ class BesCKService extends BesService {
match.range match.range
) )
const modelRange = ckEditorInstance.editing.mapper.toModelRange(viewRange) const modelRange = ckEditorInstance.editing.mapper.toModelRange(viewRange)
this.clearMistakeMarkup(el)
ckEditorInstance.model.change(writer => { ckEditorInstance.model.change(writer => {
const attributes = const attributes =
ckEditorInstance.model.document.selection.getAttributes() ckEditorInstance.model.document.selection.getAttributes()
writer.remove(modelRange) writer.remove(modelRange)
writer.insertText(replacement, attributes, modelRange.start) writer.insertText(replacement, attributes, modelRange.start)
}) })
this.clearMistakeMarkup(el)
// In my opinion, this approach provides the most straightforward solution for repositioning mistakes after a change. // In my opinion, this approach provides the most straightforward solution for repositioning mistakes after a change.
// It maintains reasonable performance as it only checks the block element that has been modified, // It maintains reasonable performance as it only checks the block element that has been modified,
// rather than re-evaluating the entire document or a larger set of elements. // rather than re-evaluating the entire document or a larger set of elements.