From 0e8dca9937022e5315340145f4c09faafba87a83 Mon Sep 17 00:00:00 2001 From: timpieces Date: Mon, 15 Dec 2025 13:37:58 +0800 Subject: [PATCH] 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. --- src/Gui/ShortcutManager.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Gui/ShortcutManager.cpp b/src/Gui/ShortcutManager.cpp index a5cfd5c4fa..4d3e1f52eb 100644 --- a/src/Gui/ShortcutManager.cpp +++ b/src/Gui/ShortcutManager.cpp @@ -305,6 +305,26 @@ bool ShortcutManager::eventFilter(QObject* o, QEvent* ev) case QEvent::KeyPress: lastFocus = nullptr; break; + case QEvent::ShortcutOverride: { + auto kev = static_cast(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(ev);