diff options
Diffstat (limited to 'src/plugins/texteditor/texteditor.cpp')
-rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 92636e63cd..5d7ddb49a2 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -354,6 +354,7 @@ public: BaseTextEditorPrivate() = default; TextEditorFactoryPrivate *m_origin = nullptr; + QByteArray m_savedNavigationState; }; class HoverHandlerRunner @@ -772,7 +773,6 @@ public: QSharedPointer<TextDocument> m_document; QList<QMetaObject::Connection> m_documentConnections; QByteArray m_tempState; - QByteArray m_tempNavigationState; bool m_parenthesesMatchingEnabled = false; QTimer m_parenthesesMatchingTimer; @@ -6498,7 +6498,7 @@ void TextEditorWidgetPrivate::slotUpdateRequest(const QRect &r, int dy) void TextEditorWidgetPrivate::saveCurrentCursorPositionForNavigation() { m_lastCursorChangeWasInteresting = true; - m_tempNavigationState = q->saveState(); + emit q->saveCurrentStateForNavigationHistory(); } void TextEditorWidgetPrivate::updateCurrentLineHighlight() @@ -6554,8 +6554,7 @@ void TextEditorWidget::slotCursorPositionChanged() << "indent:" << BaseTextDocumentLayout::userData(textCursor().block())->foldingIndent(); #endif if (!d->m_contentsChanged && d->m_lastCursorChangeWasInteresting) { - if (EditorManager::currentEditor() && EditorManager::currentEditor()->widget() == this) - EditorManager::addCurrentPositionToNavigationHistory(d->m_tempNavigationState); + emit addSavedStateToNavigationHistory(); d->m_lastCursorChangeWasInteresting = false; } else if (d->m_contentsChanged) { d->saveCurrentCursorPositionForNavigation(); @@ -6861,7 +6860,6 @@ void TextEditorWidget::mouseReleaseEvent(QMouseEvent *e) { const Qt::MouseButton button = e->button(); if (d->m_linkPressed && d->isMouseNavigationEvent(e) && button == Qt::LeftButton) { - EditorManager::addCurrentPositionToNavigationHistory(); bool inNextSplit = ((e->modifiers() & Qt::AltModifier) && !alwaysOpenLinksInNextSplit()) || (alwaysOpenLinksInNextSplit() && !(e->modifiers() & Qt::AltModifier)); @@ -7589,7 +7587,7 @@ bool TextEditorWidget::openLink(const Utils::Link &link, bool inNextSplit) } if (!inNextSplit && textDocument()->filePath() == link.targetFilePath) { - EditorManager::addCurrentPositionToNavigationHistory(); + emit addCurrentStateToNavigationHistory(); gotoLine(link.targetLine, link.targetColumn, true, true); setFocus(); return true; @@ -9605,6 +9603,23 @@ void BaseTextEditor::select(int toPos) editorWidget()->setTextCursor(tc); } +void BaseTextEditor::saveCurrentStateForNavigationHistory() +{ + d->m_savedNavigationState = saveState(); +} + +void BaseTextEditor::addSavedStateToNavigationHistory() +{ + if (EditorManager::currentEditor() == this) + EditorManager::addCurrentPositionToNavigationHistory(d->m_savedNavigationState); +} + +void BaseTextEditor::addCurrentStateToNavigationHistory() +{ + if (EditorManager::currentEditor() == this) + EditorManager::addCurrentPositionToNavigationHistory(); +} + void TextEditorWidgetPrivate::updateCursorPosition() { m_contextHelpItem = HelpItem(); @@ -10236,6 +10251,21 @@ BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentP [editor](EditorManager::OpenEditorFlags flags) { EditorManager::activateEditor(editor, flags); }); + QObject::connect( + textEditorWidget, + &TextEditorWidget::saveCurrentStateForNavigationHistory, + editor, + &BaseTextEditor::saveCurrentStateForNavigationHistory); + QObject::connect( + textEditorWidget, + &TextEditorWidget::addSavedStateToNavigationHistory, + editor, + &BaseTextEditor::addSavedStateToNavigationHistory); + QObject::connect( + textEditorWidget, + &TextEditorWidget::addCurrentStateToNavigationHistory, + editor, + &BaseTextEditor::addCurrentStateToNavigationHistory); if (m_useGenericHighlighter) textEditorWidget->setupGenericHighlighter(); |