From a943350bd7782c0038bdead210289594455f963c Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Mon, 15 Feb 2010 14:11:12 +0100
Subject: [PATCH] Fixed cursor position in file when switching editors

When closing editor splits while the same document was visible in
two editors, it could happen that the state of the closed editor
survived (as opposed to sate of the editor which was still visible).
This had the negative effect, that when visiting the file again,
the cursor would jump to the obsolete position within the file.
---
 .../editormanager/editormanager.cpp           | 25 ++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 27bef7cee23..7d6b2b22099 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -583,6 +583,24 @@ void EditorManager::closeView(Core::Internal::EditorView *view)
         return;
     }
 
+    if (IEditor *e = view->currentEditor()) {
+        /*
+           when we are closing a view with an original editor which has
+           duplicates, then make one of the duplicates the original.
+           Otherwise the original would be kept around and the user might
+           experience jumping to a missleading position within the file when
+           visiting the file again. With the code below, the position within
+           the file will be the position of the first duplicate which is still
+           around.
+        */
+        if (!m_d->m_editorModel->isDuplicate(e)) {
+            QList<IEditor *> duplicates = m_d->m_editorModel->duplicatesFor(e);
+            if (!duplicates.isEmpty()) {
+                m_d->m_editorModel->makeOriginal(duplicates.first());
+            }
+        }
+    }
+
     emptyView(view);
 
     SplitterOrView *splitterOrView = m_d->m_splitter->findView(view);
@@ -597,10 +615,11 @@ void EditorManager::closeView(Core::Internal::EditorView *view)
 
     SplitterOrView *newCurrent = splitter->findFirstView();
     if (newCurrent) {
-        if (newCurrent->editor())
-            activateEditor(newCurrent->view(), newCurrent->editor());
-        else
+        if (IEditor *e = newCurrent->editor()) {
+            activateEditor(newCurrent->view(), e);
+        } else {
             setCurrentView(newCurrent);
+        }
     }
 }
 
-- 
GitLab