Skip to content

Commit

Permalink
editor: combine left gutter context menus (#12794)
Browse files Browse the repository at this point in the history
Combine the context menus created by

  - debug in area left of the line numbers and
  - editor in the line numbers, themselves

into one context menu, managed by the editor
extension, opened either from the line numbers
or from the gutter area to their left, for
consistency with the VS Code behaviour of the
'editor/lineNumber/context' contribution point.

Fixes #12688

Signed-off-by: Christian W. Damus <give.a.damus@gmail.com>
  • Loading branch information
cdamus authored Aug 11, 2023
1 parent 9d2684d commit 2d91943
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
} from '@theia/core/lib/browser';
import { injectable, inject } from '@theia/core/shared/inversify';
import * as monaco from '@theia/monaco-editor-core';
import { MenuModelRegistry, CommandRegistry, MAIN_MENU_BAR, Command, Emitter, Mutable } from '@theia/core/lib/common';
import { EditorKeybindingContexts, EditorManager } from '@theia/editor/lib/browser';
import { MenuModelRegistry, CommandRegistry, MAIN_MENU_BAR, Command, Emitter, Mutable, CompoundMenuNodeRole } from '@theia/core/lib/common';
import { EDITOR_LINENUMBER_CONTEXT_MENU, EditorKeybindingContexts, EditorManager } from '@theia/editor/lib/browser';
import { DebugSessionManager } from './debug-session-manager';
import { DebugWidget } from './view/debug-widget';
import { FunctionBreakpoint } from './breakpoint/breakpoint-marker';
Expand Down Expand Up @@ -627,6 +627,7 @@ export class DebugFrontendApplicationContribution extends AbstractViewContributi
{ ...DebugEditorContextCommands.ENABLE_LOGPOINT, label: nlsEnableBreakpoint('Logpoint') },
{ ...DebugEditorContextCommands.DISABLE_LOGPOINT, label: nlsDisableBreakpoint('Logpoint') }
);
menus.linkSubmenu(EDITOR_LINENUMBER_CONTEXT_MENU, DebugEditorModel.CONTEXT_MENU, { role: CompoundMenuNodeRole.Group });
}

