From cf64d46bbebe636649cfd12c768aae31ef707bdb Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 27 May 2024 11:44:17 +0200 Subject: [PATCH] Markdown: Implement navigation history The text editor widget now tells us when it thinks a new navigation point should be added, so do it. Change-Id: I20e65134420cb1d94d7bc5310791d07ff951647c Reviewed-by: David Schulz --- src/plugins/texteditor/markdowneditor.cpp | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/plugins/texteditor/markdowneditor.cpp b/src/plugins/texteditor/markdowneditor.cpp index c08fedeb104..93b580a935e 100644 --- a/src/plugins/texteditor/markdowneditor.cpp +++ b/src/plugins/texteditor/markdowneditor.cpp @@ -110,6 +110,21 @@ public: m_textEditorWidget->setTextDocument(m_document); m_textEditorWidget->setupGenericHighlighter(); m_textEditorWidget->setMarksVisible(false); + QObject::connect( + m_textEditorWidget, + &TextEditorWidget::saveCurrentStateForNavigationHistory, + this, + &MarkdownEditor::saveCurrentStateForNavigationHistory); + QObject::connect( + m_textEditorWidget, + &TextEditorWidget::addSavedStateToNavigationHistory, + this, + &MarkdownEditor::addSavedStateToNavigationHistory); + QObject::connect( + m_textEditorWidget, + &TextEditorWidget::addCurrentStateToNavigationHistory, + this, + &MarkdownEditor::addCurrentStateToNavigationHistory); auto context = new IContext(this); context->setWidget(m_textEditorWidget); context->setContext(Context(MARKDOWNVIEWER_TEXT_CONTEXT)); @@ -476,6 +491,18 @@ private: } } + void saveCurrentStateForNavigationHistory() { m_savedNavigationState = saveState(); } + + void addSavedStateToNavigationHistory() + { + EditorManager::addCurrentPositionToNavigationHistory(m_savedNavigationState); + } + + void addCurrentStateToNavigationHistory() + { + EditorManager::addCurrentPositionToNavigationHistory(); + } + private: QTimer m_previewTimer; bool m_performDelayedUpdate = false; @@ -491,6 +518,7 @@ private: QAction *m_togglePreviewVisibleAction; QAction *m_swapViewsAction; std::optional m_previewRestoreScrollPosition; + QByteArray m_savedNavigationState; }; class MarkdownEditorFactory final : public IEditorFactory