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

Defer creation of editor/lineNumber/context menu #175946

Merged
merged 2 commits into from
Mar 2, 2023
Merged
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
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