fix(terminal): restore tmux scroll and resize after browser pane open/close#48
Merged
amirlehmam merged 1 commit intoJun 20, 2026
Merged
Conversation
…/close
When a browser pane is open, Chromium routes un-prevented wheel events to the
webview compositor, stealing them from the terminal. This caused tmux scroll to
break and SGR escape sequences to leak into plain shells.
- Module-level surfaceMouseEnabled map tracks whether mouse reporting is active
per surface (survives React remounts). Set on \x1b[?100[0236]h, cleared on
\x1b[?100[0236]l. Used to distinguish tmux/vim from a plain shell even when
xterm's buffer.active.type is unreliable after remount (tmux doesn't re-send
\x1b[?1049h on SIGWINCH, only on a fresh client attach).
- Wheel handler now branches on webview presence (cached via MutationObserver):
no webview, normal buffer → scrollback directly
no webview, alt buffer → fall through to xterm natively
webview + plain shell → scrollback directly
webview + mouse-enabled → write SGR scroll escapes to PTY
- pendingResizeDims captures ResizeObserver events that arrive before pty.create
IPC resolves so they are not silently dropped.
- doInitialResize retries via requestAnimationFrame (up to 8 attempts) until
fitAddon.proposeDimensions() returns non-null, ensuring tmux gets SIGWINCH and
redraws into the new xterm instance after remount.
- Deferred 300ms repaint safety-net (scrollToBottom + refresh) ensures the
renderer paints the initial content after PTY attach.
- ResizeObserver refresh is now conditional: plain shells get terminal.refresh()
to mark rows dirty after a layout change; mouse-enabled apps (tmux, vim) skip
it to avoid painting stale buffer content before their own SIGWINCH redraw arrives.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Owner
|
Merged and shipped in v0.8.8 🚀 Thanks @schroldgames! This overlapped with #42 in
Net behavior matches your PR for every webview case, plus #42's reliability for the non-webview alt-buffer case. tsc + the full suite are green (the 5 |
This was referenced Jun 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #47. Complementary to #41 / PR #42 — this addresses the specific case where a browser pane (webview) is open alongside a tmux terminal.
Root causes
Webview compositor stealing wheel events: When a
<webview>is present, Chromium routes un-prevented wheel events to it. The existing handler correctly falls through on the alternate buffer so xterm can handle it natively, but with a webview that fall-through sends the event to the webview instead of tmux.Unreliable buffer type after remount: tmux doesn't re-send
\x1b[?1049hon SIGWINCH — only on a fresh client attach. After React remounts the terminal (e.g. on browser pane close),xterm.buffer.active.typereads'normal'even though tmux is still running, causing the wrong scroll path and a prematureterminal.refresh()that paints stale content before tmux's own SIGWINCH redraw arrives.Silent resize drop: If ResizeObserver fires before
pty.createIPC resolves, the resize is dropped and tmux never gets SIGWINCH.Changes (
src/renderer/hooks/useTerminal.ts)surfaceMouseEnabledmap (module-level, survives remounts): tracks SGR/button mouse enable (\x1b[?100[0236]h) and disable per surface. Used by the wheel handler to reliably identify tmux/vim sessions independent ofbuffer.active.type.hasWebviewCached+ MutationObserver: caches webview presence to avoid a livequerySelectoron every wheel event. A single shared observer updates it when the DOM changes.Wheel handler now branches on webview presence and mouse-tracking state:
pendingResizeDims: captures ResizeObserver events that arrive beforepty.createIPC resolves, flushed inattachToPty.doInitialResize: retries via RAF (up to 8 attempts) untilfitAddon.proposeDimensions()returns non-null, ensuring tmux gets SIGWINCH and redraws into the new xterm instance after remount.Conditional
terminal.refresh()in ResizeObserver: plain shells get it to mark rows dirty after a layout change; mouse-enabled apps skip it to avoid painting stale content before their own SIGWINCH redraw arrives.Relationship to PR #42
PR #42 fixes the general alternate-buffer scroll regression (#41) by taking ownership of wheel events in the alternate screen unconditionally. This PR fixes the orthogonal webview case — the two changes are complementary and can coexist without conflict.
🤖 Generated with Claude Code