Skip to content

Commit

Permalink
Fix selecting specific row on search
Browse files Browse the repository at this point in the history
Fixes #2770
  • Loading branch information
hluk committed Nov 18, 2024
1 parent 13406b3 commit b6b56f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
32 changes: 17 additions & 15 deletions src/gui/clipboardbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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() ) {
Expand All @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions src/gui/clipboardbrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ class ClipboardBrowser final : public QListView
int m_dragTargetRow;
QPoint m_dragStartPosition;

int m_filterRow = -1;

bool m_selectNewItems = false;
};

Expand Down
2 changes: 0 additions & 2 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit b6b56f2

Please sign in to comment.