Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix selecting specific row on search #2904

Merged
merged 1 commit into from
Nov 19, 2024
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
52 changes: 29 additions & 23 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,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)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/clipboardbrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ class ClipboardBrowser final : public QListView

void dragDropScroll();

int currentRowFromSearch(const QString &search, int fallback);

ItemSaverPtr m_itemSaver;

QString m_tabName;
Expand All @@ -400,8 +402,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
Loading