Skip to content
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 @@ -25,6 +25,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 @@ -45,6 +47,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 @@ -83,6 +90,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(): Event<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 @@ -117,6 +117,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 @@ -835,6 +835,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