From fee75c22a6d5a76bd270fea2a2b0644717b29d2a Mon Sep 17 00:00:00 2001 From: Anton Kosyakov Date: Fri, 14 Aug 2020 10:13:16 +0000 Subject: [PATCH] fix #8225: fix debug exception height computation Signed-off-by: Anton Kosyakov --- .../src/browser/editor/debug-editor-model.ts | 2 +- .../browser/editor/debug-exception-widget.tsx | 61 +++++++++++++------ 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/packages/debug/src/browser/editor/debug-editor-model.ts b/packages/debug/src/browser/editor/debug-editor-model.ts index b570a4e9cb3af..9d122756af3f0 100644 --- a/packages/debug/src/browser/editor/debug-editor-model.ts +++ b/packages/debug/src/browser/editor/debug-editor-model.ts @@ -175,7 +175,7 @@ export class DebugEditorModel implements Disposable { protected async toggleExceptionWidget(): Promise { const { currentFrame } = this.sessions; - if (!currentFrame) { + if (!currentFrame || !currentFrame.source || currentFrame.source.uri.toString() !== this.uri.toString()) { this.exceptionWidget.hide(); return; } diff --git a/packages/debug/src/browser/editor/debug-exception-widget.tsx b/packages/debug/src/browser/editor/debug-exception-widget.tsx index 8c7801d89888d..53b7d4f45063d 100644 --- a/packages/debug/src/browser/editor/debug-exception-widget.tsx +++ b/packages/debug/src/browser/editor/debug-exception-widget.tsx @@ -28,6 +28,22 @@ export interface ShowDebugExceptionParams { column: number } +export class DebugExceptionMonacoEditorZoneWidget extends MonacoEditorZoneWidget { + + protected computeContainerHeight(zoneHeight: number): { + height: number, + frameWidth: number + } { + // reset height to match it to the content + this.containerNode.style.height = 'initial'; + const height = this.containerNode.offsetHeight; + const result = super.computeContainerHeight(zoneHeight); + result.height = height; + return result; + } + +} + @injectable() export class DebugExceptionWidget implements Disposable { @@ -40,9 +56,10 @@ export class DebugExceptionWidget implements Disposable { @postConstruct() protected async init(): Promise { - this.toDispose.push(this.zone = new MonacoEditorZoneWidget(this.editor.getControl())); + this.toDispose.push(this.zone = new DebugExceptionMonacoEditorZoneWidget(this.editor.getControl())); this.zone.containerNode.classList.add('theia-debug-exception-widget'); this.toDispose.push(Disposable.create(() => ReactDOM.unmountComponentAtNode(this.zone.containerNode))); + this.toDispose.push(this.editor.getControl().onDidLayoutChange(() => this.layout())); } dispose(): void { @@ -50,35 +67,41 @@ export class DebugExceptionWidget implements Disposable { } show({ info, lineNumber, column }: ShowDebugExceptionParams): void { - this.render(info); - - const fontInfo = this.editor.getControl().getOption(monaco.editor.EditorOption.fontInfo); - this.zone.containerNode.style.fontSize = `${fontInfo.fontSize}px`; - this.zone.containerNode.style.lineHeight = `${fontInfo.lineHeight}px`; - - if (lineNumber !== undefined && column !== undefined) { - const afterLineNumber = lineNumber; - const afterColumn = column; - const heightInLines = 0; - this.zone.show({ showFrame: true, afterLineNumber, afterColumn, heightInLines, frameWidth: 1 }); - } + this.render(info, () => { + const fontInfo = this.editor.getControl().getOption(monaco.editor.EditorOption.fontInfo); + this.zone.containerNode.style.fontSize = `${fontInfo.fontSize}px`; + this.zone.containerNode.style.lineHeight = `${fontInfo.lineHeight}px`; + + if (lineNumber !== undefined && column !== undefined) { + const afterLineNumber = lineNumber; + const afterColumn = column; + this.zone.show({ showFrame: true, afterLineNumber, afterColumn, heightInLines: 0, frameWidth: 1 }); + } + + this.layout(); + }); } hide(): void { this.zone.hide(); } - protected render(info: DebugExceptionInfo): void { + protected render(info: DebugExceptionInfo, cb: () => void): void { const stackTrace = info.details && info.details.stackTrace; ReactDOM.render(
{info.id ? `Exception has occurred: ${info.id}` : 'Exception has occurred.'}
{info.description &&
{info.description}
} {stackTrace &&
{stackTrace}
} -
, this.zone.containerNode, () => { - const lineHeight = this.editor.getControl().getOption(monaco.editor.EditorOption.lineHeight); - const heightInLines = Math.ceil(this.zone.containerNode.offsetHeight / lineHeight); - this.zone.layout(heightInLines); - }); + , this.zone.containerNode, cb); + } + + protected layout(): void { + // reset height to match it to the content + this.zone.containerNode.style.height = 'initial'; + + const lineHeight = this.editor.getControl().getOption(monaco.editor.EditorOption.lineHeight); + const heightInLines = Math.ceil(this.zone.containerNode.offsetHeight / lineHeight); + this.zone.layout(heightInLines); } }