diff options
| author | Yifan Zhu <[email protected]> | 2025-02-20 10:35:06 -0800 |
|---|---|---|
| committer | Yifan Zhu <[email protected]> | 2025-02-22 14:26:57 -0800 |
| commit | b4dedc0d0df2c8b191192476d7787630180e51c7 (patch) | |
| tree | 095c84eee1c8e484b8d1ea1a568790c1aa6704fa /src/kitemviews/private | |
| parent | 79d1f25ad14b1626c64d7f25c2fa16da0e2b2737 (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/private')
| -rw-r--r-- | src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp | 10 | ||||
| -rw-r--r-- | src/kitemviews/private/kitemlistkeyboardsearchmanager.h | 1 |
2 files changed, 2 insertions, 9 deletions
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. */ |
