Skip to content

Commit a26f7bb

Browse files
authored
Merge pull request #239702 from microsoft/tyriar/239609_trigger_arrow_keys
Don't show suggest widget when last input was arrow
2 parents 39cf1ff + 5446d62 commit a26f7bb

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
258258
await this._handleCompletionProviders(this._terminal, token, explicitlyInvoked);
259259
}
260260

261+
private _wasLastInputArrowKey(): boolean {
262+
// Never request completions if the last key sequence was up or down as the user was likely
263+
// navigating history
264+
return !!this._lastUserData?.match(/^\x1b[\[O]?[A-D]$/);
265+
}
266+
261267
private _sync(promptInputState: IPromptInputModelState): void {
262268
const config = this._configurationService.getValue<ITerminalSuggestConfiguration>(terminalSuggestConfigSection);
263269
if (!this._mostRecentPromptInputState || promptInputState.cursorIndex > this._mostRecentPromptInputState.cursorIndex) {
@@ -268,9 +274,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
268274
if (!this._terminalSuggestWidgetVisibleContextKey.get()) {
269275
if (config.quickSuggestions) {
270276
if (promptInputState.prefix.match(/[^\s]$/)) {
271-
// Never request completions if the last key sequence was up or down as the user was likely
272-
// navigating history
273-
if (!this._lastUserData?.match(/^\x1b[\[O]?[A-D]$/)) {
277+
if (!this._wasLastInputArrowKey()) {
274278
this.requestCompletions();
275279
sent = true;
276280
}
@@ -289,8 +293,10 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
289293
// with git branches in particular
290294
this._isFilteringDirectories && prefix?.match(/[\\\/]$/)
291295
) {
292-
this.requestCompletions();
293-
sent = true;
296+
if (!this._wasLastInputArrowKey()) {
297+
this.requestCompletions();
298+
sent = true;
299+
}
294300
}
295301
if (!sent) {
296302
for (const provider of this._terminalCompletionService.providers) {
@@ -299,8 +305,10 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
299305
}
300306
for (const char of provider.triggerCharacters) {
301307
if (prefix?.endsWith(char)) {
302-
this.requestCompletions();
303-
sent = true;
308+
if (!this._wasLastInputArrowKey()) {
309+
this.requestCompletions();
310+
sent = true;
311+
}
304312
break;
305313
}
306314
}

0 commit comments

Comments
 (0)