From 45a10827c1da6a04b024cd9a89385a6f3c5b2865 Mon Sep 17 00:00:00 2001 From: Aljaz Grilc Date: Fri, 31 Jan 2025 07:49:13 +0100 Subject: [PATCH] fix: Extend DOM element check to include H1 and H2 tags in BesQuillService --- service.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/service.js b/service.js index e9758f8..d61abc3 100644 --- a/service.js +++ b/service.js @@ -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.'