diff --git a/src/gui/clipboardbrowser.cpp b/src/gui/clipboardbrowser.cpp index 714ea62a0..e4504accf 100644 --- a/src/gui/clipboardbrowser.cpp +++ b/src/gui/clipboardbrowser.cpp @@ -324,8 +324,7 @@ bool ClipboardBrowser::isFiltered(int row) const return true; const QModelIndex ind = m.index(row); - return m_filterRow != row - && m_sharedData->itemFactory + return m_sharedData->itemFactory && !m_sharedData->itemFactory->matches(ind, *filter); } @@ -1303,36 +1302,43 @@ void ClipboardBrowser::filterItems(const ItemFilterPtr &filter) d.setItemFilter(filter); - // If search string is a number, highlight item in that row. - bool filterByRowNumber = !m_sharedData->numberSearch; - if (filterByRowNumber) { - m_filterRow = newSearch.toInt(&filterByRowNumber); - if (m_filterRow > 0 && m_sharedData->rowIndexFromOne) - --m_filterRow; - } - if (!filterByRowNumber) - m_filterRow = -1; - int row = 0; + for ( ; row < length() && hideFiltered(row); ++row ) {} - if ( !filter || filter->matchesAll() ) { - for ( ; row < length(); ++row ) - hideFiltered(row); + const int firstVisibleRow = row; + for ( ; row < length(); ++row ) + hideFiltered(row); + + if ( !filter || filter->matchesAll() ) { scrollTo(currentIndex(), PositionAtCenter); } else { - for ( ; row < length() && hideFiltered(row); ++row ) {} + const int currentRow = currentRowFromSearch(newSearch, firstVisibleRow); + setCurrent(currentRow); + } - setCurrent(row); + d.updateAllRows(); +} - for ( ; row < length(); ++row ) - hideFiltered(row); +int ClipboardBrowser::currentRowFromSearch(const QString &search, int fallback) +{ + if (m_sharedData->numberSearch) + return fallback; - if ( filterByRowNumber && m_filterRow >= 0 && m_filterRow < m.rowCount() ) - setCurrent(m_filterRow); - } + // If search string is a number, highlight item in that row. + bool ok; + int maybeRow = search.toInt(&ok); + if (!ok) + return fallback; - d.updateAllRows(); + if (maybeRow > 0 && m_sharedData->rowIndexFromOne) + --maybeRow; + + if (maybeRow < 0 || maybeRow >= m.rowCount()) + return fallback; + + setRowHidden(maybeRow, false); + return maybeRow; } void ClipboardBrowser::moveToClipboard(const QModelIndex &ind) diff --git a/src/gui/clipboardbrowser.h b/src/gui/clipboardbrowser.h index f7d9550c6..c4a7ab26e 100644 --- a/src/gui/clipboardbrowser.h +++ b/src/gui/clipboardbrowser.h @@ -374,6 +374,8 @@ class ClipboardBrowser final : public QListView void dragDropScroll(); + int currentRowFromSearch(const QString &search, int fallback); + ItemSaverPtr m_itemSaver; QString m_tabName; @@ -400,8 +402,6 @@ class ClipboardBrowser final : public QListView int m_dragTargetRow; QPoint m_dragStartPosition; - int m_filterRow = -1; - bool m_selectNewItems = false; }; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index f3e15b7fb..343288733 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -3575,9 +3575,7 @@ void MainWindow::enterSearchMode() if ( !ui->searchBar->text().isEmpty() ) { auto c = browserOrNull(); if (c) { - const int currentRow = c->currentIndex().row(); c->filterItems( ui->searchBar->filter() ); - c->setCurrent(currentRow); } } }