fix(tui): chain slash arg autocomplete after Tab completion

fixes #1437
This commit is contained in:
Benjamin Rapaport
2026-02-09 13:56:01 -05:00
committed by Mario Zechner
parent 52bf3b515d
commit 6937d2129e
2 changed files with 86 additions and 4 deletions

View File

@@ -479,6 +479,8 @@ export class Editor implements Component, Focusable {
if (kb.matches(data, "tab")) {
const selected = this.autocompleteList.getSelectedItem();
if (selected && this.autocompleteProvider) {
const shouldChainSlashArgumentAutocomplete = this.shouldChainSlashArgumentAutocompleteOnTabSelection();
this.pushUndoSnapshot();
this.lastAction = null;
const result = this.autocompleteProvider.applyCompletion(
@@ -493,6 +495,10 @@ export class Editor implements Component, Focusable {
this.setCursorCol(result.cursorCol);
this.cancelAutocomplete();
if (this.onChange) this.onChange(this.getText());
if (shouldChainSlashArgumentAutocomplete && this.isBareCompletedSlashCommandAtCursor()) {
this.tryTriggerAutocomplete();
}
}
return;
}
@@ -1827,6 +1833,26 @@ export class Editor implements Component, Focusable {
return this.isSlashMenuAllowed() && textBeforeCursor.trimStart().startsWith("/");
}
private shouldChainSlashArgumentAutocompleteOnTabSelection(): boolean {
if (this.autocompleteState !== "regular") {
return false;
}
const currentLine = this.state.lines[this.state.cursorLine] || "";
const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
return this.isInSlashCommandContext(textBeforeCursor) && !textBeforeCursor.trimStart().includes(" ");
}
private isBareCompletedSlashCommandAtCursor(): boolean {
const currentLine = this.state.lines[this.state.cursorLine] || "";
if (this.state.cursorCol !== currentLine.length) {
return false;
}
const textBeforeCursor = currentLine.slice(0, this.state.cursorCol).trimStart();
return /^\/\S+ $/.test(textBeforeCursor);
}
// Autocomplete methods
/**
* Find the best autocomplete item index for the given prefix.