┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
authorYifan Zhu <[email protected]>2025-02-20 10:35:06 -0800
committerYifan Zhu <[email protected]>2025-02-22 14:26:57 -0800
commitb4dedc0d0df2c8b191192476d7787630180e51c7 (patch)
tree095c84eee1c8e484b8d1ea1a568790c1aa6704fa /src/kitemviews
parent79d1f25ad14b1626c64d7f25c2fa16da0e2b2737 (diff)
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
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/kitemlistcontroller.cpp6
-rw-r--r--src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp10
-rw-r--r--src/kitemviews/private/kitemlistkeyboardsearchmanager.h1
3 files changed, 5 insertions, 12 deletions
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);
}
diff --git a/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp b/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp
index c18f87b7d..afc3bb071 100644
--- a/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp
+++ b/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp
@@ -10,7 +10,6 @@
KItemListKeyboardSearchManager::KItemListKeyboardSearchManager(QObject *parent)
: QObject(parent)
- , m_isSearchRestarted(false)
, m_timeout(1000)
{
m_keyboardInputTime.invalidate();
@@ -55,13 +54,9 @@ void KItemListKeyboardSearchManager::addKeys(const QString &keys)
const bool sameKey = m_searchedString.length() > 1 && m_searchedString.count(firstKey) == m_searchedString.length();
// Searching for a matching item should start from the next item if either
- // 1. a new search is started and a search has not been restarted or
+ // 1. a new search is started, or
// 2. a 'repeated key' search is done.
- const bool searchFromNextItem = (!m_isSearchRestarted && newSearch) || sameKey;
-
- // to remember not to searchFromNextItem if selection was deselected
- // losing keyboard search context basically
- m_isSearchRestarted = false;
+ const bool searchFromNextItem = newSearch || sameKey;
Q_EMIT changeCurrentItem(sameKey ? firstKey : m_searchedString, searchFromNextItem);
}
@@ -80,7 +75,6 @@ qint64 KItemListKeyboardSearchManager::timeout() const
void KItemListKeyboardSearchManager::cancelSearch()
{
- m_isSearchRestarted = true;
m_searchedString.clear();
}
diff --git a/src/kitemviews/private/kitemlistkeyboardsearchmanager.h b/src/kitemviews/private/kitemlistkeyboardsearchmanager.h
index 981d98cd3..5cb8effbf 100644
--- a/src/kitemviews/private/kitemlistkeyboardsearchmanager.h
+++ b/src/kitemviews/private/kitemlistkeyboardsearchmanager.h
@@ -72,7 +72,6 @@ private:
bool shouldClearSearchIfInputTimeReached();
QString m_searchedString;
- bool m_isSearchRestarted;
/** Measures the time since the last key press. */
QElapsedTimer m_keyboardInputTime;
/** Time in milliseconds in which a key press is considered as a continuation of the previous search input. */