From ac97dfa9e14a73ea2d6934ff566282d7f758e8bb Mon Sep 17 00:00:00 2001 From: Jeffrey Lu Date: Mon, 6 May 2024 16:29:38 -0400 Subject: [PATCH] feat(@lexical/plaintext): Add escape key handler (#5991) --- packages/lexical-plain-text/src/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/lexical-plain-text/src/index.ts b/packages/lexical-plain-text/src/index.ts index 1df4cb1c1ca..7e11cffe102 100644 --- a/packages/lexical-plain-text/src/index.ts +++ b/packages/lexical-plain-text/src/index.ts @@ -37,6 +37,7 @@ import { KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, + KEY_ESCAPE_COMMAND, PASTE_COMMAND, REMOVE_TEXT_COMMAND, SELECT_ALL_COMMAND, @@ -324,6 +325,18 @@ export function registerPlainText(editor: LexicalEditor): () => void { }, COMMAND_PRIORITY_EDITOR, ), + editor.registerCommand( + KEY_ESCAPE_COMMAND, + () => { + const selection = $getSelection(); + if (!$isRangeSelection(selection)) { + return false; + } + editor.blur(); + return true; + }, + COMMAND_PRIORITY_EDITOR, + ), editor.registerCommand( SELECT_ALL_COMMAND, () => {