Skip to content

Commit

Permalink
Merge pull request #240522 from microsoft/tyriar/240256
Browse files Browse the repository at this point in the history
Terminal suggest arrow navigation improvements
  • Loading branch information
Tyriar authored Feb 14, 2025
2 parents 31a3104 + 1a89b41 commit 6ccaf35
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
await this._handleCompletionProviders(this._terminal, token, explicitlyInvoked);
}

private _wasLastInputVerticalArrowKey(): boolean {
return !!this._lastUserData?.match(/^\x1b[\[O]?[A-B]$/);
}

private _wasLastInputArrowKey(): boolean {
// Never request completions if the last key sequence was up or down as the user was likely
// navigating history
Expand Down Expand Up @@ -376,7 +380,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
// with git branches in particular
this._isFilteringDirectories && prefix?.match(/[\\\/]$/)
) {
if (!this._wasLastInputArrowKey()) {
if (!this._wasLastInputVerticalArrowKey()) {
this.requestCompletions();
sent = true;
}
Expand All @@ -388,7 +392,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
}
for (const char of provider.triggerCharacters) {
if (prefix?.endsWith(char)) {
if (!this._wasLastInputArrowKey()) {
if (!this._wasLastInputVerticalArrowKey()) {
this.requestCompletions();
sent = true;
}
Expand All @@ -410,7 +414,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
// with git branches in particular
this._isFilteringDirectories && char.match(/[\\\/]$/)
) {
if (!this._wasLastInputArrowKey()) {
if (!this._wasLastInputVerticalArrowKey()) {
this.requestCompletions();
sent = true;
}
Expand All @@ -437,7 +441,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
// requested, but since extensions are expected to allow the client-side to filter, they are
// only invalidated when whitespace is encountered.
if (this._currentPromptInputState && this._currentPromptInputState.cursorIndex < this._leadingLineContent.length) {
if (this._currentPromptInputState.cursorIndex <= 0 || this._currentPromptInputState.value[this._currentPromptInputState.cursorIndex - 1].match(/\s/)) {
if (this._currentPromptInputState.cursorIndex <= 0 || this._currentPromptInputState.value[this._currentPromptInputState.cursorIndex].match(/[\\\/\s]/)) {
this.hideSuggestWidget(false);
return;
}
Expand Down

0 comments on commit 6ccaf35

Please sign in to comment.