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(); + } + }} + >