feat: auto-execute on slash command completion functions (#14584)

This commit is contained in:
Jack Wotherspoon
2025-12-08 16:32:39 -05:00
committed by GitHub
parent 17b5b40765
commit 89570aef06
9 changed files with 197 additions and 8 deletions

View File

@@ -621,16 +621,41 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
const isEnterKey = key.name === 'return' && !key.ctrl;
if (isEnterKey && buffer.text.startsWith('/')) {
const command = completion.getCommandFromSuggestion(suggestion);
const { isArgumentCompletion, leafCommand } =
completion.slashCompletionRange;
if (command && isAutoExecutableCommand(command)) {
if (
isArgumentCompletion &&
isAutoExecutableCommand(leafCommand)
) {
// isArgumentCompletion guarantees leafCommand exists
const completedText = completion.getCompletedText(suggestion);
if (completedText) {
setExpandedSuggestionIndex(-1);
handleSubmit(completedText.trim());
return;
}
} else if (!isArgumentCompletion) {
// Existing logic for command name completion
const command =
completion.getCommandFromSuggestion(suggestion);
// Only auto-execute if the command has no completion function
// (i.e., it doesn't require an argument to be selected)
if (
command &&
isAutoExecutableCommand(command) &&
!command.completion
) {
const completedText =
completion.getCompletedText(suggestion);
if (completedText) {
setExpandedSuggestionIndex(-1);
handleSubmit(completedText.trim());
return;
}
}
}
}