fix(terminal): paste into the terminal that got the key, not the mount's last session - #172
Merged
Merged
Conversation
…t's last session The Ctrl+V/Ctrl+Shift+V/right-click clipboard handle was stored in a ref owned by the useTerminal hook instance, while the xterm custom key handler that reads it is registered once, when the terminal is created, and lives as long as the cached terminal. A mount that switches session (a pane re-targeted, a tab dragged in or out of a split) rebinds that ref to the new session's terminal, so the old terminal's Ctrl+V pasted into the new one. Store the handle on the cache entry instead, next to the other per-terminal mirrors, so a terminal's key handler can only reach its own clipboard.
Contributor
Author
|
Live-verified in the headless dev build (
Before the fix (dev @ c881568): focus and cursor in the left pane, After the fix: |
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.
Bug
With 5 tabs — 1: Host A, 2: Host B, 3+4 grouped in a split, 5: Host B — pasting into tab 2 landed in tab 3.
Root cause
The clipboard handle from
attachTerminalClipboard(Ctrl+V, Ctrl+Shift+V, right-click paste) was stored inclipRef, a ref owned by theuseTerminalhook instance. The xterm handler that reads it,term.attachCustomKeyEventHandler, is registered once when the terminal is created and lives as long as the cached terminal — cached terminals outlive their mounts by design.A mount that switches session — a pane re-targeted, a tab dragged in or out of a split, the path
useTerminal.reattach.test.tsxalready covers — rebinds that ref to the new session's terminal. From then on the old terminal's Ctrl+V didreadClipboard()andterm.paste()on the new session's terminal.Instrumented run before the fix, showing terminal 1's key handler firing terminal 2's clipboard handle:
Fix
The handle moves onto the cache entry as
CacheEntry.clip, next to the other per-terminal mirrors (inputGateRef,onClosedRef,onResizeRef), andbindContainernow takes the entry it is binding. A terminal's key handler can only reach its own clipboard.Verification
src/hooks/useTerminal.clipboard.test.tsx— fails ondev, passes here.vitest run src/hooks src/components/terminal: 41 files, 266 tests passed.tsc --noEmit: clean.Not yet exercised by hand in a live build.