Skip to content

Commit

Permalink
Fix breakpoint context menu behaviour
Browse files Browse the repository at this point in the history
Signed-off-by: thegecko <[email protected]>
  • Loading branch information
thegecko committed Nov 6, 2019
1 parent 602f44d commit fa9cf9d
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ElectronContextMenuRenderer implements ContextMenuRenderer {
// native context menu stops the event loop, so there is no keyboard events
this.context.resetAltPressed();
if (onHide) {
onHide();
menu.once('menu-will-close', () => onHide());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,60 +747,61 @@ export class DebugFrontendApplicationContribution extends AbstractViewContributi
isVisible: () => !!this.selectedVariable && this.selectedVariable.supportCopyAsExpression
});

// Debug context menu commands
registry.registerCommand(DebugEditorContextCommands.ADD_BREAKPOINT, {
execute: () => this.editors.toggleBreakpoint(),
isEnabled: () => !this.editors.anyBreakpoint,
isVisible: () => !this.editors.anyBreakpoint
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)
});
registry.registerCommand(DebugEditorContextCommands.ADD_CONDITIONAL_BREAKPOINT, {
execute: () => this.editors.addBreakpoint('condition'),
isEnabled: () => !this.editors.anyBreakpoint,
isVisible: () => !this.editors.anyBreakpoint
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)
});
registry.registerCommand(DebugEditorContextCommands.ADD_LOGPOINT, {
execute: () => this.editors.addBreakpoint('logMessage'),
isEnabled: () => !this.editors.anyBreakpoint,
isVisible: () => !this.editors.anyBreakpoint
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)
});
registry.registerCommand(DebugEditorContextCommands.REMOVE_BREAKPOINT, {
execute: () => this.editors.toggleBreakpoint(),
isEnabled: () => !!this.editors.breakpoint,
isVisible: () => !!this.editors.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)
});
registry.registerCommand(DebugEditorContextCommands.EDIT_BREAKPOINT, {
execute: () => this.editors.editBreakpoint(),
isEnabled: () => !!this.editors.breakpoint,
isVisible: () => !!this.editors.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)
});
registry.registerCommand(DebugEditorContextCommands.ENABLE_BREAKPOINT, {
execute: () => this.editors.setBreakpointEnabled(true),
isEnabled: () => this.editors.breakpointEnabled === false,
isVisible: () => this.editors.breakpointEnabled === false
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
});
registry.registerCommand(DebugEditorContextCommands.DISABLE_BREAKPOINT, {
execute: () => this.editors.setBreakpointEnabled(false),
isEnabled: () => !!this.editors.breakpointEnabled,
isVisible: () => !!this.editors.breakpointEnabled
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)
});
registry.registerCommand(DebugEditorContextCommands.REMOVE_LOGPOINT, {
execute: () => this.editors.toggleBreakpoint(),
isEnabled: () => !!this.editors.logpoint,
isVisible: () => !!this.editors.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)
});
registry.registerCommand(DebugEditorContextCommands.EDIT_LOGPOINT, {
execute: () => this.editors.editBreakpoint(),
isEnabled: () => !!this.editors.logpoint,
isVisible: () => !!this.editors.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)
});
registry.registerCommand(DebugEditorContextCommands.ENABLE_LOGPOINT, {
execute: () => this.editors.setBreakpointEnabled(true),
isEnabled: () => this.editors.logpointEnabled === false,
isVisible: () => this.editors.logpointEnabled === false
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
});
registry.registerCommand(DebugEditorContextCommands.DISABLE_LOGPOINT, {
execute: () => this.editors.setBreakpointEnabled(false),
isEnabled: () => !!this.editors.logpointEnabled,
isVisible: () => !!this.editors.logpointEnabled
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)
});

registry.registerCommand(DebugBreakpointWidgetCommands.ACCEPT, {
Expand Down Expand Up @@ -1009,4 +1010,7 @@ export class DebugFrontendApplicationContribution extends AbstractViewContributi
return variables && variables.selectedElement instanceof DebugVariable && variables.selectedElement || undefined;
}

protected isPosition(position: monaco.Position): boolean {
return (position instanceof monaco.Position);
}
}
27 changes: 12 additions & 15 deletions packages/debug/src/browser/editor/debug-editor-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,13 @@ export class DebugEditorModel implements Disposable {
return breakpoints;
}

