Skip to content

Commit 4aea7e8

Browse files
committed
Fix terminal not resizing when zoom button is clicked
Use ghostty-web's FitAddon to recalculate terminal cols/rows from the container's pixel dimensions on resize. Previously, the ResizeObserver only forwarded stale dimensions to the PTY backend. Now FitAddon.fit() recomputes the correct grid size using font metrics before signaling the PTY, so the shell adapts to the new window size. Assisted-By: docker-agent
1 parent 9d361b5 commit 4aea7e8

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

handlers/resources/terminal.html

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// Use ghostty-web terminal emulator.
1717
// PR #136 (https://github.com/coder/ghostty-web/pull/136) fixes wheel
1818
// events with mouse tracking for proper tmux/vim pane scrolling.
19-
const { init, Terminal } = await import(
19+
const { init, Terminal, FitAddon } = await import(
2020
'https://cdn.jsdelivr.net/npm/ghostty-web@0.4.0/dist/ghostty-web.js'
2121
);
2222

@@ -36,6 +36,12 @@
3636

3737
term.open(container);
3838

39+
// FitAddon recalculates terminal cols/rows from the container's
40+
// pixel dimensions and calls term.resize(), which fires onResize.
41+
const fitAddon = new FitAddon();
42+
term.loadAddon(fitAddon);
43+
fitAddon.fit();
44+
3945
// Connect to the WebSocket PTY backend.
4046
const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
4147
const ws = new WebSocket(proto + '//' + location.host + '/ws/terminal' + location.search);
@@ -50,7 +56,8 @@
5056
// Send initial resize.
5157
sendResize();
5258

53-
// Handle terminal resize.
59+
// Handle terminal resize: when FitAddon recalculates dimensions
60+
// on container size changes, this forwards the new size to the PTY.
5461
term.onResize(sendResize);
5562
};
5663

@@ -74,11 +81,12 @@
7481
}));
7582
}
7683

77-
// Resize terminal when the window resizes.
84+
// Automatically refit terminal when the container resizes (e.g.
85+
// when the fake-window zoom button is clicked). FitAddon.fit()
86+
// recalculates cols/rows from the new container size, calls
87+
// term.resize(), which fires onResize → sendResize → PTY resize.
7888
new ResizeObserver(() => {
79-
if (ws.readyState === WebSocket.OPEN) {
80-
sendResize();
81-
}
89+
fitAddon.fit();
8290
}).observe(container);
8391
</script>
8492
</body>

0 commit comments

Comments
 (0)