Skip to content

core: YieldsToMenu ignores MenuEntry.NotInText, so a MenuNotEditing mod+r item leaves the key dead while a text input has focus #447

Closed

Description

@houko

Context

KeyOptions.YieldsToMenu leaves a binding's key to the application menu "while it has an enabled item with the same shortcut" (core/keys.go:44-45). keyActive drops such a binding whenever menuHasKey is true (core/keys.go:202-206), and menuHasKey asks menuTakes (core/keys.go:209-231, core/desktop.go:269-289), which looks at Disabled, Separator, submenus and the editing roles, but not at MenuEntry.NotInText.

NotInText is set for MenuItem.When == MenuNotEditing, and for MenuAuto items whose shortcut EditsText (core/desktop.go:305); the platforms then leave the shortcut to a focused text input or web view instead of choosing the item (internal/driver/services.go:603-606).

So while a text input has the focus, a NotInText item does not take its key, but a YieldsToMenu binding of the same key has already been removed from the keymap: the key does nothing.

What happens

The dev client binds Command/Control+R with YieldsToMenu: true (internal/dev/client.go:90-91). An app whose menu has MenuItem{Label: "Refresh", Shortcut: "mod+r", When: core.MenuNotEditing, OnSelect: ...}:

  • focus outside text: the menu item runs (expected);
  • focus in a text input: the menu item does not run (NotInText), and the dev reload binding is inactive because menuTakes counts the item, so Command/Control+R does nothing. mod+r is not a text-editing key (EditsText, core/keys.go:317-328), so the input does not use it either.

TSX exposes the same option (yieldsToMenu, tsx/services.go:105, tsx/types/index.d.ts:221), so app bindings hit it too.

Proposal

Have menuHasKey know whether a text input or web view has the focus (the tree already tracks it for KeyNotEditing) and skip NotInText entries in menuTakes in that case, so a yielding binding comes back exactly while the item does not take the key. Recompute the keymap on focus changes where it is not already.

Acceptance

  • With a MenuNotEditing mod+r item, a YieldsToMenu mod+r binding fires while a text input has the focus and yields to the item otherwise, on macOS, Windows and Linux.
  • A test in core covers both focus states.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions