Repository navigation
desktop: Route Edit menu Copy to the focused view's key bindings - #4185
Merged
Merged
Conversation
Choosing Edit > Copy with the mouse sent copy: to the root view on macOS, which only copied selected text: a focused DataTable (whose Cmd+C is a `mod+c` binding) copied nothing, yet the item stayed enabled. The menu's edit commands now run the bindings their standard key has where the focus is, as pressing the key does, before the default. - macOS: the root view's copy: and selectAll: run the Cmd+C / Cmd+A bindings first; new cut: and paste: run Cmd+X / Cmd+V bindings. validateMenuItem: enables Copy only when a binding or selected text takes it, and Cut / Paste when a binding does. A key-down in flight is skipped (the keyboard monitor already ran the bindings). - Linux: the edit roles run the Ctrl+<key> bindings before the focused widget's clipboard / selection action. - Windows already replays Ctrl+<key> through the keymap; unchanged. No public API changes. Adds the native check menu_copy (NSH_MENU_COPY_CHECK_ONLY=1) and keystroke unit tests. Refs #4177 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Agent: rust-maintainer
Member
Author
|
💡 Right approach; one side effect in menu validation to fix before merging.
Reviewed head |
Member
Author
Member
Author
|
❌ The earlier blocking point is still open; the new head only merges
Diff-only review at |
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.
Follow-up to #4177 / #4183.
Problem
On macOS, Cmd+C reaches a focused DataTable's
mod+cbinding (the keymap monitor matches before menu key equivalents), but choosing Edit > Copy with the mouse sendscopy:to the root view, which only runstext::copy(selected text). With a table focused nothing is copied, and the item is still enabled.Platform check:
copy:on the root → selected text onlyclipboard.copyaction on the GTK focus widget; NSH views other than text / selectable views have none → nothinginput::key→keymap::keyChange
The Edit menu's commands run the bindings their standard key has where the focus is, exactly as pressing the key does, then fall back to the default.
view.rs,keymap.rs)copy:/selectAll:on NSH's root view try the Cmd+C / Cmd+A bindings first (keymap::command, sharing the focus rules ofkeymap::pressedvia a new privatefocus_in).cut:/paste:on the root run the Cmd+X / Cmd+V bindings (e.g. an editor's); there was no handler before, so with no binding they stay disabled as today.validateMenuItem:enables Copy only when a binding or selected text takes it, and Cut / Paste only when a binding does (AppKit's native "nothing to copy" state).chrome.rs,keymap.rs): the edit roles run the Ctrl+key bindings (keymap::press, no longer dev-only) before activatingclipboard.*/selection.select-allon the focus widget. Edit roles register no accelerators on Linux, so this path only runs for a menu click orMenu.perform.Public API: none. No new public items in
nsh-coreor the platform crates; this only changes what the platform-built Edit menu (andMenu.perform) does, matching the keyboard.Tests
tests/native/menu_copy.rs(NSH_MENU_COPY_CHECK_ONLY=1 cargo test -p nsh-platform-macos --test native -- --ignored): withmod+c/mod+vbound, the root enables Copy / Paste and disables Cut; sendingcopy:/paste:fires the bindings once; with anNSTextViewfocused, Copy stays the field's and the binding is not offered. Fails onmain(the root has novalidateMenuItem:), passes here.keymap.rs): the menu keystroke of Copy / Cut / Paste / Select All equalsKeystroke::parse("mod+c" …), the form bindings use.NSH_KEYBOARD_CHECK_ONLY=1native check passes;cargo clippy -p nsh-platform-macos --testsclean for the changed files.Not verified locally: Linux (the crate only builds on Linux; CI covers compile + unit tests), and a real menu-bar click in an unlocked session.
🤖 Generated with Claude Code
🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee