Fix [m] menu keybindings not working on macOS#1587
Open
abaj8494 wants to merge 1 commit into
Open
Conversation
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.
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.
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 reachMyLineEdit::keyPressEventbecause macOS's Cocoa text input system intercepts them first — NSTextField's key binding mechanism maps Ctrl+N tomoveDown:, Ctrl+P tomoveUp:, etc., consuming the event before Qt can dispatch it.Root cause
Two issues:
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
KeyPressevent for them. However, they do arrive asQEvent::ShortcutOverrideevents in theBaseSelectorWidgetevent filter, which runs before Cocoa's text handling.MyLineEdit::keyPressEventdrops found commands. When a menu command is found viaget_menu_command, the handler callsevent->ignore()expecting the event to bubble up toMainWidget::keyPressEvent. This doesn't work because the widget hierarchy (MyLineEdit→BaseSelectorWidget→ …) doesn't guarantee propagation toMainWidget.Fix
ShortcutOverrideevents inBaseSelectorWidget::eventFilterand dispatch matching[m]menu commands directly viahandle_command_types.MyLineEdit::keyPressEvent, execute found menu commands immediately instead of ignoring the event.Testing
With
keys_user.config:Verified on macOS (ARM64, Qt 6.11):