Skip to content

fix: support all OSC 52 selection types for clipboard sync#1518

Open
aaradhyaberisfdc wants to merge 1 commit intotsl0922:mainfrom
aaradhyaberisfdc:osc52-fix
Open

fix: support all OSC 52 selection types for clipboard sync#1518
aaradhyaberisfdc wants to merge 1 commit intotsl0922:mainfrom
aaradhyaberisfdc:osc52-fix

Conversation

@aaradhyaberisfdc
Copy link
Copy Markdown

@aaradhyaberisfdc aaradhyaberisfdc commented Mar 26, 2026

Problem

The @xterm/addon-clipboard's default BrowserClipboardProvider silently drops OSC 52 clipboard writes for any selection type other than 'c' (system clipboard). See this.

tmux sends selection type 'p' (primary) by default with set-clipboard on, so clipboard never reaches the browser.

The addon's type definitions also have a mismatch (constructor(provider?) in .d.ts vs constructor(base64, provider) at runtime), requiring a @ts-expect-error to pass a custom provider. See this.

Proposed Fix

Replace the default BrowserClipboardProvider with a custom TtydClipboardProvider that accepts all OSC 52 selection types, browsers have a single clipboard with no primary/secondary distinction.

Testing

# All should copy "test" to clipboard
printf '\033]52;c;dGVzdA==\007'   # system clipboard
printf '\033]52;p;dGVzdA==\007'   # primary (tmux default)
printf '\033]52;;dGVzdA==\007'    # empty selection

tmux integration with set -g set-clipboard on and set -g mouse on:

  • Mouse drag select in copy-mode copies to system clipboard
  • vi copy-mode yank (y) copies to system clipboard

Replace default BrowserClipboardProvider with a custom provider that
accepts all selection types. tmux sends OSC 52 with type 'p' (primary)
which the default provider silently drops.
@aaradhyaberisfdc
Copy link
Copy Markdown
Author

@tsl0922 Could I please get a review whenever you get the time?

@tsl0922
Copy link
Copy Markdown
Owner

tsl0922 commented Apr 8, 2026

Is it possible to submit it to the upstream?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants