Keep the mouse working in OpenCode panes after reattach, and let Option-drag select text - #222
Merged
Merged
Conversation
…on-drag select text OpenCode owns the mouse (modes 1000-1006), which broke two things in the terminal: - Scrolling died after any reattach (reopening the task, a second window, app restart). The daemon rebuilds a pane from a serialized snapshot, and the serialize addon replays mouse tracking (?1003h) but not the SGR encoding (?1006h). The fresh xterm fell back to the legacy X10 encoding, which it emits on onBinary; the views only forward onData, so every wheel/click/drag was dropped. The daemon now tracks the encoding through xterm's own parser and appends it to every snapshot (unit-tested; verified against a real OpenCode session on a scratch daemon). - Text selection never worked while an app owned the mouse: on macOS xterm offers no bypass unless macOptionClickForcesSelection is set. Option+drag now selects (same convention as VS Code and iTerm2); plain drag still goes to the app. altClickMovesCursor is disabled alongside it: with it on, one Option+click on OpenCode's alt screen sent the renderer into an unbounded loop in xterm's moveToCellSequence and killed the window (out of memory).
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.
Why
OpenCode takes over the mouse at startup (DEC modes 1000-1006). Two things broke in Ateam's terminal because of that.
Scrolling stopped after any reattach. Reopening the task panel, a second window, or an app restart rebuilds the pane from the PTY daemon's serialized snapshot.
@xterm/addon-serializereplays mouse tracking (?1003h) but has no way to replay the mouse encoding (?1006h, not interminal.modes). The fresh xterm fell back to the legacy X10 encoding, which xterm emits ononBinary; the views only forwardonData, so every wheel, click and drag was dropped until the app restarted.Text selection never worked while an app owned the mouse: on macOS xterm offers no bypass unless
macOptionClickForcesSelectionis set.What
packages/server/src/pty/snapshot-modes.ts: track?1006/?1016requests through the headless terminal's own parser (split chunks handled for free, RIS resets it) and append the active encoding to every snapshot. Wired indaemon.ts. Covers desktop, box and mobile panes since they all replay the same snapshot.Terminal.tsx:macOptionClickForcesSelection: true. Option+drag selects, plain drag still goes to the app (VS Code / iTerm2 convention).altClickMovesCursor: false. With forced selection on, xterm's default Option+click "move cursor here" runs, and on OpenCode's alt screen itsmoveToCellSequenceloop diverged and grew a string until the renderer died out of memory (reproduced at ~20 GB). Disabled; no agent wants those arrow keys anyway.Verified
?1003hand?1006h.bun test(server): 260 pass. Typecheck and biome clean.Left for later (parked in the repo sidenotes)
onBinarystill unforwarded for apps that enable tracking without SGR (none today).moveToCellSequenceloop.