MacOS: Block shortcuts from overriding text input (#14869)
- It seems that on MacOS (vs other platforms), shortcuts for items in the application menu are given 'ultimate' priority, and will even take precedence over text inputs - There is a mechanism in QT (I believe designed with mac in mind) to try to 'block' these shortcuts and send it to the focus instead. It's 'Shortcut Override': https://wiki.qt.io/ShortcutOverride - Initially I was going to only apply this check when it's a Command that overrides a known line-editing shortcut, but I figure it's simpler to just always apply it when editing text. I can't really imagine a user wanting to use an application shortcut while editing text, but if there's some compelling use-case for this then let me know and I'll add a further filter. I'm quite optimistic that this won't have any ill-effects on other platforms, but I'll need help from others to test this.
This commit is contained in:
@@ -305,6 +305,26 @@ bool ShortcutManager::eventFilter(QObject* o, QEvent* ev)
|
||||
case QEvent::KeyPress:
|
||||
lastFocus = nullptr;
|
||||
break;
|
||||
case QEvent::ShortcutOverride: {
|
||||
auto kev = static_cast<QKeyEvent*>(ev);
|
||||
if (!kev) {
|
||||
break;
|
||||
}
|
||||
// don't process application shortcuts if we are editing a text widget
|
||||
if (auto* focus = QApplication::focusWidget()) {
|
||||
auto* maybeProxy = focus->focusProxy();
|
||||
auto* focusOrProxy = maybeProxy ? maybeProxy : focus;
|
||||
|
||||
bool isFocusedWidgetTextInput = focusOrProxy->inherits("QLineEdit")
|
||||
|| focusOrProxy->inherits("QTextEdit")
|
||||
|| focusOrProxy->inherits("QPlainTextEdit");
|
||||
if (isFocusedWidgetTextInput) {
|
||||
ev->accept();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QEvent::Shortcut:
|
||||
if (timeout > 0) {
|
||||
auto sev = static_cast<QShortcutEvent*>(ev);
|
||||
|
||||
Reference in New Issue
Block a user