mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix(editor): textarea not focusing in AI panel (#11429)
Closes: [BS-3006](https://linear.app/affine-design/issue/BS-3006/insider上面,圈选yuan素后,ad-hoc的ai对话框焦点控制有大问题(无法对焦,总是会跳走))
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user