diff options
| author | Seth Troisi <[email protected]> | 2025-05-01 00:52:01 +0000 |
|---|---|---|
| committer | Seth Troisi <[email protected]> | 2025-05-02 20:58:53 +0000 |
| commit | cc838fad44057a42561215fe3daed2834e6e0442 (patch) | |
| tree | 584251fd75d2d039d3e811fdab3c9d69a2ab0e0f /packages/cli/src/ui/components/InputPrompt.tsx | |
| parent | f237082c37a10db1bf9d7daddf039bf4e002ec61 (diff) | |
Add autocomplete for slash commands
Diffstat (limited to 'packages/cli/src/ui/components/InputPrompt.tsx')
| -rw-r--r-- | packages/cli/src/ui/components/InputPrompt.tsx | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/packages/cli/src/ui/components/InputPrompt.tsx b/packages/cli/src/ui/components/InputPrompt.tsx index fbf84766..1c8cff4d 100644 --- a/packages/cli/src/ui/components/InputPrompt.tsx +++ b/packages/cli/src/ui/components/InputPrompt.tsx @@ -47,25 +47,37 @@ export const InputPrompt: React.FC<InputPromptProps> = ({ return; } const selectedSuggestion = suggestions[activeSuggestionIndex]; - const atIndex = query.lastIndexOf('@'); - if (atIndex === -1) return; + const trimmedQuery = query.trimStart(); - // Find the part of the query after the '@' - const pathPart = query.substring(atIndex + 1); - // Find the last slash within that part - const lastSlashIndexInPath = pathPart.lastIndexOf('/'); - - let base = ''; - if (lastSlashIndexInPath === -1) { - // No slash after '@', replace everything after '@' - base = query.substring(0, atIndex + 1); + if (trimmedQuery.startsWith('/')) { + // Handle / command completion + const slashIndex = query.indexOf('/'); + const base = query.substring(0, slashIndex + 1); + const newValue = base + selectedSuggestion.value; + setQuery(newValue); } else { - // Slash found, keep everything up to and including the last slash - base = query.substring(0, atIndex + 1 + lastSlashIndexInPath + 1); + // Handle @ command completion + const atIndex = query.lastIndexOf('@'); + if (atIndex === -1) return; + + // Find the part of the query after the '@' + const pathPart = query.substring(atIndex + 1); + // Find the last slash within that part + const lastSlashIndexInPath = pathPart.lastIndexOf('/'); + + let base = ''; + if (lastSlashIndexInPath === -1) { + // No slash after '@', replace everything after '@' + base = query.substring(0, atIndex + 1); + } else { + // Slash found, keep everything up to and including the last slash + base = query.substring(0, atIndex + 1 + lastSlashIndexInPath + 1); + } + + const newValue = base + selectedSuggestion.value; + setQuery(newValue); } - const newValue = base + selectedSuggestion.value; - setQuery(newValue); resetCompletion(); // Hide suggestions after selection setInputKey((k) => k + 1); // Increment key to force re-render and cursor reset }, [ |
