fundon
2025-04-03 03:27:25 +00:00
parent c61df18ab9
commit a1500e3ee1
5 changed files with 34 additions and 5 deletions

View File

@@ -1,3 +1,5 @@
import { RANGE_SYNC_EXCLUDE_ATTR } from './consts';
/**
* Check if the active element is in the editor host.
* TODO(@mirone): this is a trade-off, we need to use separate awareness store for every store to make sure the selection is isolated.
@@ -8,6 +10,9 @@
export function isActiveInEditor(editorHost: HTMLElement) {
const currentActiveElement = document.activeElement;
if (!currentActiveElement) return false;
// The input or textarea in the widget should be ignored.
if (currentActiveElement.closest(`[${RANGE_SYNC_EXCLUDE_ATTR}="true"]`))
return false;
const currentEditorHost = currentActiveElement?.closest('editor-host');
if (!currentEditorHost) return false;
return currentEditorHost === editorHost;

View File

@@ -210,12 +210,11 @@ export class RangeBinding {
const el = getElement(range.commonAncestorContainer);
if (!el) return;
const closestExclude = el.closest(`[${RANGE_SYNC_EXCLUDE_ATTR}]`);
if (closestExclude?.getAttribute(RANGE_SYNC_EXCLUDE_ATTR) === 'true')
return;
const closestExclude = el.closest(`[${RANGE_SYNC_EXCLUDE_ATTR}="true"]`);
if (closestExclude) return;
const closestEditable = el.closest('[contenteditable]');
if (closestEditable?.getAttribute('contenteditable') === 'false') return;
const closestEditable = el.closest('[contenteditable="false"]');
if (closestEditable) return;
const startElement = getElement(range.startContainer);
const endElement = getElement(range.endContainer);