feat: Autocomplete for slash commands (#216)

This commit is contained in:
Devansh Jain
2025-12-15 12:54:52 -08:00
committed by GitHub
parent 3c0b60f82d
commit 7ce41e52f4
9 changed files with 416 additions and 326 deletions

View File

@@ -453,6 +453,35 @@ export function Input({
setCursorPos(newCursorPos);
};
// Handle slash command selection from autocomplete
const handleCommandSelect = (selectedCommand: string) => {
// Find the "/" at start of input and replace the command
const slashIndex = value.indexOf("/");
if (slashIndex === -1) return;
const beforeSlash = value.slice(0, slashIndex);
const afterSlash = value.slice(slashIndex + 1);
const spaceIndex = afterSlash.indexOf(" ");
let newValue: string;
let newCursorPos: number;
// Replace the command part with the selected command
if (spaceIndex === -1) {
// No space after /command, replace to end
newValue = `${beforeSlash}${selectedCommand} `;
newCursorPos = newValue.length;
} else {
// Space exists, replace only the command part
const afterCommand = afterSlash.slice(spaceIndex);
newValue = `${beforeSlash}${selectedCommand}${afterCommand}`;
newCursorPos = beforeSlash.length + selectedCommand.length;
}
setValue(newValue);
setCursorPos(newCursorPos);
};
// Get display name and color for permission mode
const getModeInfo = () => {
switch (currentMode) {
@@ -542,6 +571,7 @@ export function Input({
currentInput={value}
cursorPosition={currentCursorPosition}
onFileSelect={handleFileSelect}
onCommandSelect={handleCommandSelect}
onAutocompleteActiveChange={setIsAutocompleteActive}
agentId={agentId}
agentName={agentName}