diff --git a/src/ui/DiffView/DiffView.cpp b/src/ui/DiffView/DiffView.cpp index 089a11f7a..440800cea 100644 --- a/src/ui/DiffView/DiffView.cpp +++ b/src/ui/DiffView/DiffView.cpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace { @@ -198,11 +199,13 @@ void DiffView::setDiff(const git::Diff &diff) { fetchMore(); })); - mConnections.append( - connect(scrollBar, &QScrollBar::rangeChanged, [this](int min, int max) { + mConnections.append(connect( + scrollBar, &QScrollBar::rangeChanged, this, + [this](int min, int max) { if (max - min < this->widget()->height() / 2 && canFetchMore()) fetchMore(); - })); + }, + Qt::QueuedConnection)); // Request comments for this diff. if (Repository *remoteRepo = view->remoteRepo()) { @@ -380,6 +383,10 @@ bool DiffView::canFetchMore() { * use a while loop with canFetchMore() to get all */ void DiffView::fetchMore(int fetchWidgets) { + if (mFetching) + return; + QScopedValueRollback rollback(mFetching, true); + QVBoxLayout *layout = static_cast(widget()->layout()); // Add widgets. @@ -401,9 +408,6 @@ void DiffView::fetchMore(int fetchWidgets) { fetchAll)) { addedWidgets += lastFile->fetchMore(fetchAll ? -1 : 1); - // Load hunk(s) and update scrollbar - QApplication::processEvents(); - // Running the eventloop may trigger a view refresh if (mFiles.isEmpty()) return; diff --git a/src/ui/DiffView/DiffView.h b/src/ui/DiffView/DiffView.h index e72a8b18a..262340123 100644 --- a/src/ui/DiffView/DiffView.h +++ b/src/ui/DiffView/DiffView.h @@ -138,6 +138,7 @@ class DiffView : public QScrollArea, public EditorProvider { Account::CommitComments mComments; bool mEnabled{true}; + bool mFetching{false}; DiffTreeModel *mDiffTreeModel{nullptr}; QWidget *mParent{nullptr}; QVBoxLayout *mFileWidgetLayout{nullptr};