From b6b56f29eb986dc85106ddec93c2f1cf0f772cec Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Mon, 18 Nov 2024 20:35:12 +0100 Subject: [PATCH] Fix selecting specific row on search Fixes #2770 --- src/gui/clipboardbrowser.cpp | 32 +++++++++++++++++--------------- src/gui/clipboardbrowser.h | 2 -- src/gui/mainwindow.cpp | 2 -- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/gui/clipboardbrowser.cpp b/src/gui/clipboardbrowser.cpp index 714ea62a0..228eec20e 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,16 +1302,6 @@ 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; if ( !filter || filter->matchesAll() ) { @@ -1323,13 +1312,26 @@ void ClipboardBrowser::filterItems(const ItemFilterPtr &filter) } else { for ( ; row < length() && hideFiltered(row); ++row ) {} - setCurrent(row); + int currentRow = row; for ( ; row < length(); ++row ) hideFiltered(row); - if ( filterByRowNumber && m_filterRow >= 0 && m_filterRow < m.rowCount() ) - setCurrent(m_filterRow); + // If search string is a number, highlight item in that row. + if (!m_sharedData->numberSearch) { + bool ok; + int maybeRow = newSearch.toInt(&ok); + if (ok) { + if (maybeRow > 0 && m_sharedData->rowIndexFromOne) + --maybeRow; + if (maybeRow >= 0 && maybeRow < m.rowCount()) { + currentRow = maybeRow; + setRowHidden(currentRow, false); + } + } + } + + setCurrent(currentRow); } d.updateAllRows(); diff --git a/src/gui/clipboardbrowser.h b/src/gui/clipboardbrowser.h index f7d9550c6..384acacda 100644 --- a/src/gui/clipboardbrowser.h +++ b/src/gui/clipboardbrowser.h @@ -400,8 +400,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); } } }