Skip to content

fix(keys): match desktop menu editing rules - #752

Merged
houko merged 3 commits into
mainfrom
fix/menu-shortcut-editing
Nov 19, 2026
Merged

houko merged 3 commits into
mainfrom
fix/menu-shortcut-editing

Conversation

@houko

@houko houko commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #710.

driver.MenuShortcut, which the core uses to decide whether a YieldsToMenu binding stands aside and which headless app.Key uses to choose a menu item, now models what the desktop menus do while a text input or web view has the focus:

  • It receives the target OS. On Linux, the GTK key path offers the menu no key pressed without Control, Alt or a logo key while editing (Shift alone does not count, as in internal/platform/linux/input.go), so such a binding stays in the keymap and runs.
  • A NotInText item takes nothing and keeps its shortcut from the items after it: macOS disables it during the key press and AppKit stops at the first matching key equivalent; Windows and Linux keep the first item of each shortcut spelling (menuKeys). Off macOS only that spelling is kept, since those backends look items up by each name of the press (mod+r, then ctrl+r), and an editing role's item keeps nothing, as those backends never register it.

Core keymap decisions, headless tests, KeyOptions.YieldsToMenu's doc comment, the architecture docs and the public testing docs (en, zh) use the same rules.

Targets

  • Shared code (core, base, ui, tsx, the nsgo tool)
  • macOS
  • iOS
  • tvOS
  • watchOS
  • Android
  • Windows
  • Linux
  • Web
  • Mini programs
  • Docs or website only

Screenshots

None. This changes keyboard/menu routing.

Verification

  • go build ./..., go vet of the touched packages for linux, windows (amd64, 386), android/arm64 and js/wasm
  • go tool nsgo check -target all (the Apple mobile targets need Xcode and were skipped there; the change has no build tags)
  • go tool nsgo test ./core, ./internal/driver, ./nsgotest, and go tool nsgo test -run 'Layer|Skills|Doc' .
  • New tests: internal/driver TestMenuShortcutEditing (table per desktop), new rows in core TestMenuYieldFollowsTextFocus, both reproductions in nsgotest TestApplicationMenuShortcuts
  • Linux (Ubuntu 24.04, Xvfb): new native TestMenuYieldReachesTheBindingTheMenuLeaves presses Control+R and F5 through the GTK key path; passes, and fails against main's model
  • Windows 11: new native TestMenuYieldReachesTheBindingTheMenuLeaves presses Control+R and F5 through the backend's shortcut path in the interactive session; passes, and fails against main's model. Added as its own CI step, as Windows' native menu tests run one per process
  • macOS: an nsgotest probe run with go tool nsgo test -target macos -activate (Refresh MenuNotEditing and Run, both Command+R, plus Reload F5, with yielding bindings): Command+R in a focused field runs the binding and F5 the Reload item; against main's model Command+R in the field ran nothing

@github-actions github-actions Bot added size/S documentation Improvements or additions to documentation core bug Something isn't working labels Nov 19, 2026
@houko
houko force-pushed the fix/menu-shortcut-editing branch from c4d2b9a to 83df878 Compare November 19, 2026 01:30
@houko houko mentioned this pull request Nov 19, 2026
9 of 19 tasks
@github-actions github-actions Bot added ci conflict Conflicts with the base branch; resolve it first labels Nov 19, 2026
Linux's key path treats a key pressed with Shift alone as unmodified, so MenuShortcut now decides by the press's Control, Alt and logo modifiers rather than by whether the item's shortcut has any modifier. Windows and Linux look an item up by its shortcut's own spelling and never register an editing role's key, so a NotInText item there keeps only its own spelling from later items and an editing role keeps nothing; macOS still stops at it. Native tests on Linux and Windows press both reproductions of #710 through the backends' key paths, and the headless menu test covers them on every desktop.
Windows' native menu tests each run in a process of their own on CI, so TestMenuYieldReachesTheBindingTheMenuLeaves needs its own step.
@houko
houko force-pushed the fix/menu-shortcut-editing branch from 49f2f16 to 13f7ebf Compare November 19, 2026 02:50
@github-actions github-actions Bot removed the conflict Conflicts with the base branch; resolve it first label Nov 19, 2026
@houko

houko commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. I checked the change against the Windows and Linux backends (menuKeys keeps the first enabled, non-editing-role item per shortcut spelling; menuShortcut returns false for a NotInText item while editing and the caller then tries the next spelling of the press; the GTK path offers no key without Control, Alt, Super or Meta to the menu while editing) and found driver.MenuShortcut now agrees with them on whether an item takes the key, which is all menuHasKey uses. No CHANGELOG change, no hard-wrapped lines, no unrelated changes.

Rebased onto current main (c76e42d). The docs and nsgotest/steps.go conflicted with the headless menu role work on main; I kept main's text and reapplied this PR's wording, and passed the OS to driver.MenuShortcut at main's new call site. Every commit builds.

Verification on the rebased branch:

  • Ubuntu build host: go build ./... at each commit; go vet for linux, windows amd64, and builds for windows/386, android/arm64 and js/wasm; go tool nsgo test for ./internal/driver (137 passed), ./core (737), ./nsgotest (102 passed, 1 skipped) and the root Layer/Skills/Doc tests (37).
  • With main's MenuShortcut restored, the new tests fail as expected: TestMenuShortcutEditing (7 cases), 16 rows of TestMenuYieldFollowsTextFocus on macOS, Windows and Linux, and TestApplicationMenuShortcuts (a later mod+i item ran on every desktop, and F5 ran the menu item on Linux).
  • Windows 11, interactive session: TestMenuYieldReachesTheBindingTheMenuLeaves and TestMenuYieldFollowsNativeFocus pass; the new test fails against main's model ("the keymap does not hold the binding true").
  • Linux, Ubuntu 24.04 VM under Xvfb: TestMenuYieldReachesTheBindingTheMenuLeaves and TestMenuYieldFollowsNativeTextFocus pass; the new test fails against main's model (Control+R in the focused field ran nothing). TestMenuYieldFollowsNativeWebFocus crashed in its WebKit subprocess on that VM and passes on the Ubuntu build host; it is not touched by this PR.
  • macOS, go tool nsgo test -target macos probe (Refresh MenuNotEditing and Run on Command+R, Reload on F5, both bindings yielding, a field focused): with the fix Command+R runs the binding and F5 runs Reload; with main's model Command+R runs nothing, neither the binding nor Run, which confirms AppKit stops at the disabled NotInText item.
  • CI: test, windows, android, apple, Build and vet (and Apple), Gallery (web), CodeQL and workflow validation pass. Gallery (macos) and apple-simulator are still queued for hosted macOS runners.

@houko
houko merged commit d1a59a1 into main Nov 19, 2026
20 checks passed
@houko
houko deleted the fix/menu-shortcut-editing branch November 19, 2026 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci core documentation Improvements or additions to documentation Linux size/M Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

menus: driver.MenuShortcut gives keys to items the Linux and Windows menus never choose while editing, so YieldsToMenu bindings lose them

1 participant