From e5dee88fbe452ba52057535d272c8f756dfa4521 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 7 Feb 2025 06:23:57 -0800 Subject: [PATCH] Request completions when backspacing past a slash FIxes #239948 --- .../suggest/browser/terminalSuggestAddon.ts | 90 +++++++++++-------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts b/src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts index edf49705a2e..eb7b8d0111c 100644 --- a/src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts +++ b/src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts @@ -306,51 +306,71 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest private _sync(promptInputState: IPromptInputModelState): void { const config = this._configurationService.getValue(terminalSuggestConfigSection); - if (!this._mostRecentPromptInputState || promptInputState.cursorIndex > this._mostRecentPromptInputState.cursorIndex) { - // If input has been added + { let sent = false; - // Quick suggestions - Trigger whenever a new non-whitespace character is used - if (!this._terminalSuggestWidgetVisibleContextKey.get()) { - if (config.quickSuggestions) { - if (promptInputState.prefix.match(/[^\s]$/)) { + // If the cursor moved to the right + if (!this._mostRecentPromptInputState || promptInputState.cursorIndex > this._mostRecentPromptInputState.cursorIndex) { + // Quick suggestions - Trigger whenever a new non-whitespace character is used + if (!this._terminalSuggestWidgetVisibleContextKey.get()) { + if (config.quickSuggestions) { + if (promptInputState.prefix.match(/[^\s]$/)) { + if (!this._wasLastInputArrowKey()) { + this.requestCompletions(); + sent = true; + } + } + } + } + + // Trigger characters - this happens even if the widget is showing + if (config.suggestOnTriggerCharacters && !sent) { + const prefix = promptInputState.prefix; + if ( + // Only trigger on `-` if it's after a space. This is required to not clear + // completions when typing the `-` in `git cherry-pick` + prefix?.match(/\s[\-]$/) || + // Only trigger on `\` and `/` if it's a directory. Not doing so causes problems + // with git branches in particular + this._isFilteringDirectories && prefix?.match(/[\\\/]$/) + ) { if (!this._wasLastInputArrowKey()) { this.requestCompletions(); sent = true; } } + if (!sent) { + for (const provider of this._terminalCompletionService.providers) { + if (!provider.triggerCharacters) { + continue; + } + for (const char of provider.triggerCharacters) { + if (prefix?.endsWith(char)) { + if (!this._wasLastInputArrowKey()) { + this.requestCompletions(); + sent = true; + } + break; + } + } + } + } } } - // Trigger characters - this happens even if the widget is showing - if (config.suggestOnTriggerCharacters && !sent) { - const prefix = promptInputState.prefix; - if ( - // Only trigger on `-` if it's after a space. This is required to not clear - // completions when typing the `-` in `git cherry-pick` - prefix?.match(/\s[\-]$/) || - // Only trigger on `\` and `/` if it's a directory. Not doing so causes problems - // with git branches in particular - this._isFilteringDirectories && prefix?.match(/[\\\/]$/) - ) { - if (!this._wasLastInputArrowKey()) { - this.requestCompletions(); - sent = true; - } - } - if (!sent) { - for (const provider of this._terminalCompletionService.providers) { - if (!provider.triggerCharacters) { - continue; - } - for (const char of provider.triggerCharacters) { - if (prefix?.endsWith(char)) { - if (!this._wasLastInputArrowKey()) { - this.requestCompletions(); - sent = true; - } - break; - } + // If the cursor moved to the left + if (this._mostRecentPromptInputState && promptInputState.cursorIndex < this._mostRecentPromptInputState.cursorIndex) { + // Backspace or left past a trigger character + if (config.suggestOnTriggerCharacters && !sent && this._mostRecentPromptInputState.cursorIndex > 0) { + const char = this._mostRecentPromptInputState.value[this._mostRecentPromptInputState.cursorIndex - 1]; + if ( + // Only trigger on `\` and `/` if it's a directory. Not doing so causes problems + // with git branches in particular + this._isFilteringDirectories && char.match(/[\\\/]$/) + ) { + if (!this._wasLastInputArrowKey()) { + this.requestCompletions(); + sent = true; } } }