EditorManager: Do not switch mode in response to editor closing

Switching to design mode when in process of closing editor can result
in state where there is no active text editor for a document, which
is required to properly initialize design mode. This happens when
the next editor to be activated targets the same document as the
closed editor, i.e. when the last open document is used in split view.

To prevent design mode initialization crash, we block
changing to design mode in response to editor closing, if the
new editor targets the same document as the closed editor.

Fixes: QDS-3763
Change-Id: I2bd325b805d3e526778f8cdd8e583e87b8c93a24
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Miikka Heikkinen
2021-02-26 16:27:49 +02:00
parent 0d0eb5be24
commit 71c5f9e52b

View File

@@ -1730,9 +1730,8 @@ bool EditorManagerPrivate::closeEditors(const QList<IEditor*> &editors, CloseFla
if (editor == viewCurrentEditor && view == views.last()) {
// Avoid removing the globally current editor from its view,
// set a new current editor before.
const EditorManager::OpenEditorFlags flags = view != currentView
? EditorManager::DoNotChangeCurrentEditor
: EditorManager::NoFlags;
EditorManager::OpenEditorFlags flags = view != currentView
? EditorManager::DoNotChangeCurrentEditor : EditorManager::NoFlags;
const QList<IEditor *> viewEditors = view->editors();
IEditor *newCurrent = viewEditors.size() > 1 ? viewEditors.at(viewEditors.size() - 2)
: nullptr;
@@ -1748,6 +1747,10 @@ bool EditorManagerPrivate::closeEditors(const QList<IEditor*> &editors, CloseFla
const QList<DocumentModel::Entry *> documents = DocumentModel::entries();
if (!documents.isEmpty()) {
if (IDocument *document = documents.last()->document) {
// Do not auto-switch to design mode if the new editor will be for
// the same document as the one that was closed.
if (view == currentView && document == editor->document())
flags = EditorManager::DoNotSwitchToDesignMode;
activateEditorForDocument(view, document, flags);
}
}