Fix terminal fit errors (#5811)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-07-18 09:53:15 -04:00
1 parent ede8a2e91f
commit 5f746760c8
2 files changed
+29 -28

No files matched your search

@@ -119,6 +119,9 @@ export class Terminal {
() => this.api.removeAllListeners(),
() => window.removeEventListener("resize", this.onResize),
() => this.elem.removeEventListener("contextmenu", this.onContextMenu),
this.xterm.onResize(({ cols, rows }) => {
this.api.sendTerminalSize(cols, rows);
}),
);
}
@@ -127,21 +130,7 @@ export class Terminal {
this.xterm.dispose();
}
fit = () => {
try {
const { cols, rows } = this.fitAddon.proposeDimensions();
// attempt to resize/fit terminal when it's not visible in DOM will crash with exception
// see: https://github.com/xtermjs/xterm.js/issues/3118
if (isNaN(cols) || isNaN(rows)) return;
this.fitAddon.fit();
this.api.sendTerminalSize(cols, rows);
} catch (error) {
// see https://github.com/lensapp/lens/issues/1891
logger.error(`[TERMINAL]: failed to resize terminal to fit`, error);
}
};
fit = () => this.fitAddon.fit();
fitLazy = debounce(this.fit, 250);