Commit eee50d28 authored by Piotr Henryk Dabrowski's avatar Piotr Henryk Dabrowski Committed by Nate Graham
Browse files

[KFind] Natural auto-scrolling during new items insertion into search results view

Summary:
When new results are added to the list, ensure KFind continues to display the results that user has scrolled to or selected.

Finally no more partial results constantly running away from cursor...

{F7048436}

Reviewers: #kfind, ngraham, davidedmundson

Reviewed By: ngraham, davidedmundson

Subscribers: broulik, davidedmundson

Differential Revision: https://phabricator.kde.org/D22547
parent 214c1e58
......@@ -27,6 +27,7 @@
#include <QHeaderView>
#include <QMenu>
#include <QMimeData>
#include <QScrollBar>
#include <QTextCodec>
#include <QTextStream>
......@@ -395,9 +396,43 @@ void KFindTreeView::endSearch()
resizeToContents();
}
QList<QPersistentModelIndex> KFindTreeView::selectedVisibleIndexes() {
QModelIndexList selected = selectedIndexes();
if (selected.empty()) {
return QList<QPersistentModelIndex>();
}
QModelIndex index = indexAt(QPoint(0, 0));
QModelIndex bottomIndex = indexAt(viewport()->rect().bottomLeft());
QList<QPersistentModelIndex> result;
while (index.isValid()) {
if (selected.contains(index)) {
result.append(QPersistentModelIndex(index));
}
if (index == bottomIndex) {
break;
}
index = indexBelow(index);
}
return result;
}
void KFindTreeView::insertItems(const QList< QPair<KFileItem, QString> > &pairs)
{
auto hScroll = horizontalScrollBar()->value();
QPersistentModelIndex topIndex(indexAt(rect().topLeft()));
QList<QPersistentModelIndex> selectedVisible = selectedVisibleIndexes();
m_model->insertFileItems(pairs);
if (topIndex.isValid()) {
if (verticalScrollBar()->value() > 0) {
scrollTo(topIndex, QAbstractItemView::PositionAtTop);
}
}
if (!selectedVisible.empty()) {
scrollTo(selectedVisible.last());
}
horizontalScrollBar()->setValue(hScroll);
}
void KFindTreeView::removeItem(const QUrl &url)
......
......@@ -172,6 +172,8 @@ Q_SIGNALS:
private:
void resizeToContents();
QList<QPersistentModelIndex> selectedVisibleIndexes();
QDir m_baseDir;
KFindItemModel *m_model;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment