Skip to content

Commit

Permalink
Make editors own decorations; move listeners into models
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-grant-work committed Mar 1, 2023
1 parent e2f76b6 commit ab8726f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
35 changes: 30 additions & 5 deletions packages/debug/src/browser/editor/debug-editor-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import URI from '@theia/core/lib/common/uri';
import { Disposable, DisposableCollection, MenuPath, isOSX } from '@theia/core';
import { ContextMenuRenderer } from '@theia/core/lib/browser';
import { MonacoConfigurationService } from '@theia/monaco/lib/browser/monaco-frontend-module';
import { BreakpointManager } from '../breakpoint/breakpoint-manager';
import { BreakpointManager, SourceBreakpointsChangeEvent } from '../breakpoint/breakpoint-manager';
import { DebugSourceBreakpoint } from '../model/debug-source-breakpoint';
import { DebugSessionManager } from '../debug-session-manager';
import { SourceBreakpoint } from '../breakpoint/breakpoint-marker';
Expand Down Expand Up @@ -97,6 +97,9 @@ export class DebugEditorModel implements Disposable {
@inject(MonacoConfigurationService)
readonly configurationService: IConfigurationService;

@inject(DebugSessionManager)
protected readonly sessionManager: DebugSessionManager;

@postConstruct()
protected init(): void {
this.uri = new URI(this.editor.getControl().getModel()!.uri.toString());
Expand All @@ -112,7 +115,13 @@ export class DebugEditorModel implements Disposable {
this.editor.getControl().getModel()!.onDidChangeDecorations(() => this.updateBreakpoints()),
this.editor.onDidResize(e => this.breakpointWidget.inputSize = e),
this.sessions.onDidChange(() => this.update()),
this.toDisposeOnUpdate
this.toDisposeOnUpdate,
this.sessionManager.onDidChangeBreakpoints(({ session, uri }) => {
if ((!session || session === this.sessionManager.currentSession) && uri.isEqual(this.uri)) {
this.render();
}
}),
this.breakpoints.onDidChangeBreakpoints(event => this.closeBreakpointIfAffected(event)),
]);
this.update();
this.render();
Expand Down Expand Up @@ -243,7 +252,7 @@ export class DebugEditorModel implements Disposable {
});
}

render(): void {
protected render(): void {
this.renderBreakpoints();
this.renderCurrentBreakpoints();
}
Expand Down Expand Up @@ -404,7 +413,7 @@ export class DebugEditorModel implements Disposable {
this.contextMenu.render({
menuPath: DebugEditorModel.CONTEXT_MENU,
anchor: event.event.browserEvent,
args: [event.target.position!]
args: [event.target.position!, this]
});
});
} else {
Expand Down Expand Up @@ -444,6 +453,22 @@ export class DebugEditorModel implements Disposable {
return [];
}

protected closeBreakpointIfAffected({ uri, removed }: SourceBreakpointsChangeEvent): void {
if (!uri.isEqual(this.uri)) {
return;
}
const position = this.breakpointWidget.position;
if (!position) {
return;
}
for (const breakpoint of removed) {
if (breakpoint.raw.line === position.lineNumber) {
this.breakpointWidget.hide();
break;
}
}
}

protected showHover(mouseEvent: monaco.editor.IEditorMouseEvent): void {
const targetType = mouseEvent.target.type;
const stopKey = isOSX ? 'metaKey' : 'ctrlKey';
Expand Down Expand Up @@ -472,7 +497,7 @@ export class DebugEditorModel implements Disposable {
protected deltaDecorations(oldDecorations: string[], newDecorations: monaco.editor.IModelDeltaDecoration[]): string[] {
this.updatingDecorations = true;
try {
return this.editor.getControl().getModel()!.deltaDecorations(oldDecorations, newDecorations);
return this.editor.getControl().deltaDecorations(oldDecorations, newDecorations);
} finally {
this.updatingDecorations = false;
}
Expand Down
14 changes: 0 additions & 14 deletions packages/debug/src/browser/editor/debug-editor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
import * as monaco from '@theia/monaco-editor-core';
import URI from '@theia/core/lib/common/uri';
import { EditorManager, EditorWidget } from '@theia/editor/lib/browser';
import { ContextMenuRenderer } from '@theia/core/lib/browser';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
Expand Down Expand Up @@ -50,12 +49,6 @@ export class DebugEditorService {
protected init(): void {
this.editors.all.forEach(widget => this.push(widget));
this.editors.onCreated(widget => this.push(widget));
this.sessionManager.onDidChangeBreakpoints(({ session, uri }) => {
if (!session || session === this.sessionManager.currentSession) {
this.render(uri);
}
});
this.breakpoints.onDidChangeBreakpoints(event => this.closeBreakpointIfAffected(event));
}

protected push(widget: EditorWidget): void {
Expand All @@ -72,13 +65,6 @@ export class DebugEditorService {
});
}

protected render(uri: URI): void {
const model = this.models.get(uri.toString());
if (model) {
model.render();
}
}

get model(): DebugEditorModel | undefined {
const { currentEditor } = this.editors;
const uri = currentEditor && currentEditor.getResourceUri();
Expand Down

0 comments on commit ab8726f

Please sign in to comment.