override registerCommands(registry: CommandRegistry): void {
Expand Down Expand Up @@ -882,59 +883,59 @@ export class DebugFrontendApplicationContribution extends AbstractViewContributi

// Debug context menu commands
registry.registerCommand(DebugEditorContextCommands.ADD_BREAKPOINT, {
execute: position => this.isPosition(position) && this.editors.toggleBreakpoint(position),
isEnabled: position => this.isPosition(position) && !this.editors.anyBreakpoint(position),
isVisible: position => this.isPosition(position) && !this.editors.anyBreakpoint(position)
execute: position => this.isPosition(position) && this.editors.toggleBreakpoint(this.asPosition(position)),
isEnabled: position => this.isPosition(position) && !this.editors.anyBreakpoint(this.asPosition(position)),
isVisible: position => this.isPosition(position) && !this.editors.anyBreakpoint(this.asPosition(position))
});
registry.registerCommand(DebugEditorContextCommands.ADD_CONDITIONAL_BREAKPOINT, {
execute: position => this.isPosition(position) && this.editors.addBreakpoint('condition', position),
isEnabled: position => this.isPosition(position) && !this.editors.anyBreakpoint(position),
isVisible: position => this.isPosition(position) && !this.editors.anyBreakpoint(position)
execute: position => this.isPosition(position) && this.editors.addBreakpoint('condition', this.asPosition(position)),
isEnabled: position => this.isPosition(position) && !this.editors.anyBreakpoint(this.asPosition(position)),
isVisible: position => this.isPosition(position) && !this.editors.anyBreakpoint(this.asPosition(position))
});
registry.registerCommand(DebugEditorContextCommands.ADD_LOGPOINT, {
execute: position => this.isPosition(position) && this.editors.addBreakpoint('logMessage', position),
isEnabled: position => this.isPosition(position) && !this.editors.anyBreakpoint(position),
isVisible: position => this.isPosition(position) && !this.editors.anyBreakpoint(position)
execute: position => this.isPosition(position) && this.editors.addBreakpoint('logMessage', this.asPosition(position)),
isEnabled: position => this.isPosition(position) && !this.editors.anyBreakpoint(this.asPosition(position)),
isVisible: position => this.isPosition(position) && !this.editors.anyBreakpoint(this.asPosition(position))
});
registry.registerCommand(DebugEditorContextCommands.REMOVE_BREAKPOINT, {
execute: position => this.isPosition(position) && this.editors.toggleBreakpoint(position),
isEnabled: position => this.isPosition(position) && !!this.editors.getBreakpoint(position),
isVisible: position => this.isPosition(position) && !!this.editors.getBreakpoint(position)
execute: position => this.isPosition(position) && this.editors.toggleBreakpoint(this.asPosition(position)),
isEnabled: position => this.isPosition(position) && !!this.editors.getBreakpoint(this.asPosition(position)),
isVisible: position => this.isPosition(position) && !!this.editors.getBreakpoint(this.asPosition(position))
});
registry.registerCommand(DebugEditorContextCommands.EDIT_BREAKPOINT, {
execute: position => this.isPosition(position) && this.editors.editBreakpoint(position),
isEnabled: position => this.isPosition(position) && !!this.editors.getBreakpoint(position),
isVisible: position => this.isPosition(position) && !!this.editors.getBreakpoint(position)
execute: position => this.isPosition(position) && this.editors.editBreakpoint(this.asPosition(position)),
isEnabled: position => this.isPosition(position) && !!this.editors.getBreakpoint(this.asPosition(position)),
isVisible: position => this.isPosition(position) && !!this.editors.getBreakpoint(this.asPosition(position))
});
registry.registerCommand(DebugEditorContextCommands.ENABLE_BREAKPOINT, {
execute: position => this.isPosition(position) && this.editors.setBreakpointEnabled(position, true),
isEnabled: position => this.isPosition(position) && this.editors.getBreakpointEnabled(position) === false,
isVisible: position => this.isPosition(position) && this.editors.getBreakpointEnabled(position) === false
execute: position => this.isPosition(position) && this.editors.setBreakpointEnabled(this.asPosition(position), true),
isEnabled: position => this.isPosition(position) && this.editors.getBreakpointEnabled(this.asPosition(position)) === false,
isVisible: position => this.isPosition(position) && this.editors.getBreakpointEnabled(this.asPosition(position)) === false
});
registry.registerCommand(DebugEditorContextCommands.DISABLE_BREAKPOINT, {
execute: position => this.isPosition(position) && this.editors.setBreakpointEnabled(position, false),
isEnabled: position => this.isPosition(position) && !!this.editors.getBreakpointEnabled(position),
isVisible: position => this.isPosition(position) && !!this.editors.getBreakpointEnabled(position)
execute: position => this.isPosition(position) && this.editors.setBreakpointEnabled(this.asPosition(position), false),
isEnabled: position => this.isPosition(position) && !!this.editors.getBreakpointEnabled(this.asPosition(position)),
isVisible: position => this.isPosition(position) && !!this.editors.getBreakpointEnabled(this.asPosition(position))
});
registry.registerCommand(DebugEditorContextCommands.REMOVE_LOGPOINT, {
execute: position => this.isPosition(position) && this.editors.toggleBreakpoint(position),
isEnabled: position => this.isPosition(position) && !!this.editors.getLogpoint(position),
isVisible: position => this.isPosition(position) && !!this.editors.getLogpoint(position)
execute: position => this.isPosition(position) && this.editors.toggleBreakpoint(this.asPosition(position)),
isEnabled: position => this.isPosition(position) && !!this.editors.getLogpoint(this.asPosition(position)),
isVisible: position => this.isPosition(position) && !!this.editors.getLogpoint(this.asPosition(position))
});
registry.registerCommand(DebugEditorContextCommands.EDIT_LOGPOINT, {
execute: position => this.isPosition(position) && this.editors.editBreakpoint(position),
isEnabled: position => this.isPosition(position) && !!this.editors.getLogpoint(position),
isVisible: position => this.isPosition(position) && !!this.editors.getLogpoint(position)
execute: position => this.isPosition(position) && this.editors.editBreakpoint(this.asPosition(position)),
isEnabled: position => this.isPosition(position) && !!this.editors.getLogpoint(this.asPosition(position)),
isVisible: position => this.isPosition(position) && !!this.editors.getLogpoint(this.asPosition(position))
});
registry.registerCommand(DebugEditorContextCommands.ENABLE_LOGPOINT, {
execute: position => this.isPosition(position) && this.editors.setBreakpointEnabled(position, true),
isEnabled: position => this.isPosition(position) && this.editors.getLogpointEnabled(position) === false,
isVisible: position => this.isPosition(position) && this.editors.getLogpointEnabled(position) === false
execute: position => this.isPosition(position) && this.editors.setBreakpointEnabled(this.asPosition(position), true),
isEnabled: position => this.isPosition(position) && this.editors.getLogpointEnabled(this.asPosition(position)) === false,
isVisible: position => this.isPosition(position) && this.editors.getLogpointEnabled(this.asPosition(position)) === false
});
registry.registerCommand(DebugEditorContextCommands.DISABLE_LOGPOINT, {
execute: position => this.isPosition(position) && this.editors.setBreakpointEnabled(position, false),
isEnabled: position => this.isPosition(position) && !!this.editors.getLogpointEnabled(position),
isVisible: position => this.isPosition(position) && !!this.editors.getLogpointEnabled(position)
execute: position => this.isPosition(position) && this.editors.setBreakpointEnabled(this.asPosition(position), false),
isEnabled: position => this.isPosition(position) && !!this.editors.getLogpointEnabled(this.asPosition(position)),
isVisible: position => this.isPosition(position) && !!this.editors.getLogpointEnabled(this.asPosition(position))
});

registry.registerCommand(DebugBreakpointWidgetCommands.ACCEPT, {
Expand Down Expand Up @@ -1263,8 +1264,12 @@ export class DebugFrontendApplicationContribution extends AbstractViewContributi
return watch && watch.selectedElement instanceof DebugWatchExpression && watch.selectedElement || undefined;
}

protected isPosition(position: monaco.Position): boolean {
return (position instanceof monaco.Position);
protected isPosition(position: unknown): boolean {
return monaco.Position.isIPosition(position);
}

protected asPosition(position: monaco.IPosition): monaco.Position {
return monaco.Position.lift(position);
}

registerColors(colors: ColorRegistry): void {
Expand Down
11 changes: 1 addition & 10 deletions packages/debug/src/browser/editor/debug-editor-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,7 @@ export class DebugEditorModel implements Disposable {

protected handleMouseDown(event: monaco.editor.IEditorMouseEvent): void {
if (event.target && event.target.type === monaco.editor.MouseTargetType.GUTTER_GLYPH_MARGIN) {
if (event.event.rightButton) {
this.editor.focus();
setTimeout(() => {
this.contextMenu.render({
menuPath: DebugEditorModel.CONTEXT_MENU,
anchor: event.event.browserEvent,
args: [event.target.position!]
});
});
} else {
if (!event.event.rightButton) {
this.toggleBreakpoint(event.target.position!);
}
}
Expand Down
5 changes: 3 additions & 2 deletions packages/editor/src/browser/editor-linenumber-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ export class EditorLineNumberContribution implements FrontendApplicationContribu
}

protected handleContextMenu(editor: TextEditor, event: EditorMouseEvent): void {
if (event.target && event.target.type === MouseTargetType.GUTTER_LINE_NUMBERS) {
if (event.target && (event.target.type === MouseTargetType.GUTTER_LINE_NUMBERS || event.target.type === MouseTargetType.GUTTER_GLYPH_MARGIN)) {
if (event.event.button === 2) {
editor.focus();
const lineNumber = lineNumberFromPosition(event.target.position);
const contextKeyService = this.contextKeyService.createOverlay([['editorLineNumber', lineNumber]]);
const uri = editor.getResourceUri()!;
const args = [{
lineNumber: lineNumber,
uri: uri['codeUri']
column: 1, // Compatible with Monaco editor IPosition API
uri: uri['codeUri'],
}];

setTimeout(() => {
Expand Down

0 comments on commit 2d91943

Please sign in to comment.