fix(web): terminal tells the shell its new width as soon as you release a resize drag (#19395)
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
7fd2ba7526
commit
2cde3f770b
2 files changed
+44
No files matched your search
@@ -540,6 +540,30 @@ describe("GhosttyTerminalSurface visibility", () => {
|
||||
expect(resizePty).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("sends the settled grid when a resize drag is released", async () => {
|
||||
const harness = createHarness();
|
||||
const onResize = vi.fn<(cols: number, rows: number) => void>();
|
||||
const surface = await harness.create({ onResize });
|
||||
vi.advanceTimersByTime(150);
|
||||
onResize.mockClear();
|
||||
|
||||
// Mid-drag, the grid reflows locally while the PTY waits for the debounce.
|
||||
harness.mount.clientWidth = 120;
|
||||
harness.resize();
|
||||
expect(surface.cols).toBe(14);
|
||||
expect(onResize).not.toHaveBeenCalled();
|
||||
|
||||
// The release writes the final width before the observer reports it.
|
||||
harness.mount.clientWidth = 96;
|
||||
window.dispatchEvent(new Event("pointerup"));
|
||||
expect(onResize).toHaveBeenCalledExactlyOnceWith(11, 6);
|
||||
|
||||
harness.resize();
|
||||
vi.advanceTimersByTime(150);
|
||||
window.dispatchEvent(new Event("pointerup"));
|
||||
expect(onResize).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("replays the current grid on reveal when a hidden host becomes ready", async () => {
|
||||
const harness = createHarness();
|
||||
const onResize = vi.fn<(cols: number, rows: number) => void>();
|
||||
|
||||
@@ -942,6 +942,22 @@ export class GhosttyTerminalSurface {
|
||||
}, 150);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releasing a panel, drawer, or split divider settles the size, so the PTY
|
||||
* hears it now instead of after the debounce. Otherwise typing right after
|
||||
* the release reaches a shell that still lays out the old width.
|
||||
*/
|
||||
private readonly onWindowPointerRelease = () => {
|
||||
if (this.disposed || this.resizeNotifyTimer === null) return;
|
||||
// The drag hook writes the release position before this bubbles to window,
|
||||
// so fit now rather than wait a frame for the observer.
|
||||
this.fit();
|
||||
if (this.resizeNotifyTimer === null) return;
|
||||
window.clearTimeout(this.resizeNotifyTimer);
|
||||
this.resizeNotifyTimer = null;
|
||||
this.options.onResize(this.cols, this.rows);
|
||||
};
|
||||
|
||||
focus(): void {
|
||||
if (this.disposed || !this.visible) return;
|
||||
this.input.focus({ preventScroll: true });
|
||||
@@ -1843,6 +1859,8 @@ export class GhosttyTerminalSurface {
|
||||
this.scrollbar.addEventListener("pointerup", this.onScrollbarPointerUp);
|
||||
this.scrollbar.addEventListener("pointercancel", this.onScrollbarPointerUp);
|
||||
this.scrollbar.addEventListener("keydown", this.onScrollbarKeyDown);
|
||||
window.addEventListener("pointerup", this.onWindowPointerRelease);
|
||||
window.addEventListener("pointercancel", this.onWindowPointerRelease);
|
||||
}
|
||||
|
||||
private removeEvents(): void {
|
||||
@@ -1869,6 +1887,8 @@ export class GhosttyTerminalSurface {
|
||||
this.scrollbar.removeEventListener("pointerup", this.onScrollbarPointerUp);
|
||||
this.scrollbar.removeEventListener("pointercancel", this.onScrollbarPointerUp);
|
||||
this.scrollbar.removeEventListener("keydown", this.onScrollbarKeyDown);
|
||||
window.removeEventListener("pointerup", this.onWindowPointerRelease);
|
||||
window.removeEventListener("pointercancel", this.onWindowPointerRelease);
|
||||
}
|
||||
|
||||
private scrollViewport(deltaRows: number): void {
|
||||
|
||||
Reference in new issue
Block a user