Skip to content

Commit dd67020

Browse files
masonwyatt23claude
andcommitted
fix: slash command autocomplete works mid-message
Autocomplete was only matching when input started with / (e.g., "/dee" → "/deep-work"). But users type slash commands mid-message like "do this task /dee". Now extracts the last word and matches against that, so /deep-work appears regardless of position. - Suggestion display shows only the completion suffix - Tab acceptance replaces only the last word, preserving prefix text - Autocomplete hints filter on last word, not full input Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 71b18f8 commit dd67020

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/ui/App.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,12 @@ export function App({
153153
};
154154
}, []);
155155

156+
// Autocomplete slash commands — works at start of input OR after a space (mid-message)
157+
const lastWord = input.split(" ").pop() ?? "";
156158
const slashSuggestion =
157-
input.startsWith("/") && input.length > 1 ? commands.find((c) => c.startsWith(input) && c !== input) : undefined;
159+
lastWord.startsWith("/") && lastWord.length > 1
160+
? commands.find((c) => c.startsWith(lastWord) && c !== lastWord)
161+
: undefined;
158162

159163
const fileSuggestion = useMemo(
160164
() => (!slashSuggestion && cwd ? getFilePathSuggestion(input, cwd) : undefined),
@@ -177,11 +181,13 @@ export function App({
177181
const acceptSuggestion = useCallback(() => {
178182
if (!suggestion) return;
179183
// For directory completions (ending with /), don't add trailing space
180-
// so the user can keep tabbing into subdirectories
181184
const suffix = suggestion.endsWith("/") ? "" : " ";
182-
setInput(suggestion + suffix);
183-
setInputKey((k) => k + 1); // Force TextInput remount — cursor goes to end
184-
}, [suggestion]);
185+
// Replace only the last word with the suggestion, preserving text before it
186+
const words = input.split(" ");
187+
words[words.length - 1] = suggestion + suffix;
188+
setInput(words.join(" "));
189+
setInputKey((k) => k + 1);
190+
}, [suggestion, input]);
185191

186192
useInput(
187193
useCallback(
@@ -362,17 +368,17 @@ export function App({
362368
onSubmit={handleSubmit}
363369
placeholder="Type a message..."
364370
/>
365-
{suggestion && <Text dimColor>{suggestion.slice(input.length)}</Text>}
371+
{suggestion && <Text dimColor>{suggestion.slice(lastWord.length)}</Text>}
366372
</Box>
367373
)}
368374
</Box>
369375
)}
370376
{/* Autocomplete hints — only shown when typing a slash command and no question pending */}
371-
{!pendingQuestionOptionCount && input.startsWith("/") && input.length > 1 && !isProcessing && (
377+
{!pendingQuestionOptionCount && lastWord.startsWith("/") && lastWord.length > 1 && !isProcessing && (
372378
<Box marginLeft={2}>
373379
<Text dimColor>
374380
{commands
375-
.filter((c) => c.startsWith(input))
381+
.filter((c) => c.startsWith(lastWord))
376382
.slice(0, 5)
377383
.join(" ")}
378384
</Text>

0 commit comments

Comments
 (0)