Update workspace and app changes

This commit is contained in:
Mohamed Boudra
2026-03-07 19:09:00 +07:00
parent 1d1c7058f1
commit 7d76da3249
40 changed files with 2693 additions and 976 deletions
@@ -196,4 +196,42 @@ describe("terminal-emulator-runtime", () => {
expect(terminal.options?.theme).toEqual({ background: "after" });
expect(refresh).toHaveBeenCalledWith(0, 11);
});
it("forces a refit when the page becomes visible again", () => {
const runtime = new TerminalEmulatorRuntime();
const fitAndEmitResize = vi.fn();
(runtime as unknown as { fitAndEmitResize: (force: boolean) => void }).fitAndEmitResize =
fitAndEmitResize;
(globalThis as { document?: { visibilityState?: string } }).document = {
visibilityState: "visible",
};
(
runtime as unknown as {
handleVisibilityRestore: () => void;
}
).handleVisibilityRestore();
expect(fitAndEmitResize).toHaveBeenCalledWith(true);
});
it("does not refit while the page is still hidden", () => {
const runtime = new TerminalEmulatorRuntime();
const fitAndEmitResize = vi.fn();
(runtime as unknown as { fitAndEmitResize: (force: boolean) => void }).fitAndEmitResize =
fitAndEmitResize;
(globalThis as { document?: { visibilityState?: string } }).document = {
visibilityState: "hidden",
};
(
runtime as unknown as {
handleVisibilityRestore: () => void;
}
).handleVisibilityRestore();
expect(fitAndEmitResize).not.toHaveBeenCalled();
});
});
@@ -36,6 +36,8 @@ type TerminalEmulatorRuntimeDisposables = {
disposeInput: () => void;
disconnectResizeObserver: () => void;
removeWindowResize: () => void;
removeWindowFocus: () => void;
removeDocumentVisibilityChange: () => void;
removeVisualViewportResize: () => void;
clearFitInterval: () => void;
clearFitTimeouts: () => void;
@@ -102,6 +104,19 @@ export class TerminalEmulatorRuntime {
private inFlightOutputOperationTimeout: ReturnType<typeof setTimeout> | null = null;
private suppressInput = false;
private handleVisibilityRestore = (): void => {
if (typeof document !== "undefined" && document.visibilityState !== "visible") {
return;
}
this.fitAndEmitResize?.(true);
if (typeof window.requestAnimationFrame === "function") {
window.requestAnimationFrame(() => {
this.fitAndEmitResize?.(true);
});
}
};
setCallbacks(input: { callbacks: TerminalEmulatorRuntimeCallbacks }): void {
this.callbacks = input.callbacks;
}
@@ -311,6 +326,15 @@ export class TerminalEmulatorRuntime {
const windowResizeHandler = () => fitAndEmitResize(false);
window.addEventListener("resize", windowResizeHandler);
const windowFocusHandler = () => {
this.handleVisibilityRestore();
};
window.addEventListener("focus", windowFocusHandler);
const documentVisibilityChangeHandler = () => {
this.handleVisibilityRestore();
};
document.addEventListener("visibilitychange", documentVisibilityChangeHandler);
const visualViewport = window.visualViewport;
const visualViewportResizeHandler = () => fitAndEmitResize(false);
@@ -369,6 +393,12 @@ export class TerminalEmulatorRuntime {
removeWindowResize: () => {
window.removeEventListener("resize", windowResizeHandler);
},
removeWindowFocus: () => {
window.removeEventListener("focus", windowFocusHandler);
},
removeDocumentVisibilityChange: () => {
document.removeEventListener("visibilitychange", documentVisibilityChangeHandler);
},
removeVisualViewportResize: () => {
visualViewport?.removeEventListener("resize", visualViewportResizeHandler);
},
@@ -410,6 +440,8 @@ export class TerminalEmulatorRuntime {
disposables.disposeInput();
disposables.disconnectResizeObserver();
disposables.removeWindowResize();
disposables.removeWindowFocus();
disposables.removeDocumentVisibilityChange();
disposables.removeVisualViewportResize();
disposables.clearFitInterval();
disposables.clearFitTimeouts();