fundon
2025-04-03 03:27:25 +00:00
parent c61df18ab9
commit a1500e3ee1
5 changed files with 34 additions and 5 deletions
@@ -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;