Skip to content

Commit

Permalink
Merge pull request #155666 from justschen/justin/CodeActionMenu-Widget
Browse files Browse the repository at this point in the history
Drop in CodeAction Menu w/List Widget #152913
  • Loading branch information
justschen authored Jul 20, 2022
2 parents 85e47d3 + 565b23b commit 3f454e9
Show file tree
Hide file tree
Showing 7 changed files with 572 additions and 43 deletions.
4 changes: 4 additions & 0 deletions src/vs/base/browser/ui/list/listWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,10 @@ export class List<T> implements ISpliceable<T>, IThemable, IDisposable {
return this.view.domNode;
}

getElementID(index: number): string {
return this.view.getElementDomId(index);
}

style(styles: IListStyles): void {
this.styleController.style(styles);
}
Expand Down
79 changes: 78 additions & 1 deletion src/vs/editor/contrib/codeAction/browser/codeActionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Lazy } from 'vs/base/common/lazy';
import { Disposable } from 'vs/base/common/lifecycle';
import { escapeRegExpCharacters } from 'vs/base/common/strings';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorAction, EditorCommand, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { EditorAction, EditorCommand, registerEditorCommand, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { IBulkEditService, ResourceEdit } from 'vs/editor/browser/services/bulkEditService';
import { IPosition } from 'vs/editor/common/core/position';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
Expand All @@ -32,6 +32,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { CodeActionModel, CodeActionsState, SUPPORTED_CODE_ACTIONS } from './codeActionModel';
import { CodeActionAutoApply, CodeActionCommandArgs, CodeActionFilter, CodeActionKind, CodeActionTrigger, CodeActionTriggerSource } from './types';
import { Context } from 'vs/editor/contrib/codeAction/browser/codeActionMenu';

function contextKeyForSupportedActions(kind: CodeActionKind) {
return ContextKeyExpr.regex(
Expand Down Expand Up @@ -132,6 +133,24 @@ export class QuickFixController extends Disposable implements IEditorContributio
this._ui.getValue().update(newState);
}

public hideCodeActionMenu() {
if (this._ui.hasValue()) {
this._ui.getValue().hideCodeActionWidget();
}
}

public navigateCodeActionList(navUp: Boolean) {
if (this._ui.hasValue()) {
this._ui.getValue().navigateList(navUp);
}
}

public selectedOption() {
if (this._ui.hasValue()) {
this._ui.getValue().onEnter();
}
}

public showCodeActions(trigger: CodeActionTrigger, actions: CodeActionSet, at: IAnchor | IPosition) {
return this._ui.getValue().showCodeActionList(trigger, actions, at, { includeDisabledActions: false, fromLightbulb: false });
}
Expand Down Expand Up @@ -490,3 +509,61 @@ export class AutoFixAction extends EditorAction {
CodeActionAutoApply.IfSingle, undefined, CodeActionTriggerSource.AutoFix);
}
}

const CodeActionContribution = EditorCommand.bindToContribution<QuickFixController>(QuickFixController.get);

const weight = KeybindingWeight.EditorContrib + 90;

registerEditorCommand(new CodeActionContribution({
id: 'hideCodeActionMenuWidget',
precondition: Context.Visible,
handler(x) {
x.hideCodeActionMenu();
},
kbOpts: {
weight: weight,
primary: KeyCode.Escape,
secondary: [KeyMod.Shift | KeyCode.Escape]
}
}));

registerEditorCommand(new CodeActionContribution({
id: 'focusPreviousCodeAction',
precondition: Context.Visible,
handler(x) {
x.navigateCodeActionList(true);
},
kbOpts: {
weight: weight + 100000,
primary: KeyCode.UpArrow,
secondary: [KeyMod.CtrlCmd | KeyCode.UpArrow],
}
}));

registerEditorCommand(new CodeActionContribution({
id: 'focusNextCodeAction',
precondition: Context.Visible,
handler(x) {
x.navigateCodeActionList(false);
},
kbOpts: {
weight: weight + 100000,
primary: KeyCode.DownArrow,
secondary: [KeyMod.CtrlCmd | KeyCode.DownArrow],
}
}));

registerEditorCommand(new CodeActionContribution({
id: 'onEnterSelectCodeAction',
precondition: Context.Visible,
handler(x) {
x.selectedOption();
},
kbOpts: {
weight: weight + 100000,
primary: KeyCode.Enter,
secondary: [KeyMod.Shift | KeyCode.Tab],
}
}));


Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { registerEditorAction, registerEditorCommand, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { AutoFixAction, CodeActionCommand, FixAllAction, OrganizeImportsAction, QuickFixAction, QuickFixController, RefactorAction, RefactorPreview, SourceAction } from 'vs/editor/contrib/codeAction/browser/codeActionCommands';

import 'vs/editor/contrib/codeAction/browser/codeActionWidgetContribution';

registerEditorContribution(QuickFixController.ID, QuickFixController);
registerEditorAction(QuickFixAction);
Expand Down
Loading

0 comments on commit 3f454e9

Please sign in to comment.