From 705b4c1b1187332b83f77b440e22580c7f2536ad Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 16 Jul 2025 01:32:42 -0700 Subject: [PATCH] Only trigger slash commands when slash is the very first character --- src/slashCommands.ts | 3 ++- src/ui/UserInput.tsx | 32 ++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/slashCommands.ts b/src/slashCommands.ts index e9c7b5c26..9851e7573 100644 --- a/src/slashCommands.ts +++ b/src/slashCommands.ts @@ -18,7 +18,8 @@ export async function handleSlashCommands( newInput?: string; clear?: boolean; } | null> { - if (input.startsWith("/")) { + // Only trigger slash commands if slash is the very first character + if (input.startsWith("/") && input.trim().startsWith("/")) { const [command, ...args] = input.slice(1).split(" "); switch (command) { case "help": diff --git a/src/ui/UserInput.tsx b/src/ui/UserInput.tsx index 67e537b04..116199475 100644 --- a/src/ui/UserInput.tsx +++ b/src/ui/UserInput.tsx @@ -80,20 +80,24 @@ const UserInput: React.FC = ({ // Update slash command UI state based on input const updateSlashCommandState = (text: string, cursor: number) => { - // Check if we're in a slash command context - const beforeCursor = text.slice(0, cursor); - const lastSlashIndex = beforeCursor.lastIndexOf("/"); - - if (lastSlashIndex !== -1) { - // Check if there's any whitespace between the last slash and cursor - const afterSlash = beforeCursor.slice(lastSlashIndex + 1); - - if (!afterSlash.includes(" ") && !afterSlash.includes("\n")) { - // We're in a slash command context - setShowSlashCommands(true); - setSlashCommandFilter(afterSlash); - setSelectedCommandIndex(0); - setShowFileSearch(false); + // Only show slash commands if slash is the very first character + if (text.trimStart().startsWith("/")) { + const trimmedText = text.trimStart(); + const beforeCursor = trimmedText.slice(0, cursor - (text.length - trimmedText.length)); + + // Only show if cursor is after the slash and before any whitespace + if (beforeCursor.length > 0 && beforeCursor.startsWith("/")) { + const afterSlash = beforeCursor.slice(1); + + if (!afterSlash.includes(" ") && !afterSlash.includes("\n")) { + // We're in a slash command context + setShowSlashCommands(true); + setSlashCommandFilter(afterSlash); + setSelectedCommandIndex(0); + setShowFileSearch(false); + } else { + setShowSlashCommands(false); + } } else { setShowSlashCommands(false); }