Skip to content
Merged
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
33 changes: 16 additions & 17 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,13 @@ bool DiffView::canFetchMore() {
* use a while loop with canFetchMore() to get all
*/
void DiffView::fetchMore(int fetchWidgets) {
// Back out early if we're reentrant or lazy loading isn't triggered
if (mFetching ||
(verticalScrollBar()->maximum() - verticalScrollBar()->value() >
height() / 2))
return;
QScopedValueRollback rollback(mFetching, true);
Comment thread
Murmele marked this conversation as resolved.

QVBoxLayout *layout = static_cast<QVBoxLayout *>(widget()->layout());

// Add widgets.
Expand All @@ -395,23 +405,12 @@ void DiffView::fetchMore(int fetchWidgets) {
bool fetchFiles = true;
if (!mFiles.isEmpty()) {
FileWidget *lastFile = mFiles.last();
while (lastFile->canFetchMore() &&
((verticalScrollBar()->maximum() - verticalScrollBar()->value() <
height() / 2) ||
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;
if (lastFile->canFetchMore()) {
addedWidgets += lastFile->fetchMore(fetchAll ? -1 : fetchWidgets);
}

// Stop loading files
if (verticalScrollBar()->maximum() - verticalScrollBar()->value() >
height() / 2)
if (fetchAll == false && addedWidgets >= fetchWidgets)
fetchFiles = false;
}

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