mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user