Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

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

Saul-Mirone58d6a96e4533
diff --git a/blocksuite/framework/std/src/inline/range/range-binding.ts b/blocksuite/framework/std/src/inline/range/range-binding.ts
index 250c7bf148..0f10e70147 100644
--- a/blocksuite/framework/std/src/inline/range/range-binding.ts
+++ b/blocksuite/framework/std/src/inline/range/range-binding.ts
@@ -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;
+}