After clearing bin filter line, ensure selected item is visible.

Fixes #845
parent 5e9c863d
......@@ -875,6 +875,16 @@ Bin::Bin(std::shared_ptr<ProjectItemModel> model, QWidget *parent)
// m_searchLine->setClearButtonEnabled(true);
m_searchLine->setPlaceholderText(i18n("Search..."));
m_searchLine->setFocusPolicy(Qt::ClickFocus);
connect(m_searchLine, &QLineEdit::textChanged, [this] (const QString &str) {
m_proxyModel->slotSetSearchString(str);
if (str.isEmpty()) {
// focus last selected item when clearing search line
QModelIndex current = m_proxyModel->selectionModel()->currentIndex();
if (current.isValid()) {
m_itemView->scrollTo(current, QAbstractItemView::PositionAtCenter);
}
}
});
auto *leventEater = new LineEventEater(this);
m_searchLine->installEventFilter(leventEater);
......@@ -2101,7 +2111,6 @@ void Bin::slotInitView(QAction *action)
});
connect(m_proxyModel.get(), &ProjectSortProxyModel::selectModel, this, &Bin::selectProxyModel);
connect(m_proxyModel.get(), &QAbstractItemModel::layoutAboutToBeChanged, this, &Bin::slotSetSorting);
connect(m_searchLine, &QLineEdit::textChanged, m_proxyModel.get(), &ProjectSortProxyModel::slotSetSearchString);
m_itemView->setModel(m_proxyModel.get());
m_itemView->setSelectionModel(m_proxyModel->selectionModel());
m_proxyModel->setDynamicSortFilter(true);
......
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