From ab8726f4ad474e24b2c07926e901a978fb065511 Mon Sep 17 00:00:00 2001 From: Colin Grant Date: Wed, 1 Mar 2023 23:36:06 +0100 Subject: [PATCH] Make editors own decorations; move listeners into models --- .../src/browser/editor/debug-editor-model.ts | 35 ++++++++++++++++--- .../browser/editor/debug-editor-service.ts | 14 -------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/packages/debug/src/browser/editor/debug-editor-model.ts b/packages/debug/src/browser/editor/debug-editor-model.ts index af29c2ae85724..c78f8359b23cb 100644 --- a/packages/debug/src/browser/editor/debug-editor-model.ts +++ b/packages/debug/src/browser/editor/debug-editor-model.ts @@ -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'; @@ -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()); @@ -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(); @@ -243,7 +252,7 @@ export class DebugEditorModel implements Disposable { }); } - render(): void { + protected render(): void { this.renderBreakpoints(); this.renderCurrentBreakpoints(); } @@ -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 { @@ -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'; @@ -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; } diff --git a/packages/debug/src/browser/editor/debug-editor-service.ts b/packages/debug/src/browser/editor/debug-editor-service.ts index d315fe314193a..59bd35335e3ca 100644 --- a/packages/debug/src/browser/editor/debug-editor-service.ts +++ b/packages/debug/src/browser/editor/debug-editor-service.ts @@ -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'; @@ -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 { @@ -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();