Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/ui/DiffView/DiffView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QScrollBar>
#include <QPushButton>
#include <QMimeData>
#include <QScopedValueRollback>

namespace {

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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<QVBoxLayout *>(widget()->layout());

// Add widgets.
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/ui/DiffView/DiffView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Loading