From 0803a1c042d60f5ed23f658d393a293da7de1db0 Mon Sep 17 00:00:00 2001 From: tisilent Date: Wed, 22 Nov 2023 17:32:19 +0800 Subject: [PATCH 1/4] Fill screenElement --- addons/addon-fit/src/FitAddon.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/addon-fit/src/FitAddon.ts b/addons/addon-fit/src/FitAddon.ts index 2087e6146a..bc8078824d 100644 --- a/addons/addon-fit/src/FitAddon.ts +++ b/addons/addon-fit/src/FitAddon.ts @@ -24,6 +24,8 @@ const MINIMUM_ROWS = 1; export class FitAddon implements ITerminalAddon , IFitApi { private _terminal: Terminal | undefined; + private _lastAvailableHeight: number | undefined; + private _lastAvailableWidth: number | undefined; public activate(terminal: Terminal): void { this._terminal = terminal; @@ -44,6 +46,10 @@ export class FitAddon implements ITerminalAddon , IFitApi { if (this._terminal.rows !== dims.rows || this._terminal.cols !== dims.cols) { core._renderService.clear(); this._terminal.resize(dims.cols, dims.rows); + if (this._lastAvailableHeight && this._lastAvailableWidth) { + core.screenElement.style.width = `${this._lastAvailableWidth}px`; + core.screenElement.style.height = `${this._lastAvailableHeight}px`; + } } } @@ -81,6 +87,8 @@ export class FitAddon implements ITerminalAddon , IFitApi { const elementPaddingHor = elementPadding.right + elementPadding.left; const availableHeight = parentElementHeight - elementPaddingVer; const availableWidth = parentElementWidth - elementPaddingHor - scrollbarWidth; + this._lastAvailableHeight = availableHeight; + this._lastAvailableWidth = availableWidth; const geometry = { cols: Math.max(MINIMUM_COLS, Math.floor(availableWidth / dims.css.cell.width)), rows: Math.max(MINIMUM_ROWS, Math.floor(availableHeight / dims.css.cell.height)) From bf22b0b1b6deca692fcae3ebd086041b39cd38aa Mon Sep 17 00:00:00 2001 From: tisilent Date: Wed, 22 Nov 2023 17:45:31 +0800 Subject: [PATCH 2/4] Describe --- addons/addon-fit/src/FitAddon.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/addon-fit/src/FitAddon.ts b/addons/addon-fit/src/FitAddon.ts index bc8078824d..62f4d839ea 100644 --- a/addons/addon-fit/src/FitAddon.ts +++ b/addons/addon-fit/src/FitAddon.ts @@ -46,6 +46,7 @@ export class FitAddon implements ITerminalAddon , IFitApi { if (this._terminal.rows !== dims.rows || this._terminal.cols !== dims.cols) { core._renderService.clear(); this._terminal.resize(dims.cols, dims.rows); + // Fill in less than one row if (this._lastAvailableHeight && this._lastAvailableWidth) { core.screenElement.style.width = `${this._lastAvailableWidth}px`; core.screenElement.style.height = `${this._lastAvailableHeight}px`; From 16ede70df86647918d07a2ec8c53017108e7a9a9 Mon Sep 17 00:00:00 2001 From: tisilent Date: Wed, 22 Nov 2023 18:20:00 +0800 Subject: [PATCH 3/4] Add public attribute screenElement. --- addons/addon-fit/src/FitAddon.ts | 6 +++--- src/browser/public/Terminal.ts | 1 + typings/xterm.d.ts | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/addon-fit/src/FitAddon.ts b/addons/addon-fit/src/FitAddon.ts index 62f4d839ea..ddbfdb77b6 100644 --- a/addons/addon-fit/src/FitAddon.ts +++ b/addons/addon-fit/src/FitAddon.ts @@ -47,9 +47,9 @@ export class FitAddon implements ITerminalAddon , IFitApi { core._renderService.clear(); this._terminal.resize(dims.cols, dims.rows); // Fill in less than one row - if (this._lastAvailableHeight && this._lastAvailableWidth) { - core.screenElement.style.width = `${this._lastAvailableWidth}px`; - core.screenElement.style.height = `${this._lastAvailableHeight}px`; + if (this._lastAvailableHeight && this._lastAvailableWidth && this._terminal.screenElement) { + this._terminal.screenElement.style.width = `${this._lastAvailableWidth}px`; + this._terminal.screenElement.style.height = `${this._lastAvailableHeight}px`; } } } diff --git a/src/browser/public/Terminal.ts b/src/browser/public/Terminal.ts index 6f009f74f2..b4fe8b0b4c 100644 --- a/src/browser/public/Terminal.ts +++ b/src/browser/public/Terminal.ts @@ -80,6 +80,7 @@ export class Terminal extends Disposable implements ITerminalApi { public get onWriteParsed(): IEvent { return this._core.onWriteParsed; } public get element(): HTMLElement | undefined { return this._core.element; } + public get screenElement(): HTMLElement | undefined { return this._core.screenElement; } public get parser(): IParser { if (!this._parser) { this._parser = new ParserApi(this._core); diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 70b0c6d71f..087911cee9 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -767,6 +767,11 @@ declare module '@xterm/xterm' { */ readonly element: HTMLElement | undefined; + /** + * The element is a screen container. + */ + readonly screenElement: HTMLElement | undefined; + /** * The textarea that accepts input for the terminal. */ From e13dfb037618773eb789c4f12a2fe27cc572fcec Mon Sep 17 00:00:00 2001 From: tisilent Date: Wed, 22 Nov 2023 18:34:12 +0800 Subject: [PATCH 4/4] test --- test/playwright/TestUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/playwright/TestUtils.ts b/test/playwright/TestUtils.ts index 3e925f79c9..fb9b4ce3ba 100644 --- a/test/playwright/TestUtils.ts +++ b/test/playwright/TestUtils.ts @@ -68,6 +68,7 @@ type TerminalProxyAsyncMethodOverrides = 'hasSelection' | 'getSelection' | 'getS type TerminalProxyCustomOverrides = 'buffer' | ( // The below are not implemented yet 'element' | + 'screenElement' | 'textarea' | 'markers' | 'unicode' |