From 9a3d8d68009e013810084e8d82bff7df8d5b0dcf Mon Sep 17 00:00:00 2001 From: Mark Tomlinson <54233735+mark-tomlinson-dev@users.noreply.github.com> Date: Thu, 6 Nov 2025 01:24:08 +1100 Subject: [PATCH] Fix block command bar ESC key handling (#232) * fix: BlockCommandBar ESC key handling * Align clearCommandSearchText more with repo code style --- components/Blocks/BlockCommandBar.tsx | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/components/Blocks/BlockCommandBar.tsx b/components/Blocks/BlockCommandBar.tsx index 61087046..62bf0e87 100644 --- a/components/Blocks/BlockCommandBar.tsx +++ b/components/Blocks/BlockCommandBar.tsx @@ -6,6 +6,7 @@ import { useEntitySetContext } from "components/EntitySetProvider"; import { NestedCardThemeProvider } from "components/ThemeManager/ThemeProvider"; import { UndoManager } from "src/undoManager"; import { useLeafletPublicationData } from "components/PageSWRDataProvider"; +import { setEditorState, useEditorStates } from "src/state/useEditorState"; type Props = { parent: string; @@ -32,6 +33,19 @@ export const BlockCommandBar = ({ let entity_set = useEntitySetContext(); let { data: pub } = useLeafletPublicationData(); + // This clears '/' AND anything typed after it + const clearCommandSearchText = () => { + if (!props.entityID) return; + const entityID = props.entityID; + + const existingState = useEditorStates.getState().editorStates[entityID]; + if (!existingState) return; + + const tr = existingState.editor.tr; + tr.deleteRange(1, tr.doc.content.size - 1); + setEditorState(entityID, { editor: existingState.editor.apply(tr) }); + }; + let commandResults = blockCommands.filter((command) => { const matchesSearch = command.name .toLocaleLowerCase() @@ -98,9 +112,6 @@ export const BlockCommandBar = ({ undoManager.endGroup(); return; } - - // radix menu component handles esc - if (e.key === "Escape") return; }; window.addEventListener("keydown", listener); @@ -108,7 +119,14 @@ export const BlockCommandBar = ({ }, [highlighted, setHighlighted, commandResults, rep, entity_set.set, props]); return ( - + { + if (!open) { + clearCommandSearchText(); + } + }} + >