From cd7a53abbbb81e468efb33eb56eefc12739969b8 Mon Sep 17 00:00:00 2001 From: Colfenor <34011017+Colfenor@users.noreply.github.com> Date: Mon, 25 Sep 2023 15:21:28 +0200 Subject: [PATCH] Fix first entry is not selected when a search is performed (#9868) --- src/gui/entry/EntryView.cpp | 3 ++- tests/gui/TestGui.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gui/entry/EntryView.cpp b/src/gui/entry/EntryView.cpp index e35b10e930..c587f7c1ea 100644 --- a/src/gui/entry/EntryView.cpp +++ b/src/gui/entry/EntryView.cpp @@ -219,11 +219,12 @@ void EntryView::displaySearch(const QList& entries) m_model->setEntries(entries); header()->showSection(EntryModel::ParentGroup); + setFirstEntryActive(); + // Reset sort column to 'Group', overrides DatabaseWidgetStateSync m_sortModel->sort(EntryModel::ParentGroup, Qt::AscendingOrder); sortByColumn(EntryModel::ParentGroup, Qt::AscendingOrder); - setFirstEntryActive(); m_inSearchMode = true; } diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 170bf3a175..4840092ea6 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -1082,6 +1082,13 @@ void TestGui::testSearch() QCOMPARE(groupView->currentGroup(), m_db->rootGroup()); QVERIFY(!m_dbWidget->isSearchActive()); + // check if first entry is selected after search + QTest::keyClicks(searchTextEdit, "some"); + QTRY_VERIFY(m_dbWidget->isSearchActive()); + QTRY_COMPARE(entryView->selectedEntries().length(), 1); + QModelIndex index_current = entryView->indexFromEntry(entryView->currentEntry()); + QTRY_COMPARE(index_current.row(), 0); + // Try to edit the first entry from the search view // Refocus back to search edit QTest::mouseClick(searchTextEdit, Qt::LeftButton);