From 8940894666a382284ebdca369d7df7d47cf12e67 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Thu, 22 Dec 2022 18:58:33 +0000 Subject: [PATCH] Add logic in isSelectionCapturedInDecoratorInput for contentEditables --- packages/lexical/src/LexicalUtils.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/lexical/src/LexicalUtils.ts b/packages/lexical/src/LexicalUtils.ts index 1cb01654e84..cd33c990f4d 100644 --- a/packages/lexical/src/LexicalUtils.ts +++ b/packages/lexical/src/LexicalUtils.ts @@ -107,11 +107,20 @@ export function $isSelectionCapturedInDecorator(node: Node): boolean { } export function isSelectionCapturedInDecoratorInput(anchorDOM: Node): boolean { - const activeElement = document.activeElement; - const nodeName = activeElement !== null ? activeElement.nodeName : null; + const activeElement = document.activeElement as HTMLElement; + + if (activeElement === null) { + return false; + } + const nodeName = activeElement.nodeName; + return ( $isDecoratorNode($getNearestNodeFromDOMNode(anchorDOM)) && - (nodeName === 'INPUT' || nodeName === 'TEXTAREA') + (nodeName === 'INPUT' || + nodeName === 'TEXTAREA' || + (activeElement.contentEditable === 'true' && + // @ts-ignore iternal field + activeElement.__lexicalEditor == null)) ); }