Repository navigation
rich-editor: Let Copy with nothing selected copy the selection around the editor - #3071
Merged
Merged
Conversation
… the editor A focused RichEditor bound Cmd+C / Ctrl+C itself and copied only its own selection, so text selected around it (a chat's messages above its composer, which keeps the focus while they are selected) could not be copied on macOS. With nothing selected in the editor the key now goes on to the platform's Copy as well, as an Input's editor already does; plugins still hear it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
huacnlee
reviewed
Nov 24, 2026
huacnlee
left a comment
Member
There was a problem hiding this comment.
💡 The fix targets the right cause and mirrors Input, but it is unverified at runtime and the author marks it not for merging yet.
Reviewed head: a5cbc9d
- Diagnosis: correct.
key_tablebinds Cmd/Ctrl+C withWhen::AlwaysandRv::copyreturns early on an empty selection, so the key never reaches the platform Copy. Passing it through only while the editor's selection is empty matchescopies_selection_aroundintext_input.rs. - Implementation: small and contained. No public API change.
KeySpec::copyis crate-private, and the Copy binding is re-registered onsel_revinside the same focus-scoped effect pattern the other keys already use. Plugins still see the key. - Tests:
cargo test -p nsh-base rich_editorpasses locally (Linux): 310 + 248 passed. - Gap: no macOS run with real key events yet. The gallery
copy-selectiontest also fails onmainin the author's harness, so it proves nothing either way. One check on a Mac (caret in the RichEditor, text selected in a TextView above, Cmd+C →pbpaste) is what this needs before merging. - The second finding (a
focusablecontainer swallowing Copy) is out of scope here. It deserves its own issue.
huacnlee
marked this pull request as ready for review
November 24, 2026 08:39
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.
What
On macOS, a focused
RichEditortakes Cmd+C itself (keys::key_tablebinds it withWhen::Always) and copies only its own selection (Rv::copyreturns early when it is empty). So text selected around the editor cannot be copied while the editor keeps the keyboard focus. That is the usual chat shape: a reply selected above a composer that still has the caret.A plain
Inputalready handles this (copies_selection_aroundinnsh-platform-macos/src/text_input.rs). This PR does the same for the RichEditor. While nothing is selected in the editor, its Copy binding is registered withpass_through. The key still reaches the editor and its plugins, then goes on to the platform's Copy, which copies the selection around it. Once the editor has a selection, the binding consumes the key as before.keys.rs:KeySpec::copymarks the platform's Copy keystroke (Cmd+C on Apple keyboards, Ctrl+C elsewhere).controller.rs: the Copy keystroke is bound in its own effect, re-bound as the selection empties or fills (sel_rev), withpass_through: empty.examples/gallery/tests/copy-selection.test.tsx: the fixture gets aRichEditorcomposer, and the two "selection around it" cases run for it too.How it was found
eta (an app on nsh) received a report that Cmd+C copies nothing in rich text on macOS. Measured on a GitHub macOS 15 runner, AppKit host, nsh nightly
f577c51, with real key events (CGEvent) andpbpaste:TextViewSecond finding (not fixed here)
A view with
focusabletakes the keyboard focus when pressed (eta's transcript region). With it focused, after selecting text in aTextViewinside it, both Cmd+C and an enabled Edit › Copy write nothing to the pasteboard. Accessibility reports the focused element as thatAXGroup. I have not traced this one yet.Status: draft, not verified at runtime
cargo check -p nsh-basepasses.rustfmtwas run on the changed files.nsh-clifrom source (debug) on the runner, andexamples/gallery/tests/copy-selection.test.tsxfails 7 of 7 onmainthere too: theInputs never show (no pressable view matches id:composer). The new RichEditor cases fail on this branch in the same harness, which says nothing either way.Please treat this as a pointer to the cause rather than a ready change. Not for merging as is.
🤖 Generated with Claude Code