diff --git a/addons/xterm-addon-fit/src/FitAddon.ts b/addons/xterm-addon-fit/src/FitAddon.ts index 360397ec..7b9c228f 100644 --- a/addons/xterm-addon-fit/src/FitAddon.ts +++ b/addons/xterm-addon-fit/src/FitAddon.ts @@ -63,6 +63,9 @@ export class FitAddon implements ITerminalAddon { return undefined; } + const scrollbarWidth = this._terminal.options.scrollback === 0 ? + 0 : core.viewport.scrollBarWidth; + const parentElementStyle = window.getComputedStyle(this._terminal.element.parentElement); const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')); const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width'))); @@ -76,7 +79,7 @@ export class FitAddon implements ITerminalAddon { const elementPaddingVer = elementPadding.top + elementPadding.bottom; const elementPaddingHor = elementPadding.right + elementPadding.left; const availableHeight = parentElementHeight - elementPaddingVer; - const availableWidth = parentElementWidth - elementPaddingHor - core.viewport.scrollBarWidth; + const availableWidth = parentElementWidth - elementPaddingHor - scrollbarWidth; const geometry = { cols: Math.max(MINIMUM_COLS, Math.floor(availableWidth / core._renderService.dimensions.actualCellWidth)), rows: Math.max(MINIMUM_ROWS, Math.floor(availableHeight / core._renderService.dimensions.actualCellHeight)) diff --git a/src/browser/Viewport.ts b/src/browser/Viewport.ts index 14fab897..1eb9dc4e 100644 --- a/src/browser/Viewport.ts +++ b/src/browser/Viewport.ts @@ -26,7 +26,6 @@ export class Viewport extends Disposable implements IViewport { private _lastRecordedBufferHeight: number = 0; private _lastTouchY: number = 0; private _lastScrollTop: number = 0; - private _lastHadScrollBar: boolean = false; private _activeBuffer: IBuffer; private _renderDimensions: IRenderDimensions; @@ -54,7 +53,6 @@ export class Viewport extends Disposable implements IViewport { // Unfortunately the overlay scrollbar would be hidden underneath the screen element in that case, // therefore we account for a standard amount to make it visible this.scrollBarWidth = (this._viewportElement.offsetWidth - this._scrollArea.offsetWidth) || FALLBACK_SCROLL_BAR_WIDTH; - this._lastHadScrollBar = true; this.register(addDisposableDomListener(this._viewportElement, 'scroll', this._onScroll.bind(this))); // Track properties used in performance critical code manually to avoid using slow getters @@ -109,17 +107,6 @@ export class Viewport extends Disposable implements IViewport { this._viewportElement.scrollTop = scrollTop; } - // Update scroll bar width - if (this._optionsService.rawOptions.scrollback === 0) { - this.scrollBarWidth = 0; - } else { - this.scrollBarWidth = (this._viewportElement.offsetWidth - this._scrollArea.offsetWidth) || FALLBACK_SCROLL_BAR_WIDTH; - } - this._lastHadScrollBar = this.scrollBarWidth > 0; - - const elementStyle = window.getComputedStyle(this._element); - const elementPadding = parseInt(elementStyle.paddingLeft) + parseInt(elementStyle.paddingRight); - this._viewportElement.style.width = (this._renderService.dimensions.actualCellWidth * (this._bufferService.cols) + this.scrollBarWidth + (this._lastHadScrollBar ? elementPadding : 0)).toString() + 'px'; this._refreshAnimationFrame = null; } @@ -151,11 +138,6 @@ export class Viewport extends Disposable implements IViewport { this._refresh(immediate); return; } - - // If the scroll bar visibility changed - if (this._lastHadScrollBar !== (this._optionsService.rawOptions.scrollback > 0)) { - this._refresh(immediate); - } } /**