From 39c4261bc507f8fdcbc4d226c25a711728c3561d Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 10 May 2021 12:12:19 -0700 Subject: [PATCH] Clean up --- .../contrib/terminal/browser/terminalGroup.ts | 3 - .../terminal/browser/terminalInstance.ts | 57 ++++++------------- 2 files changed, 16 insertions(+), 44 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/terminalGroup.ts b/src/vs/workbench/contrib/terminal/browser/terminalGroup.ts index 2a7fcd93ea2..8adc82d2039 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalGroup.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalGroup.ts @@ -148,7 +148,6 @@ class SplitPaneContainer extends Disposable { layout(width: number, height: number): void { this._width = width; this._height = height; - console.log('SplitPaneContainer.layout', width, height); if (this.orientation === Orientation.HORIZONTAL) { this._children.forEach(c => c.orthogonalLayout(height)); this._splitView.layout(width); @@ -211,7 +210,6 @@ class SplitPane implements IView { } layout(size: number): void { - console.log(`SplitPane.layout (${this.instance.instanceId})`, size, this.orthogonalSize); // Only layout when both sizes are known if (!size || !this.orthogonalSize) { return; @@ -436,7 +434,6 @@ export class TerminalGroup extends Disposable implements ITerminalGroup { if (this._groupElement) { this._groupElement.style.display = visible ? '' : 'none'; } - console.log('TerminalGroup.setVisible'); this.terminalInstances.forEach(i => i.setVisible(visible)); } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts index 786e49abac4..ed81cc620cf 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts @@ -132,6 +132,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { private _navigationModeAddon: INavigationMode & ITerminalAddon | undefined; private _timeoutDimension: dom.Dimension | undefined; + private _lastLayoutDimensions: dom.Dimension | undefined; private _hasHadInput: boolean; @@ -346,8 +347,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { } private _initDimensions(): void { - console.log('initDimensions, container?', this._container); - // The terminal panel needs to have been created if (!this._container) { return; @@ -369,21 +368,18 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { // Ignore if dimensions are undefined or 0 if (!width || !height) { this._setLastKnownColsAndRows(); - console.log('1'); return null; } const dimension = this._getDimension(width, height); if (!dimension) { this._setLastKnownColsAndRows(); - console.log('2'); return null; } const font = this._configHelper.getFont(this._xtermCore); if (!font.charWidth || !font.charHeight) { this._setLastKnownColsAndRows(); - console.log('3'); return null; } @@ -402,7 +398,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { const newRows = Math.max(Math.floor(scaledHeightAvailable / scaledLineHeight), 1); if (this._cols !== newCols || this._rows !== newRows) { - console.log('newRows', newRows); this._cols = newCols; this._rows = newRows; this._fireMaximumDimensionsChanged(); @@ -427,18 +422,10 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { // The font needs to have been initialized const font = this._configHelper.getFont(this._xtermCore); if (!font || !font.charWidth || !font.charHeight) { - console.log('a'); return undefined; } - // The panel is minimized - // if (!this._isVisible) { - // console.log('b'); - // return TerminalInstance._lastKnownCanvasDimensions; - // } - if (!this._wrapperElement) { - console.log('c'); return undefined; } @@ -488,8 +475,9 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { xtermRendererType = config.gpuAcceleration === 'on' ? 'canvas' : 'dom'; } - console.log('create 80x30 terminal', this._cols, this._rows); const xterm = new Terminal({ + cols: this._cols || undefined, + rows: this._rows || undefined, altClickMovesCursor: config.altClickMovesCursor && editorOptions.multiCursorModifier === 'alt', scrollback: config.scrollback, theme: this._getXtermTheme(), @@ -593,7 +581,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { } attachToElement(container: HTMLElement): Promise | void { - console.log('external attachToElement'); // The container did not change, do nothing if (this._container === container) { return; @@ -611,8 +598,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { } private async _attachToElement(container: HTMLElement): Promise { - console.log('_attachToElement', container); - if (this._wrapperElement) { throw new Error('The terminal instance has already been attached to a container'); } @@ -765,10 +750,12 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { this._processManager.onProcessReady(() => this._linkManager?.setWidgetManager(this._widgetManager)); // const computedStyle = window.getComputedStyle(this._container); - const computedStyle = window.getComputedStyle(this._container.parentElement!); - const width = parseInt(computedStyle.getPropertyValue('width').replace('px', ''), 10); - const height = parseInt(computedStyle.getPropertyValue('height').replace('px', ''), 10); - this.layout(new dom.Dimension(width, height)); + // const computedStyle = window.getComputedStyle(this._container.parentElement!); + // const width = parseInt(computedStyle.getPropertyValue('width').replace('px', ''), 10); + // const height = parseInt(computedStyle.getPropertyValue('height').replace('px', ''), 10); + if (this._lastLayoutDimensions) { + this.layout(this._lastLayoutDimensions); + } this.setVisible(this._isVisible); this.updateConfig(); @@ -986,7 +973,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { } setVisible(visible: boolean): void { - console.log('setVisible', visible); this._isVisible = visible; if (this._wrapperElement) { this._wrapperElement.classList.toggle('active', visible); @@ -999,21 +985,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { // This can likely be removed after https://github.com/xtermjs/xterm.js/issues/291 is // fixed upstream. this._xtermCore._onScroll.fire(this._xterm.buffer.active.viewportY); - if (this._container && this._container.parentElement) { - // Force a layout when the instance becomes visible. This is particularly important - // for ensuring that terminals that are created in the background by an extension will - // correctly get correct character measurements in order to render to the screen (see - // #34554). - // const computedStyle = window.getComputedStyle(this._container.parentElement); - // const width = parseInt(computedStyle.getPropertyValue('width').replace('px', ''), 10); - // const height = parseInt(computedStyle.getPropertyValue('height').replace('px', ''), 10); - // this.layout(new dom.Dimension(width, height)); - // HACK: Trigger another async layout to ensure xterm's CharMeasure is ready to use, - // this hack can be removed when https://github.com/xtermjs/xterm.js/issues/702 is - // supported. - // this._timeoutDimension = new dom.Dimension(width, height); - // setTimeout(() => this.layout(this._timeoutDimension!), 0); - } } } @@ -1504,12 +1475,17 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { } layout(dimension: dom.Dimension): void { + this._lastLayoutDimensions = dimension; if (this.disableLayout) { - console.log('disableLayout'); return; } - console.log('layout', dimension); + // Don't layout if dimensions are invalid (eg. the container is not attached to the DOM or + // if display: none + if (dimension.width <= 0 || dimension.height <= 0) { + return; + } + const terminalWidth = this._evaluateColsAndRows(dimension.width, dimension.height); if (!terminalWidth) { return; @@ -1565,7 +1541,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { this._onDimensionsChanged.fire(); } - console.log('resize now', cols, rows); this._xterm.resize(cols, rows); TerminalInstance._lastKnownGridDimensions = { cols, rows }; -- GitLab