From f7c0024fe15057ad049c71e15e88adb482a4497f Mon Sep 17 00:00:00 2001 From: szmidtpiotr <91347162+szmidtpiotr@users.noreply.github.com> Date: Tue, 9 Jun 2026 14:56:31 +0200 Subject: [PATCH] fix: slash command suggestions trigger at any / in input, not only at start (#843) Previously the regex ^\/(\S*)$ only matched when the entire text before the cursor was a bare /command. Typing a slash mid-sentence (e.g. "please run /he") produced no suggestions. Changed pattern to (?:^|\s)(\/\S*)$ which matches / at the start of input or after any whitespace. Also compute slashPos from match.index instead of hardcoding 0, so insertCommandIntoInput replaces the correct slice of the input when the command is mid-sentence. Co-authored-by: Claude Sonnet 4.6 --- src/components/chat/hooks/useSlashCommands.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/chat/hooks/useSlashCommands.ts b/src/components/chat/hooks/useSlashCommands.ts index db6eefaa..b64ac6e0 100644 --- a/src/components/chat/hooks/useSlashCommands.ts +++ b/src/components/chat/hooks/useSlashCommands.ts @@ -393,7 +393,8 @@ export function useSlashCommands({ return; } - const slashPattern = /^\/(\S*)$/; + // Match / at start of input OR after whitespace, capturing the /word up to cursor. + const slashPattern = /(?:^|\s)(\/\S*)$/; const match = textBeforeCursor.match(slashPattern); if (!match) { @@ -401,8 +402,9 @@ export function useSlashCommands({ return; } - const slashPos = 0; - const query = match[1]; + // Compute actual position of / in the full input string. + const slashPos = match.index! + (match[0].length - match[1].length); + const query = match[1].slice(1); // strip leading / setSlashPosition(slashPos); setShowCommandMenu(true);