diff options
author | Eike Ziller <eike.ziller@qt.io> | 2022-05-02 09:10:52 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2022-05-02 09:47:38 +0000 |
commit | f8a04666d5734be97195bc87f0d00f1773daffec (patch) | |
tree | 706cf4bf150b22b9a972dcd8ba0921ec69003a5f | |
parent | c3d04642e172c024ff7af15830a8bc9d66223eb7 (diff) |
Editors: Fix that actions were applied to wrong editor
We delayed switching the "current editor" by the double-click interval
to fix opening editors in extra editor windows from the project tree
etc. This leads to the weird effect that after switching the focus
between editors even within the same window was only applied after a
delay.
Instead just delay setting the current editor by "two events". When
clicking into a window, Qt sets the focus in two phases.
1. First the focus ends up in the focusWidget() in the new window, which
possibly is the editor that was active before in _that_ window
2. Only during the next event processing does Qt set the focus to the widget
that the user clicked into, which could be a non-editor widget, like the
Projects tree
We may only change the current editor if the focus didn't move away from
any editor in (2). So we need to delay setting the current editor until
after the next event processing.
Amends 22c67db406ec02d42e34dc182741ad473ba714fb
Fixes: QTCREATORBUG-27479
Change-Id: I3d9197176a2d7ce50e5f29a1ce1b2efef52232d0
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r-- | src/plugins/coreplugin/editormanager/editormanager.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 60a81aa027..657400027b 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -2389,15 +2389,26 @@ void EditorManagerPrivate::handleContextChange(const QList<IContext *> &context) if ((editor = qobject_cast<IEditor*>(c))) break; if (editor && editor != d->m_currentEditor) { + d->m_scheduledCurrentEditor = editor; // Delay actually setting the current editor to after the current event queue has been handled // Without doing this, e.g. clicking into projects tree or locator would always open editors // in the main window. That is because clicking anywhere in the main window (even over e.g. // the locator line edit) first activates the window and sets focus to its focus widget. // Only afterwards the focus is shifted to the widget that received the click. - d->m_scheduledCurrentEditor = editor; - QTimer::singleShot(QApplication::doubleClickInterval() + 10, - d, - &EditorManagerPrivate::setCurrentEditorFromContextChange); + + // 1) During this event handling, focus landed in the editor. + // 2) During the following event handling, focus might change to the project tree. + // So, delay setting the current editor by two events. + // If focus changes to e.g. the project tree in (2), then m_scheduledCurrentEditor is set to + // nullptr, and the setCurrentEditorFromContextChange call becomes a no-op. + QMetaObject::invokeMethod( + d, + [] { + QMetaObject::invokeMethod(d, + &EditorManagerPrivate::setCurrentEditorFromContextChange, + Qt::QueuedConnection); + }, + Qt::QueuedConnection); } else { updateActions(); } |