┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/kitemlistcontroller.cpp11
-rw-r--r--src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp5
-rw-r--r--src/kitemviews/private/kitemlistkeyboardsearchmanager.h11
3 files changed, 19 insertions, 8 deletions
diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp
index 955e418e8..29a5bd87a 100644
--- a/src/kitemviews/kitemlistcontroller.cpp
+++ b/src/kitemviews/kitemlistcontroller.cpp
@@ -436,13 +436,10 @@ bool KItemListController::keyPressEvent(QKeyEvent* event)
m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
m_selectionManager->beginAnchoredSelection(index);
break;
- } else {
- // Select the current item if it is not selected yet.
- const int current = m_selectionManager->currentItem();
- if (!m_selectionManager->isSelected(current)) {
- m_selectionManager->setSelected(current);
- break;
- }
+ } else if (m_keyboardManager->addKeyBeginsNewSearch()) { // File names shouldn't start with a space,
+ // so we can use this press as a keyboard shortcut instead.
+ Q_EMIT selectionModeChangeRequested(!m_selectionMode);
+ break;
}
}
Q_FALLTHROUGH(); // fall through to the default case and add the Space to the current search string.
diff --git a/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp b/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp
index 0e6280ede..e646a6249 100644
--- a/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp
+++ b/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp
@@ -63,6 +63,11 @@ void KItemListKeyboardSearchManager::addKeys(const QString& keys)
m_keyboardInputTime.start();
}
+bool KItemListKeyboardSearchManager::addKeyBeginsNewSearch() const
+{
+ return m_keyboardInputTime.hasExpired(m_timeout) || m_searchedString.isEmpty();
+}
+
void KItemListKeyboardSearchManager::setTimeout(qint64 milliseconds)
{
m_timeout = milliseconds;
diff --git a/src/kitemviews/private/kitemlistkeyboardsearchmanager.h b/src/kitemviews/private/kitemlistkeyboardsearchmanager.h
index 72f5695ce..80caea2ed 100644
--- a/src/kitemviews/private/kitemlistkeyboardsearchmanager.h
+++ b/src/kitemviews/private/kitemlistkeyboardsearchmanager.h
@@ -35,6 +35,11 @@ public:
* Add \a keys to the text buffer used for searching.
*/
void addKeys(const QString& keys);
+ /**
+ * @returns true if the next call to addKeys() will trigger a new search.
+ * Returns false if the next added key char will be added to the search string that was used previously.
+ */
+ bool addKeyBeginsNewSearch() const;
/**
* Sets the delay after which the search is cancelled to \a milliseconds.
@@ -46,7 +51,6 @@ public:
qint64 timeout() const;
void cancelSearch();
- bool shouldClearSearchIfInputTimeReached();
public Q_SLOTS:
@@ -66,9 +70,14 @@ Q_SIGNALS:
void changeCurrentItem(const QString& string, bool searchFromNextItem);
private:
+ bool shouldClearSearchIfInputTimeReached();
+
+private:
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. */
qint64 m_timeout;
};