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 <noreply@anthropic.com>
This commit is contained in:
szmidtpiotr
2026-06-09 14:56:31 +02:00
committed by GitHub
parent b7e6bca2e3
commit f7c0024fe1

View File

@@ -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);