diff --git a/src/components/ComboBox/ComboBox.test.tsx b/src/components/ComboBox/ComboBox.test.tsx index 0a9addeb..4c6939e0 100644 --- a/src/components/ComboBox/ComboBox.test.tsx +++ b/src/components/ComboBox/ComboBox.test.tsx @@ -175,4 +175,17 @@ describe("ComboBox", () => { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access expect(event.target.value).toEqual("hello\n"); }); + + test("select command, type / and then delete", async () => { + const { user, ...app } = render(); + const textarea = app.getByRole("combobox"); + await user.type(textarea, "@fi{Enter}"); + expect(app.getByRole("combobox").textContent).toEqual("@file "); + await user.type(textarea, "/"); + expect(app.queryByText("/foo")).not.toBeNull(); + expect(app.queryByText("/bar")).not.toBeNull(); + await user.type(textarea, "{Backspace}"); + expect(app.queryByText("/foo")).not.toBeNull(); + expect(app.queryByText("/bar")).not.toBeNull(); + }); }); diff --git a/src/components/ComboBox/ComboBox.tsx b/src/components/ComboBox/ComboBox.tsx index fa8ce97b..91f7874c 100644 --- a/src/components/ComboBox/ComboBox.tsx +++ b/src/components/ComboBox/ComboBox.tsx @@ -175,11 +175,12 @@ export const ComboBox: React.FC = ({ const maybeCommand = detectCommand(ref.current); if (maybeCommand !== null) { - const [command, args] = maybeCommand.command.split(" "); + const maybeCommandWithArguments = maybeCommand.command.split(" "); + const [command, args] = maybeCommandWithArguments; if (!selectedCommand && args) { setSelectedCommand(command + " "); - } else if (selectedCommand && !args) { + } else if (selectedCommand && maybeCommandWithArguments.length < 2) { setSelectedCommand(""); }