Skip to content

Commit

Permalink
Merge pull request #175946 from microsoft/dev/joyceerhl/judicial-impala
Browse files Browse the repository at this point in the history
Defer creation of `editor/lineNumber/context` menu
  • Loading branch information
joyceerhl authored Mar 2, 2023
2 parents 6a6afc6 + 64d9f7b commit f04ee59
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Separator } from 'vs/base/common/actions';
import { IAction, Separator } from 'vs/base/common/actions';
import { Disposable } from 'vs/base/common/lifecycle';
import { ICodeEditor, MouseTargetType } from 'vs/editor/browser/editorBrowser';
import { registerEditorContribution, EditorContributionInstantiation } from 'vs/editor/browser/editorExtensions';
Expand All @@ -13,8 +13,8 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IBreakpointEditorContribution, BREAKPOINT_EDITOR_CONTRIBUTION_ID } from 'vs/workbench/contrib/debug/common/debug';

class EditorLineNumberContextMenu extends Disposable implements IEditorContribution {
private readonly menu = this._register(this.menuService.createMenu(MenuId.EditorLineNumberContext, this.contextKeyService));
export class EditorLineNumberContextMenu extends Disposable implements IEditorContribution {
static readonly ID = 'workbench.contrib.editorLineNumberContextMenu';

constructor(
private readonly editor: ICodeEditor,
Expand All @@ -30,6 +30,8 @@ class EditorLineNumberContextMenu extends Disposable implements IEditorContribut

private registerListeners(): void {
this._register(this.editor.onContextMenu((e) => {
const menu = this.menuService.createMenu(MenuId.EditorLineNumberContext, this.contextKeyService);

const model = this.editor.getModel();
if (!e.target.position || !model || e.target.type !== MouseTargetType.GUTTER_LINE_NUMBERS) {
return;
Expand All @@ -38,20 +40,27 @@ class EditorLineNumberContextMenu extends Disposable implements IEditorContribut
const anchor = { x: e.event.posx, y: e.event.posy };
const lineNumber = e.target.position.lineNumber;

const actions = Separator.join(...this.menu.getActions().map(a => a[1]));
let actions: IAction[] = [];

// TODO@joyceerhl refactor breakpoint and testing actions to statically contribute to this menu
const contribution = this.editor.getContribution<IBreakpointEditorContribution>(BREAKPOINT_EDITOR_CONTRIBUTION_ID);
if (contribution) {
actions.push(...contribution.getContextMenuActionsAtPosition(lineNumber, model));
}
const menuActions = menu.getActions();
if (menuActions.length > 0) {
actions = Separator.join(...[actions], ...menuActions.map(a => a[1]));
}

this.contextMenuService.showContextMenu({
getAnchor: () => anchor,
getActions: () => actions,
menuActionOptions: { shouldForwardArgs: true },
getActionsContext: () => ({ lineNumber, uri: model.uri }),
onHide: () => menu.dispose(),
});
}));
}
}

registerEditorContribution('workbench.contrib.editorLineNumberContextMenu', EditorLineNumberContextMenu, EditorContributionInstantiation.AfterFirstRender);
registerEditorContribution(EditorLineNumberContextMenu.ID, EditorLineNumberContextMenu, EditorContributionInstantiation.AfterFirstRender);
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ const apiMenus: IAPIMenu[] = [
key: 'editor/lineNumber/context',
id: MenuId.EditorLineNumberContext,
description: localize('editorLineNumberContext', "The contributed editor line number context menu"),
proposed: 'contribShareMenu'
proposed: 'contribEditorLineNumberMenu'
},
{
key: 'mergeEditor/result/title',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const allApiProposals = Object.freeze({
contribCommentThreadAdditionalMenu: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribCommentThreadAdditionalMenu.d.ts',
contribEditSessions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribEditSessions.d.ts',
contribEditorContentMenu: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribEditorContentMenu.d.ts',
contribEditorLineNumberMenu: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribEditorLineNumberMenu.d.ts',
contribLabelFormatterWorkspaceTooltip: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribLabelFormatterWorkspaceTooltip.d.ts',
contribMenuBarHome: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribMenuBarHome.d.ts',
contribMergeEditorMenus: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribMergeEditorMenus.d.ts',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// empty placeholder declaration for the `editor/lineNumber/context` menu contribution point

// https://github.com/microsoft/vscode/issues/175945 @joyceerhl

0 comments on commit f04ee59

Please sign in to comment.