Skip to content

Fix [m] menu keybindings not working on macOS#1587

Open
abaj8494 wants to merge 1 commit into
ahrm:developmentfrom
abaj8494:fix/macos-menu-keybindings
Open

Fix [m] menu keybindings not working on macOS#1587
abaj8494 wants to merge 1 commit into
ahrm:developmentfrom
abaj8494:fix/macos-menu-keybindings

Conversation

@abaj8494

Copy link
Copy Markdown

Problem

On macOS, [m]-prefixed menu keybindings (e.g. [m]control_menu(down) <C-n>) silently fail. Ctrl+key combos like Ctrl+N and Ctrl+P never reach MyLineEdit::keyPressEvent because macOS's Cocoa text input system intercepts them first — NSTextField's key binding mechanism maps Ctrl+N to moveDown:, Ctrl+P to moveUp:, etc., consuming the event before Qt can dispatch it.

Root cause

Two issues:

  1. Cocoa eats Ctrl+key events in text fields. The Cocoa input handling layer processes these combos at the NSView level, so Qt never generates a KeyPress event for them. However, they do arrive as QEvent::ShortcutOverride events in the BaseSelectorWidget event filter, which runs before Cocoa's text handling.

  2. MyLineEdit::keyPressEvent drops found commands. When a menu command is found via get_menu_command, the handler calls event->ignore() expecting the event to bubble up to MainWidget::keyPressEvent. This doesn't work because the widget hierarchy (MyLineEditBaseSelectorWidget → …) doesn't guarantee propagation to MainWidget.

Fix

  • Intercept ShortcutOverride events in BaseSelectorWidget::eventFilter and dispatch matching [m] menu commands directly via handle_command_types.
  • In MyLineEdit::keyPressEvent, execute found menu commands immediately instead of ignoring the event.

Testing

With keys_user.config:

[m]control_menu(down);[M]screen_down <C-n>
[m]control_menu(up);[M]screen_up <C-p>

Verified on macOS (ARM64, Qt 6.11):

  • Ctrl+N/P navigate up/down in search menus, bookmark lists, and open-document lists
  • Ctrl+N/P scroll the page in normal view
  • Backspace still works in menu search fields
  • Arrow keys continue to work in all menus

On macOS, Ctrl+key combinations (e.g. Ctrl+N, Ctrl+P) inside QLineEdit
are consumed by the Cocoa text input system (NSTextField's key binding
mechanism maps them to moveDown:/moveUp: etc.) before Qt generates a
KeyPress event. This means user-configured [m]-prefixed menu commands
like control_menu(down/up) are never dispatched.

These key combos do arrive as QEvent::ShortcutOverride events in the
BaseSelectorWidget event filter, so we intercept them there and execute
matching menu commands directly.

Also fix MyLineEdit::keyPressEvent to execute found menu commands
immediately rather than calling event->ignore(), which relied on the
event bubbling up to MainWidget — a path that doesn't work because the
widget hierarchy (MyLineEdit → BaseSelectorWidget → …) doesn't
guarantee propagation to MainWidget::keyPressEvent.
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