From 67121e6cd3e47a7b229dbecac6a61e06b3d7c474 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 29 Sep 2022 11:35:17 +0200 Subject: [PATCH] DiffEditor: Fix scrolling to current file after reloading This feature got broken during recent refactorings. Change-Id: I9d2d24e7ed63d5512b64c53e4bb9303497871d5e Reviewed-by: Orgad Shaneh --- src/plugins/diffeditor/diffeditorwidgetcontroller.h | 3 +++ src/plugins/diffeditor/sidebysidediffeditorwidget.cpp | 4 ++++ src/plugins/diffeditor/unifieddiffeditorwidget.cpp | 3 +++ 3 files changed, 10 insertions(+) diff --git a/src/plugins/diffeditor/diffeditorwidgetcontroller.h b/src/plugins/diffeditor/diffeditorwidgetcontroller.h index b36b434651e..ff2e541083e 100644 --- a/src/plugins/diffeditor/diffeditorwidgetcontroller.h +++ b/src/plugins/diffeditor/diffeditorwidgetcontroller.h @@ -43,6 +43,8 @@ public: void addExtraActions(QMenu *menu, int fileIndex, int chunkIndex, const ChunkSelection &selection); void updateCannotDecodeInfo(); void setBusyShowing(bool busy); + void setCurrentDiffFileIndex(int index) { m_currentDiffFileIndex = index; } + int currentDiffFileIndex() const { return m_currentDiffFileIndex; } ChunkData chunkData(int fileIndex, int chunkIndex) const; @@ -74,6 +76,7 @@ private: DiffEditorDocument *m_document = nullptr; bool m_isBusyShowing = false; + int m_currentDiffFileIndex = -1; Utils::ProgressIndicator *m_progressIndicator = nullptr; QTimer m_timer; }; diff --git a/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp b/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp index b2b1ec428d8..1922f8867ee 100644 --- a/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp +++ b/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp @@ -950,6 +950,8 @@ void SideBySideDiffEditorWidget::setCurrentDiffFileIndex(int diffFileIndex) const int blockNumber = m_leftEditor->diffData().blockNumberForFileIndex(diffFileIndex); const GuardLocker locker(m_controller.m_ignoreChanges); + m_controller.setCurrentDiffFileIndex(diffFileIndex); + QTextBlock leftBlock = m_leftEditor->document()->findBlockByNumber(blockNumber); QTextCursor leftCursor = m_leftEditor->textCursor(); leftCursor.setPosition(leftBlock.position()); @@ -1009,6 +1011,7 @@ void SideBySideDiffEditorWidget::showDiff() } m_leftEditor->setSelections(results[LeftSide].selections); m_rightEditor->setSelections(results[RightSide].selections); + setCurrentDiffFileIndex(m_controller.currentDiffFileIndex()); } m_watcher.release()->deleteLater(); m_controller.setBusyShowing(false); @@ -1241,6 +1244,7 @@ void SideBySideDiffEditorWidget::handlePositionChange(SideDiffEditorWidget *sour const GuardLocker locker(m_controller.m_ignoreChanges); syncCursor(source, dest); + m_controller.setCurrentDiffFileIndex(fileIndex); emit currentDiffFileIndexChanged(fileIndex); } diff --git a/src/plugins/diffeditor/unifieddiffeditorwidget.cpp b/src/plugins/diffeditor/unifieddiffeditorwidget.cpp index ee17ce94fe5..ff1db604c1a 100644 --- a/src/plugins/diffeditor/unifieddiffeditorwidget.cpp +++ b/src/plugins/diffeditor/unifieddiffeditorwidget.cpp @@ -132,6 +132,7 @@ void UnifiedDiffEditorWidget::slotCursorPositionChangedInEditor() return; const GuardLocker locker(m_controller.m_ignoreChanges); + m_controller.setCurrentDiffFileIndex(fileIndex); emit currentDiffFileIndexChanged(fileIndex); } @@ -499,6 +500,7 @@ void UnifiedDiffEditorWidget::showDiff() setReadOnly(true); } setSelections(result.selections); + setCurrentDiffFileIndex(m_controller.currentDiffFileIndex()); } m_watcher.release()->deleteLater(); m_controller.setBusyShowing(false); @@ -647,6 +649,7 @@ void UnifiedDiffEditorWidget::setCurrentDiffFileIndex(int diffFileIndex) return; const GuardLocker locker(m_controller.m_ignoreChanges); + m_controller.setCurrentDiffFileIndex(diffFileIndex); const int blockNumber = blockNumberForFileIndex(diffFileIndex); QTextBlock block = document()->findBlockByNumber(blockNumber);