Commit f84c6514 authored by con's avatar con
Browse files

Refactor navigation history again, put last edit position in history

Task:     240811
parent 393eb142
......@@ -501,7 +501,7 @@ void BookmarkManager::documentPrevNext(bool next)
}
Core::EditorManager *em = Core::EditorManager::instance();
em->addCurrentPositionToNavigationHistory(true);
em->addCurrentPositionToNavigationHistory();
if (next) {
if (nextLine == -1)
editor->gotoLine(firstLine);
......@@ -513,7 +513,6 @@ void BookmarkManager::documentPrevNext(bool next)
else
editor->gotoLine(prevLine);
}
em->addCurrentPositionToNavigationHistory();
}
void BookmarkManager::next()
......
......@@ -190,7 +190,7 @@ EditorManagerPrivate::EditorManagerPrivate(ICore *core, QWidget *parent) :
m_goBackAction(new QAction(EditorManager::tr("Go back"), parent)),
m_goForwardAction(new QAction(EditorManager::tr("Go forward"), parent)),
m_openInExternalEditorAction(new QAction(EditorManager::tr("Open in External Editor"), parent)),
currentNavigationHistoryPosition(-1),
currentNavigationHistoryPosition(0),
m_windowPopup(0),
m_coreListener(0)
{
......@@ -473,15 +473,11 @@ void EditorManager::setCurrentEditor(IEditor *editor, bool ignoreNavigationHisto
setCurrentView(0);
if (m_d->m_currentEditor == editor)
return;
if (m_d->m_currentEditor)
updateCurrentPositionInNavigationHistory();
if (m_d->m_currentEditor && !ignoreNavigationHistory)
addCurrentPositionToNavigationHistory();
m_d->m_currentEditor = editor;
if (editor) {
bool addToHistory = (!ignoreNavigationHistory);
if (addToHistory)
addCurrentPositionToNavigationHistory(true);
if (SplitterOrView *splitterOrView = m_d->m_splitter->findView(editor))
splitterOrView->view()->setCurrentEditor(editor);
}
......@@ -1374,17 +1370,17 @@ void EditorManager::addCurrentPositionToNavigationHistory(bool compress)
QByteArray state = editor->saveState();
// cut existing
int firstIndexToRemove;
if (compress && m_d->currentNavigationHistoryPosition >= 0) {
if (compress && m_d->currentNavigationHistoryPosition > 0) {
EditorManagerPrivate::EditLocation *previousLocation =
m_d->m_navigationHistory.at(m_d->currentNavigationHistoryPosition);
m_d->m_navigationHistory.at(m_d->currentNavigationHistoryPosition-1);
if ((previousLocation->editor && editor == previousLocation->editor)
|| (!fileName.isEmpty() && previousLocation->fileName == fileName)) {
firstIndexToRemove = m_d->currentNavigationHistoryPosition;
firstIndexToRemove = m_d->currentNavigationHistoryPosition-1;
} else {
firstIndexToRemove = m_d->currentNavigationHistoryPosition+1;
firstIndexToRemove = m_d->currentNavigationHistoryPosition;
}
} else {
firstIndexToRemove = m_d->currentNavigationHistoryPosition+1;
firstIndexToRemove = m_d->currentNavigationHistoryPosition;
}
if (firstIndexToRemove >= 0) {
for (int i = m_d->m_navigationHistory.size()-1; i >= firstIndexToRemove; --i) {
......@@ -1400,17 +1396,26 @@ void EditorManager::addCurrentPositionToNavigationHistory(bool compress)
location->kind = editor->kind();
location->state = QVariant(state);
m_d->m_navigationHistory.append(location);
m_d->currentNavigationHistoryPosition = m_d->m_navigationHistory.size()-1;
m_d->currentNavigationHistoryPosition = m_d->m_navigationHistory.size();
updateActions();
}
void EditorManager::updateCurrentPositionInNavigationHistory()
{
if (!m_d->m_currentEditor
|| m_d->currentNavigationHistoryPosition < 0
|| m_d->m_navigationHistory.at(m_d->currentNavigationHistoryPosition)->editor != m_d->m_currentEditor)
if (!m_d->m_currentEditor || !m_d->m_currentEditor->file())
return;
m_d->m_navigationHistory.at(m_d->currentNavigationHistoryPosition)->state = m_d->m_currentEditor->saveState();
EditorManagerPrivate::EditLocation *location;
if (m_d->currentNavigationHistoryPosition < m_d->m_navigationHistory.size()) {
location = m_d->m_navigationHistory[m_d->currentNavigationHistoryPosition];
} else {
location = new EditorManagerPrivate::EditLocation;
m_d->m_navigationHistory.append(location);
}
location->editor = m_d->m_currentEditor;
location->fileName = m_d->m_currentEditor->file()->fileName();
location->kind = m_d->m_currentEditor->kind();
location->state = QVariant(m_d->m_currentEditor->saveState());
}
void EditorManager::goBackInNavigationHistory()
......
......@@ -979,9 +979,8 @@ bool CPPEditor::openEditorAt(Symbol *s)
if (baseTextDocument()->fileName() == fileName) {
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->addCurrentPositionToNavigationHistory(true);
gotoLine(line, column);
editorManager->addCurrentPositionToNavigationHistory();
gotoLine(line, column);
setFocus();
return true;
}
......
......@@ -128,12 +128,11 @@ ITextEditor *BaseTextEditor::openEditorAt(const QString &fileName,
const QString &editorKind)
{
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->addCurrentPositionToNavigationHistory(true);
editorManager->addCurrentPositionToNavigationHistory();
Core::IEditor *editor = editorManager->openEditor(fileName, editorKind, Core::EditorManager::IgnoreNavigationHistory);
TextEditor::ITextEditor *texteditor = qobject_cast<TextEditor::ITextEditor *>(editor);
if (texteditor) {
texteditor->gotoLine(line, column);
editorManager->addCurrentPositionToNavigationHistory();
return texteditor;
}
return 0;
......@@ -565,6 +564,8 @@ Core::IFile *BaseTextEditor::file()
void BaseTextEditor::editorContentsChange(int position, int charsRemoved, int charsAdded)
{
d->m_contentsChanged = true;
// add last edit position to history
Core::EditorManager::instance()->addCurrentPositionToNavigationHistory(true);
// Keep the line numbers and the block information for the text marks updated
if (charsRemoved != 0) {
......
......@@ -62,9 +62,8 @@ void LineNumberFilter::accept(FilterEntry selection) const
if (editor) {
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->ensureEditorManagerVisible();
editorManager->addCurrentPositionToNavigationHistory(true);
editor->gotoLine(selection.internalData.toInt());
editorManager->addCurrentPositionToNavigationHistory();
editor->gotoLine(selection.internalData.toInt());
editor->widget()->setFocus();
}
}
......
......@@ -265,9 +265,8 @@ void VCSBaseEditor::slotDiffBrowse(int index)
return;
const int lineNumber = d->m_diffSections.at(index);
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->addCurrentPositionToNavigationHistory(true);
gotoLine(lineNumber + 1, 0); // TextEdit uses 1..n convention
editorManager->addCurrentPositionToNavigationHistory();
gotoLine(lineNumber + 1, 0); // TextEdit uses 1..n convention
}
// Locate a line number in the list of diff sections.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment