Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First PR: Adding jump to nth autocomplete suggestion via keyboard shortcut #58670

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/vs/editor/contrib/suggest/suggestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ export class SuggestController implements IEditorContribution {
}
}

selectNthSuggestion(number): void {
if (this._widget) {
this._widget.selectNth(number);
}
}

toggleSuggestionDetails(): void {
if (this._widget) {
this._widget.toggleDetails();
Expand Down Expand Up @@ -477,3 +483,18 @@ registerEditorCommand(new SuggestCommand({
mac: { primary: KeyMod.WinCtrl | KeyMod.Alt | KeyCode.Space }
}
}));

for (let idx = 0, len = 10; idx < len; idx++) {
registerEditorCommand(new SuggestCommand({
id: 'selectNthSuggestion' + idx,
precondition: ContextKeyExpr.and(SuggestContext.Visible, SuggestContext.MultipleSuggestions),
handler: c => c.selectNthSuggestion(idx),
kbOpts: {
weight: weight,
kbExpr: EditorContextKeys.textInputFocus,
primary: KeyCode.KEY_0 + idx - 1,
secondary: [KeyMod.CtrlCmd],
mac: { primary: KeyMod.CtrlCmd, secondary: [KeyCode.KEY_0 + idx - 1] }
}
}));
}
15 changes: 15 additions & 0 deletions src/vs/editor/contrib/suggest/suggestWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,21 @@ export class SuggestWidget implements IContentWidget, IVirtualDelegate<ICompleti
}
}

selectNth(number): boolean {
switch (this.state) {
case State.Hidden:
return false;
case State.Details:
this.details.scrollTop();
return true;
case State.Loading:
return !this.isAuto;
default:
this.list.setFocus([number]);
return true;
}
}

getFocusedItem(): ISelectedSuggestion {
if (this.state !== State.Hidden
&& this.state !== State.Empty
Expand Down