fix(editor): firefox invalid selection range (#11320)

Closes: BS-2987
This commit is contained in:
Saul-Mirone
2025-03-31 14:33:24 +00:00
parent 5f3cf53819
commit 58d6a96e45

View File

@@ -209,14 +209,23 @@ export class RangeBinding {
return;
}
const el =
range.commonAncestorContainer instanceof Element
? range.commonAncestorContainer
: range.commonAncestorContainer.parentElement;
const el = getElement(range.commonAncestorContainer);
if (!el) return;
const block = el.closest<BlockComponent>(`[${BLOCK_ID_ATTR}]`);
if (block?.getAttribute(RANGE_SYNC_EXCLUDE_ATTR) === 'true') return;
const startElement = getElement(range.startContainer);
const endElement = getElement(range.endContainer);
// if neither start nor end is in a v-text, the range is invalid
if (!startElement?.closest('v-text') && !endElement?.closest('v-text')) {
this._prevTextSelection = null;
this.selectionManager.clear(['text']);
selection.removeRange(range);
return;
}
const inlineEditor = this.rangeManager?.getClosestInlineEditor(
range.commonAncestorContainer
);
@@ -351,3 +360,10 @@ export class RangeBinding {
);
}
}
function getElement(node: Node): Element | null {
if (node instanceof Element) {
return node;
}
return node.parentElement;
}