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 reproofNeeded = true
} }
}) })
if (reproofNeeded) { if (reproofNeeded) {
const editorLength = this.quillInstance.getLength() const editorLength = this.quillInstance.getLength()
const clampedIndex = Math.min(index, editorLength - 1) const clampedIndex = Math.min(index, editorLength - 1)
@ -1215,15 +1214,21 @@ class BesQuillService extends BesTreeService {
const [leaf, offset] = this.quillInstance.getLeaf(clampedIndex) const [leaf, offset] = this.quillInstance.getLeaf(clampedIndex)
if (leaf) { if (leaf) {
let domElement = leaf.domNode 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 domElement = domElement.parentNode
} }
this.clearProofing(domElement) if (domElement) {
this.clearProofing(domElement)
setTimeout(() => { setTimeout(() => {
this.repositionAllMarkup() this.repositionAllMarkup()
this.scheduleProofing(1000) this.scheduleProofing(1000)
}, 0) }, 0)
}
} else { } else {
console.warn( console.warn(
'Leaf is null. The index might be out of bounds or the editor content is empty.' 'Leaf is null. The index might be out of bounds or the editor content is empty.'