mirror of
https://github.com/lensapp/lens.git
synced 2024-09-20 13:57:23 +03:00
Fix terminal fit errors (#5811)
This commit is contained in:
parent
ede8a2e91f
commit
5f746760c8
@ -3,23 +3,35 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export type Disposer = () => void;
|
||||
|
||||
interface Extendable<T> {
|
||||
push(...vals: T[]): void;
|
||||
|
||||
export interface Disposer {
|
||||
(): void;
|
||||
}
|
||||
|
||||
export type ExtendableDisposer = Disposer & Extendable<Disposer>;
|
||||
|
||||
export function disposer(...args: (Disposer | undefined | null)[]): ExtendableDisposer {
|
||||
const res = () => {
|
||||
args.forEach(dispose => dispose?.());
|
||||
args.length = 0;
|
||||
};
|
||||
|
||||
res.push = (...vals: Disposer[]) => {
|
||||
args.push(...vals);
|
||||
};
|
||||
|
||||
return res;
|
||||
export interface Disposable {
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export interface ExtendableDisposer extends Disposer {
|
||||
push(...vals: (Disposer | ExtendableDisposer | Disposable)[]): void;
|
||||
}
|
||||
|
||||
export function disposer(...items: (Disposer | Disposable | undefined | null)[]): ExtendableDisposer {
|
||||
return Object.assign(() => {
|
||||
for (const item of items) {
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof item === "function") {
|
||||
item();
|
||||
} else {
|
||||
item.dispose();
|
||||
}
|
||||
}
|
||||
items.length = 0;
|
||||
}, {
|
||||
push: (...newItems) => items.push(...newItems),
|
||||
} as Pick<ExtendableDisposer, "push">);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user