protected _position: monaco.Position | undefined;
get position(): monaco.Position {
return this._position || this.editor.getControl().getPosition()!;
return this.editor.getControl().getPosition()!;
}
get breakpoint(): DebugBreakpoint | undefined {
return this.getBreakpoint();
}
protected getBreakpoint(position: monaco.Position = this.position): DebugBreakpoint | undefined {
getBreakpoint(position: monaco.Position = this.position): DebugBreakpoint | undefined {
return this.sessions.getBreakpoint(this.uri, position.lineNumber);
}
toggleBreakpoint(): void {
this.doToggleBreakpoint();
}
protected doToggleBreakpoint(position: monaco.Position = this.position): void {
toggleBreakpoint(position: monaco.Position = this.position): void {
const breakpoint = this.getBreakpoint(position);
if (breakpoint) {
breakpoint.remove();
Expand Down Expand Up @@ -285,12 +278,16 @@ 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._position = event.target.position!;
this.contextMenu.render(DebugEditorModel.CONTEXT_MENU, event.event.browserEvent, () =>
setTimeout(() => this._position = undefined)
);
this.editor.focus();
setTimeout(() => {
this.contextMenu.render({
menuPath: DebugEditorModel.CONTEXT_MENU,
anchor: event.event.browserEvent,
args: [event.target.position!]
});
});
} else {
this.doToggleBreakpoint(event.target.position!);
this.toggleBreakpoint(event.target.position!);
}
}
this.hintBreakpoint(event);
Expand Down
55 changes: 29 additions & 26 deletions packages/debug/src/browser/editor/debug-editor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,38 +84,38 @@ export class DebugEditorService {
return uri && this.models.get(uri.toString());
}

get logpoint(): DebugBreakpoint | undefined {
const logpoint = this.anyBreakpoint;
getLogpoint(position: monaco.Position): DebugBreakpoint | undefined {
const logpoint = this.anyBreakpoint(position);
return logpoint && logpoint.logMessage ? logpoint : undefined;
}
get logpointEnabled(): boolean | undefined {
const { logpoint } = this;
getLogpointEnabled(position: monaco.Position): boolean | undefined {
const logpoint = this.getLogpoint(position);
return logpoint && logpoint.enabled;
}

get breakpoint(): DebugBreakpoint | undefined {
const breakpoint = this.anyBreakpoint;
getBreakpoint(position: monaco.Position): DebugBreakpoint | undefined {
const breakpoint = this.anyBreakpoint(position);
return breakpoint && breakpoint.logMessage ? undefined : breakpoint;
}
get breakpointEnabled(): boolean | undefined {
const { breakpoint } = this;
getBreakpointEnabled(position: monaco.Position): boolean | undefined {
const breakpoint = this.getBreakpoint(position);
return breakpoint && breakpoint.enabled;
}

get anyBreakpoint(): DebugBreakpoint | undefined {
return this.model && this.model.breakpoint;
anyBreakpoint(position?: monaco.Position): DebugBreakpoint | undefined {
return this.model && this.model.getBreakpoint(position);
}

toggleBreakpoint(): void {
toggleBreakpoint(position?: monaco.Position): void {
const { model } = this;
if (model) {
model.toggleBreakpoint();
model.toggleBreakpoint(position);
}
}
setBreakpointEnabled(enabled: boolean): void {
const { anyBreakpoint } = this;
if (anyBreakpoint) {
anyBreakpoint.setEnabled(enabled);
setBreakpointEnabled(position: monaco.Position, enabled: boolean): void {
const breakpoint = this.anyBreakpoint(position);
if (breakpoint) {
breakpoint.setEnabled(enabled);
}
}

Expand All @@ -135,28 +135,31 @@ export class DebugEditorService {
return false;
}

addBreakpoint(context: DebugBreakpointWidget.Context): void {
addBreakpoint(context: DebugBreakpointWidget.Context, position?: monaco.Position): void {
const { model } = this;
if (model) {
const { breakpoint } = model;
position = position || model.position;
const breakpoint = model.getBreakpoint(position);
if (breakpoint) {
model.breakpointWidget.show({ breakpoint, context });
} else {
model.breakpointWidget.show({
position: model.position,
position,
context
});
}
}
}
editBreakpoint(): Promise<void>;
editBreakpoint(breakpoint: DebugBreakpoint): Promise<void>;
async editBreakpoint(breakpoint: DebugBreakpoint | undefined = this.anyBreakpoint): Promise<void> {
if (breakpoint) {
await breakpoint.open();
const model = this.models.get(breakpoint.uri.toString());
async editBreakpoint(breakpointOrPosition?: DebugBreakpoint | monaco.Position): Promise<void> {
if (breakpointOrPosition instanceof monaco.Position) {
breakpointOrPosition = this.anyBreakpoint(breakpointOrPosition);
}

if (breakpointOrPosition) {
await breakpointOrPosition.open();
const model = this.models.get(breakpointOrPosition.uri.toString());
if (model) {
model.breakpointWidget.show(breakpoint);
model.breakpointWidget.show(breakpointOrPosition);
}
}
}
Expand Down

0 comments on commit fa9cf9d

Please sign in to comment.