GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(tui): add linux_clipboard_selection config for primary buffer support by bornmw · Pull Request #32370 · anomalyco/opencode Conversation
|
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate PRs Found
Note: PR #6370 appears to be the most relevant, as it specifically addresses enabling PRIMARY clipboard copy for Linux middle-click paste functionality—the exact feature being implemented in PR #32370. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I reviewed the potential duplicates flagged by the bot, and here is how this PR compares: PR #31252 and PR #27861 are not duplicates. They handle clipboard failure reporting and error validation rather than the primary selection buffer. PR #6370 attempts to solve the same underlying issue (adding PRIMARY selection for Linux middle-click paste), but there are a few key differences. First, that PR has been stalled since December. Second, my implementation introduces a more flexible configuration approach—letting the user explicitly choose between Clipboard, Primary, or Both (defaulting to Both)—whereas #6370 uses a simple boolean toggle. Finally, this PR optimizes the copy operation under the hood by utilizing Promise.allSettled to update the buffers in parallel. Given these architectural differences and the inactivity on #6370, I believe this PR provides a more robust and complete solution to closing #29963. Let me know if any changes are needed! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
b1cb38a to
c6e0c83
Compare
693c292 to
f5bfa85
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
feat(opencode): add linux_clipboard_selection config for primary buffer supportThe feature is sound and the bundled fix is the real value. The issues are formatting, one behavioral gap, and some type hygiene.
wl-copy --type text/plain;charset=utf-8 fix is the most important line in this PR. Without it, piped wl-copy offers only application/octet-stream (wl-copy dumps stdin to a temp file named stdin, and xdg-mime content-sniffing on an extensionless file returns octet-stream), which text editors reject. This is arguably a hidden bug fix inside a feature PR — worth calling out explicitly in the description.copyCommand stays pure, getCopyMethod routes by selection, Promise.allSettled for "both" is correct.tui.json schema.copyCommand branches including the MIME fix.OSC52 bypasses the selection setting (most substantive). write() calls writeOsc52(text) unconditionally before routing to the selection-specific method (clipboard.ts). With linux_clipboard_selection: "primary", the regular clipboard is still written via OSC52 whenever the terminal supports it (tmux, kitty, wezterm...). OSC52 also cannot target the primary buffer. "primary" mode is therefore not primary-only. Suggest skipping OSC52 for "primary" (or threading selection into it).
Formatting: the PR introduces Prettier violations in all 4 modified source files. The repo uses prettier (printWidth 120, semi: false) and base dev is clean, but this PR fails bunx prettier --check on clipboard.ts (xsel ternary, copyMethod type), clipboard.tsx (138-char ClipboardProvider signature), config/index.tsx (Resolved Omit), and clipboard.test.ts (long toEqual arrays). CI only runs tsgo typecheck so this will not block, but it deviates from repo convention — run bunx prettier --write on the changed files.
Union types duplicated in three files; exported ClipboardSelection is unused. "clipboard" | "primary" | "both" appears in clipboard.ts, config/index.tsx (Resolved), and clipboard.tsx (ClipboardConfig); copyCommand uses an inline "clipboard" | "primary" instead of the exported ClipboardSelection. Define one shared type and reuse it.
Non-Linux platforms silently ignore the selection. The osascript (macOS) and PowerShell (Windows) branches do not read selection, so primary/both degrade to clipboard-only writes there. Defensible given the linux_ scope, but worth documenting (or gating the option in resolve()).
Minor: props.linuxClipboardSelection! non-null assertion in ClipboardProvider is avoidable; PR history has 2 merge commits + "trigger title check" (squash on merge); PR body says "Closes #43176" while the duplicate-PR comment references #29963 — keep the linked issue consistent.
write() routing ("both"/allSettled) has no test coverage — acceptable given spawn mocking cost, but a natural follow-up.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Addressed all review comments:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Verified the changes against the latest head (
One item is not actually done:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Fixes applied. Prettier formatting now complete. Commit cb7bf05 updates all 4 files. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Confirmed — all review items are now closed. LGTM from the review side. Good to merge. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
feat(tui): add linux_clipboard_selection config for primary buffer supportThe previous round's asks are all closed and verified on the current head. The remaining gaps: the selection contract is write-only, a silent no-op failure mode claims success, and the option is missing from tests and docs.
2fdfe1c9b2)"primary" (the write() guard), prettier is clean on all 5 changed files (re-ran bunx prettier --check), ClipboardSelection is unified, the non-null assertion is gone, and the title is conventional.bun typecheck is clean and all 196 TUI tests pass (195 pass / 1 skip).TuiConfig.Info → resolve() at both call sites, a typo fails loudly like any other key, no committed schema artifact needs regeneration (the tui.json schema is generated from Info at web build time), and tui-migrate correctly needs no change.useClipboard), so selection routing applies everywhere — nothing bypasses it with a direct write import.The selection contract is write-only: read() ignores the selection (most substantive). ClipboardProvider only wraps write with the selection; read is passed through bare. The default ctrl+v (input_paste) routes to prompt.paste → clipboard.read?.(), and read() only ever reads the clipboard buffer (wl-paste default, xclip -selection clipboard, clipboardy). With "primary", every opencode copy lands in the primary buffer only, then opencode's own paste reads the stale clipboard. Middle-click itself is fine (the TUI has no middle-click handler; with mouse capture off the terminal pastes natively from primary), so the gap is specifically opencode's own ctrl+v path. Suggest making read selection-aware (wl-paste --primary / xclip -selection primary for "primary"), or explicitly documenting that the paste keybind is unaffected by the setting.
Silent no-op and unconditional success toast. write() never rejects (.catch(() => undefined) everywhere, Promise.allSettled for "both"), and the clipboardy fallback does if (selection === "primary") return — a silent no-op. Both resolve "successfully" into the "Copied to clipboard" toast, so a failed or skipped copy claims success. At minimum the fallback should fall back to the clipboard instead of no-op'ing, or the failure should surface.
Config tests missing in config.test.tsx. That file already has the pattern: "validates config constraints" decodes Info and asserts invalid values throw (e.g. cursor: { style: "beam" }), and "resolves host-neutral defaults" asserts defaults like mouse: true. Nothing covers linux_clipboard_selection — no valid-value decode, no invalid-value throw, no resolve({}).linux_clipboard_selection === "both". A few lines in an existing file.
Docs: linux_clipboard_selection is missing from the TUI options reference. tui.mdx documents diff_style, cursor, mouse, attention and the rest; this option appears nowhere in the repo's docs. Every user-facing option is listed there.
Non-Linux platforms silently ignore the selection (previous item #4, still open). The osascript branch ignores it; the win32 copyCommand branch returns the same PowerShell command for every selection, so "primary" writes the normal clipboard and "both" spawns the identical command twice in parallel. Defensible given the linux_ scope, but it's still undocumented and un-gated.
"both" default is a silent behavior change for all Linux users (copies now also write the primary selection). Fine, but the PR body frames it as a new option — one sentence about the default changing existing copy behavior would help, alongside calling out the wl-copy --type text/plain fix.copyCommand accepts "both" but implicitly behaves as "clipboard" — Exclude<ClipboardSelection, "both"> would make the contract honest. Resolved also still inlines the union instead of importing ClipboardSelection (previous item #3 half-closed).cursor config" — Cursor already exists on dev; stale from an earlier iteration.both/allSettled path — acceptable follow-up as previously noted.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
cannot wait for this to be merged in. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
All addressed in
Notes addressed as well:
Verified: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@thdxr Could you review this PR when you get a chance? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
a25520c to
ba1942a
Compare
|
@bornmw I've reworked the branch so primary-selection support is off by default and sits under the existing I dropped two parts of the original design:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Copying/pasting changes look good, but I'm not sure why primary selection would be off by default? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
You're right about selections. Went a bit back and forth on this, but i changed it. Mouse selections now go to the primary selection by default on Linux. Instead of a separate setting, this is part of
Copy commands like "Copy session ID" always use the clipboard, and so does paste. That keeps the usual Linux split between selecting and explicitly copying.
Also removed |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
d830f1a to
c7d331f
Compare
Hooray! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Copying now targets the standard clipboard by default, avoiding unexpected primary-selection changes. Enable primary copying explicitly when middle-click paste integration is wanted.
c7d331f to
1adb91f
Compare
|
what would be the next step @simonklee ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
One gap in the current rework: middle click is still a dead key in the TUI. Mouse capture suppresses the terminal's own middle-click → PRIMARY paste, and Tracking the read half separately in #58658 — happy to keep this PR scoped to the write side. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Following up on @EMeowAGENT's point about middle click: I've implemented middle-click → PRIMARY paste on top of this branch, in one commit: axeluhl@ea9af38 A middle click in the prompt reads the primary selection and inserts it at the cursor, on Linux with mouse capture on. Ctrl+V and image paste keep reading the clipboard, as you set it up. It uses the @simonklee @bornmw feel free to cherry-pick it into this PR, or I can open it as a separate PR stacked on this one, whichever is easier for you. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
do you think this could go in @simonklee ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
middle-click paste is functionally very different from copying, and it's not controlled by the setting that's included in this PR (not sure if it's controlled by any setting), for those reasons I think it's better to keep them separate @axeluhl @EMeowAGENT |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
# Conflicts: # packages/tui/test/clipboard.test.ts
|
Hi @kitlangton, @jlongster, @simonklee and @thdxr - I hope you are all doing well! I'm not sure how Linux users are comfortable using OpenCode with no ability to copy to primary buffer, but maybe I'm missing something? Is modern generation even aware that it exists? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
i normally don't "me too", but here... this is the #1 quality of life improvement for me across all applications on my desktop we could make. not being able to copy/paste in opencode to other windows, to itself... i created a short cut to copy clipboard to primary, but, i cannot retrain my fingers to use it. and, its something i hit 10's of times per day. if this was a standard terminal tui application it would work, but since its intercepting and moving to the wrong clipboard, its just different, so i select, but then can't paste. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[FEATURE]: Add support for Linux PRIMARY selection (middle-click paste) Wayland clipboard copy doesn't populate primary clipboard selection
There was an error while loading. Please reload this page.