From b4dedc0d0df2c8b191192476d7787630180e51c7 Mon Sep 17 00:00:00 2001 From: Yifan Zhu Date: Thu, 20 Feb 2025 10:35:06 -0800 Subject: kitemlistkeyboardsearchmanager: smarter search start position Search from the next position for new search and special repeated key search. Otherwise search from the current position, which is current selected item if something is selected or in selection mode, and 0 (the beginning) otherwise. Test plan: - create directory with files ab1, ab2, and ab3 - click ab2, and press escape to deselect - type ab; verify that ab1 is selected - wait a while, type ab again, verify that ab2 is selected - wait a while, type ab again, verify that ab3 is selected - click ab1, type ab, verify that ab2 is selected BUG: 422951 --- src/kitemviews/kitemlistcontroller.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/kitemviews/kitemlistcontroller.cpp') diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 5a396de61..2f1bdc551 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -521,9 +521,9 @@ void KItemListController::slotChangeCurrentItem(const QString &text, bool search return; } int index; - if (searchFromNextItem) { - const int currentIndex = m_selectionManager->currentItem(); - index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count()); + // In selection mode, always use the current (underlined) item, or the next item, for search start position. + if (m_selectionBehavior == NoSelection || m_selectionMode || m_selectionManager->hasSelection()) { + index = m_model->indexForKeyboardSearch(text, searchFromNextItem ? m_selectionManager->currentItem() + 1 : m_selectionManager->currentItem()); } else { index = m_model->indexForKeyboardSearch(text, 0); } -- cgit v1.3