diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 6cb9b00b490..5d7ddb49a23 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 m_document; QList 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(); @@ -7588,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; @@ -9604,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(); @@ -10235,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(); diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index 78dc0e0b823..c155bb8ff21 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -169,6 +169,11 @@ public: private: friend class TextEditorFactory; friend class Internal::TextEditorFactoryPrivate; + + void saveCurrentStateForNavigationHistory(); + void addSavedStateToNavigationHistory(); + void addCurrentStateToNavigationHistory(); + Internal::BaseTextEditorPrivate *d; }; @@ -532,6 +537,11 @@ signals: void requestCallHierarchy(const QTextCursor &cursor); void toolbarOutlineChanged(QWidget *newOutline); + // used by the IEditor + void saveCurrentStateForNavigationHistory(); + void addSavedStateToNavigationHistory(); + void addCurrentStateToNavigationHistory(); + protected: QTextBlock blockForVisibleRow(int row) const; QTextBlock blockForVerticalOffset(int offset) const;