Fix out-of-bounds index in BesQuillService

This commit is contained in:
Aljaž Grilc 2025-01-28 13:55:47 +01:00
parent 675ecdc7a4
commit 5b10a90814

View File

@ -1209,17 +1209,26 @@ class BesQuillService extends BesTreeService {
})
if (reproofNeeded) {
const [leaf, offset] = this.quillInstance.getLeaf(index)
let domElement = leaf.domNode
while (domElement && domElement.tagName !== 'P') {
domElement = domElement.parentNode
}
this.clearProofing(domElement)
const editorLength = this.quillInstance.getLength()
const clampedIndex = Math.min(index, editorLength - 1)
setTimeout(() => {
this.repositionAllMarkup()
this.scheduleProofing(1000)
}, 0)
const [leaf, offset] = this.quillInstance.getLeaf(clampedIndex)
if (leaf) {
let domElement = leaf.domNode
while (domElement && domElement.tagName !== 'P') {
domElement = domElement.parentNode
}
this.clearProofing(domElement)
setTimeout(() => {
this.repositionAllMarkup()
this.scheduleProofing(1000)
}, 0)
} else {
console.warn(
'Leaf is null. The index might be out of bounds or the editor content is empty.'
)
}
}
}