]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp
Merge branch 'Applications/18.04'
[dolphin.git] / src / kitemviews / private / kitemlistkeyboardsearchmanager.cpp
index 41ca34be46e06e054699b27819fea720f5254d95..ffa92a1cf0bd19cb578484a6076f4871333d6a06 100644 (file)
@@ -22,8 +22,6 @@
 
 #include "kitemlistkeyboardsearchmanager.h"
 
-#include <QApplication>
-#include <QElapsedTimer>
 
 KItemListKeyboardSearchManager::KItemListKeyboardSearchManager(QObject* parent) :
     QObject(parent),
@@ -40,12 +38,18 @@ void KItemListKeyboardSearchManager::addKeys(const QString& keys)
 {
     const bool keyboardTimeWasValid = m_keyboardInputTime.isValid();
     const qint64 keyboardInputTimeElapsed = m_keyboardInputTime.restart();
-    if (keyboardInputTimeElapsed > m_timeout || !keyboardTimeWasValid || keys.isEmpty()) {
+    if (keyboardInputTimeElapsed > m_timeout || !keyboardTimeWasValid) {
         m_searchedString.clear();
     }
 
     const bool newSearch = m_searchedString.isEmpty();
 
+    // Do not start a new search if the user pressed Space. Only add
+    // it to the search string if a search is in progress already.
+    if (newSearch && keys == QLatin1String(" ")) {
+        return;
+    }
+
     if (!keys.isEmpty()) {
         m_searchedString.append(keys);
 
@@ -78,3 +82,13 @@ void KItemListKeyboardSearchManager::cancelSearch()
 {
     m_searchedString.clear();
 }
+
+void KItemListKeyboardSearchManager::slotCurrentChanged(int current, int previous)
+{
+    Q_UNUSED(previous);
+
+    if (current < 0) {
+        // The current item has been removed. We should cancel the search.
+        cancelSearch();
+    }
+}