Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FitAddon: fill screenElement #4891

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions addons/addon-fit/src/FitAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,6 +46,11 @@ 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 && this._terminal.screenElement) {
this._terminal.screenElement.style.width = `${this._lastAvailableWidth}px`;
this._terminal.screenElement.style.height = `${this._lastAvailableHeight}px`;
}
}
}

Expand Down Expand Up @@ -81,6 +88,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))
Expand Down
1 change: 1 addition & 0 deletions src/browser/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class Terminal extends Disposable implements ITerminalApi {
public get onWriteParsed(): IEvent<void> { 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);
Expand Down
1 change: 1 addition & 0 deletions test/playwright/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type TerminalProxyAsyncMethodOverrides = 'hasSelection' | 'getSelection' | 'getS
type TerminalProxyCustomOverrides = 'buffer' | (
// The below are not implemented yet
'element' |
'screenElement' |
'textarea' |
'markers' |
'unicode' |
Expand Down
5 changes: 5 additions & 0 deletions typings/xterm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,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.
*/
Expand Down
Loading