Skip to content

desktop: Keep an app's own Edit menu instead of adding a second one - #4237

Open
huacnlee wants to merge 2 commits into
mainfrom
agent/T-H0125-edit-menu
Open

huacnlee wants to merge 2 commits into
mainfrom
agent/T-H0125-edit-menu

Conversation

@huacnlee

@huacnlee huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member

Problem

desktop::menu_bar completes an app's menu with the platform's standard menus. It added the standard Edit menu (Undo, Redo, Cut, Copy, Paste, Select All) whenever the app's menu held no editing MenuRole. An app that builds its own Edit menu from plain items, such as an editor with its own undo and clipboard commands, ended up with two Edit menus. NsVim showed this while its macOS menu was being verified (huacnlee/nsvim#87 (comment)).

Change

  • A top-level menu whose title is Edit now stands in for the standard one. The title is matched against every translation NSH ships for its own Edit menu (desktop/menu.json, including the Windows variants). The match ignores case and Windows & mnemonics, so Edit, &Edit, 编辑 and Bearbeiten all count. AppKit identifies the Edit menu the same way: it adds Dictation and Emoji & Symbols to the menu titled Edit. In Electron and Tauri, once an app sets its own menu, nothing is added to it.
  • An Edit menu that has editing roles is still detected by its roles, as before.
  • No public API change. There is no opt-out flag, because defining the Edit menu yourself is the opt-out.

Behavior note: an app's own Edit menu now takes its shortcuts (⌘C, ⌘V, …). If its items carry the editing roles, the keys still go to a focused text field. The doc comment on menu_bar says this. NsVim's own Copy/Paste items will now handle ⌘C/⌘V on macOS, including inside its dialog inputs, so NsVim should check those inputs after it upgrades.

Tests

  • New unit test an_app_edit_menu_without_roles_replaces_the_standard_one. It runs on macOS and on Windows/Linux, with the titles Edit, &Edit, 编辑 and Bearbeiten, and checks that a menu titled View still gets the standard Edit menu. On main the test fails: two Edit menus.
  • cargo test -p nsh-core --lib desktop (48 passed), cargo clippy -p nsh-core --all-targets clean.

No real-window macOS screenshot of the menu bar yet: the verification Mac's screen was locked. It will follow as a comment.

🤖 Generated with Claude Code

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

The standard Edit menu was added whenever the app's menu held no
editing role, so an app with its own Edit menu of plain items (an
editor with its own undo and clipboard, NsVim) showed two Edit menus.
A top-level menu titled Edit, in any language NSH translates its menus
to, now stands in for the standard one, as an app's menu does in AppKit
and Electron.

Agent: rust-maintainer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@huacnlee

huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

💡 Fix is right; it changes shortcut ownership for apps with their own Edit menu.

Matches the app menu title against every shipped Edit translation, ignoring case and & (desktop.rs:1272), like AppKit/Electron. Side effect: an app Edit menu without editing roles now owns ⌘C/⌘V/⌘Z, so text fields in such apps (e.g. NsVim dialog inputs) lose default editing keys unless the app adds roles (desktop.rs:1340). No public API.

  • desktop.rs:1698 tests Bearbeiten; make sure menu.json has that German entry.
  • Promised macOS screenshot not posted yet.

Reviewed head df58d83 (diff read only). CI pending.

🤖 Noop (reviewer) · AI agent acting for @huacnlee

@huacnlee

huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

macOS check failed on main drift (WebHost.loading never read). Merged origin/main, which reads it again via hosted_content_loading; no conflicts.

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

This branch has not been deployed

No deployments
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.

1 participant