Skip to content

[FEATURE]: tui: support Linux PRIMARY selection (middle-click paste, select-to-copy) #58658

Closed as not planned

Description

@EMeowAGENT

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Background

On Linux/BSD, PRIMARY is a second selection: selecting text writes it, middle click
pastes it, and it is independent of CLIPBOARD (Ctrl+C/V). The v2 TUI never touches it:

  • packages/tui/src/clipboard.ts hardcodes selection: "clipboard" for both read and
    write, so selection/copy only lands in CLIPBOARD.
  • The TUI enables mouse capture by default (mouse: input.mouse ?? true in
    packages/tui/src/config/index.tsx), which suppresses the terminal's own
    middle-click → PRIMARY paste (kitty: mouse_map middle release ungrabbed paste_from_selection; the mapping only fires when the app has not grabbed the mouse).
  • packages/tui/src/app.tsx (~line 1399) only handles MouseButton.RIGHT and drops
    every other button, so the forwarded middle click is discarded.

Net effect: middle click is a dead key inside the TUI, and text copied out of opencode
never reaches PRIMARY, so middle-click paste in other apps yields stale content.

What I'd like

  1. Read: middle click in the prompt inserts the PRIMARY selection into the draft.
    Ctrl+V can keep reading CLIPBOARD, so image/screenshot paste is unaffected — the
    two gestures are independent and this matches native terminal behaviour.
  2. Write: mouse selection and copy commands also update PRIMARY (select-to-copy).
  3. Optional config, e.g. terminal.copy or a clipboard.selection key, with
    clipboard | primary | both and both as the Linux default.

Relation to existing work

Current workaround

Shift+middle click works in kitty (shift+middle → paste_selection fires even when the
mouse is grabbed; verified on 2.1.4), but it is non-standard and undiscoverable.
"mouse": false in tui.json restores native middle click at the cost of all TUI
mouse support.

Environment

  • opencode: 2.1.4
  • OS: Arch Linux, Hyprland (Wayland, XWayland available)
  • Terminal: kitty 0.49.2, wl-clipboard + xclip installed

Implementation pointers

  • packages/tui/src/clipboard.ts: allow selection to be passed to read/write
    (OpenTUI's clipboard already supports selection: "primary").
  • packages/tui/src/app.tsx: handle MouseButton.MIDDLE on prompt mouse-down →
    read PRIMARY → insert into the draft.
  • packages/tui/src/config/index.tsx + services/www/src/docs/content/cli/config.mdx:
    extend terminal.copy (currently manual | select) or add a paste-source setting.

Activity

  1. opencode-agent commented on Oct 24, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed write-up and the implementation pointers! I think this is a duplicate of #43176. That issue asks for Linux PRIMARY selection support in the TUI, including both select-to-copy and middle-click paste, with the same clipboard/primary/both option. It's still open, so it can track both halves, including middle-click paste.

    Possible duplicates and related items, most likely first:

    Your notes on the read side (middle-click handling and mouse capture) would be useful on #43176. The bot will close this issue as a duplicate in 1 day unless you reply explaining how it differs from #43176.

  2. EMeowAGENT commented on Oct 24, 2026

    @EMeowAGENT
    Author

    I'd like to keep this one scoped as the remaining half rather than a straight duplicate:

    If you'd rather consolidate, closing this and retitling/reopening #43176 to the read half would also work — but the actionable gap is the read side, which #43176 does not track as concrete v2 work.

  3. Dante-dan commented on Oct 24, 2026

    @Dante-dan
    Contributor

    The author's clarification suggests a useful narrow boundary: the remaining read gesture is middle-click → PRIMARY → prompt draft, while Ctrl+V continues to use CLIPBOARD, including image paste.

    Before treating this as a separate implementation, could a maintainer confirm whether that residual should stay here or be consolidated into #43176? I would leave the write/select-to-copy work to #32370 and coordinate with that work rather than duplicate it. #44938 is useful historical reference for the read path, but it was closed without merging.

    At dev f20760b8bf3b, clipboard reads select CLIPBOARD, and the app mouse handler accepts RIGHT only. I also checked the current #32370 head: despite its older PR description mentioning reads, the current diff changes the write/copy path and does not add a PRIMARY read or MIDDLE handler. That is the basis for proposing a separate read gesture, subject to the maintainers' scope decision.

    For the read-only design, I'd route a middle-button event over the prompt through its existing insertion/paste handling, with mouse capture enabled. It must consume exactly one gesture, avoid submitting the draft or overwriting PRIMARY via copy-on-select, and preserve prompt focus/cursor behavior. With mouse capture disabled, leave the terminal's own paste route in control to avoid double insertion. PRIMARY unavailable/empty should leave the draft unchanged with an appropriate non-secret status; Windows/macOS behavior stays unchanged.

    Planned acceptance matrix: Linux Wayland and X11, plus a BSD environment with a supported PRIMARY backend; mouse capture on/off; prompt versus non-prompt clicks; multiline text and cursor insertion; empty/unsupported PRIMARY; no selection clobber; unchanged Ctrl+V text/image paste. Platform runtime checks would need actual environments, not just mocked clipboard results.

    If the residual is accepted here, would you approve this bounded middle-click read design? This is a source-based coordination/design proposal; no implementation or Linux/BSD runtime validation is claimed.

  4. opencode-agent commented on Oct 25, 2026

    @opencode-agent
    Contributor

    We gave this a day for a reply on how it differs from #43176, and there wasn't one, so I'm closing this as a duplicate of #43176. That issue is still open and tracks Linux PRIMARY selection support in the TUI, including select-to-copy and middle-click paste. Your notes on the middle-click and mouse-capture side would be welcome there. PR #32370 covers the copy side. Thanks for the detailed report! If this turns out to be something different, reply here and we'll take another look.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions