fix: Extend DOM element check to include H1 and H2 tags in BesQuillService

This commit is contained in:
Aljaž Grilc 2025-01-31 07:49:13 +01:00
parent 5b10a90814
commit 45a10827c1

View File

@ -1207,7 +1207,6 @@ class BesQuillService extends BesTreeService {
reproofNeeded = true
}
})
if (reproofNeeded) {
const editorLength = this.quillInstance.getLength()
const clampedIndex = Math.min(index, editorLength - 1)
@ -1215,15 +1214,21 @@ class BesQuillService extends BesTreeService {
const [leaf, offset] = this.quillInstance.getLeaf(clampedIndex)
if (leaf) {
let domElement = leaf.domNode
while (domElement && domElement.tagName !== 'P') {
// TODO: Think of a way to get the block element containing the leaf. Because it is not necessary that the user will use this types of tag names.
const acceptedTagNames = ['P', 'H1', 'H2']
while (domElement && !acceptedTagNames.includes(domElement.tagName)) {
domElement = domElement.parentNode
}
this.clearProofing(domElement)
if (domElement) {
this.clearProofing(domElement)
setTimeout(() => {
this.repositionAllMarkup()
this.scheduleProofing(1000)
}, 0)
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.'