]> cloud.milkyroute.net Git - dolphin.git/commitdiff
When the selection is deselected, restart the keyboard search from the beginning
authorMéven Car <meven29@gmail.com>
Sat, 26 Oct 2019 10:53:04 +0000 (12:53 +0200)
committerMéven Car <meven29@gmail.com>
Sat, 26 Oct 2019 10:53:34 +0000 (12:53 +0200)
Summary:
BUG: 411538
FIXED-IN: 19.12

Test Plan:
Open a directory with 3 files starting with the same letter.
1. Press this letter key twice
2. The second file is selected
3. Deselect the file with the mouse or using Esc
4. Wait 1 second
5. Press the same key again

Before:
The third file gets selected

After:
The first file get selected

ctest

Reviewers: #dolphin, elvisangelaccio, ngraham

Reviewed By: #dolphin, elvisangelaccio, ngraham

Subscribers: ngraham, kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D23716

src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp
src/kitemviews/private/kitemlistkeyboardsearchmanager.h
src/tests/kitemlistcontrollertest.cpp
src/tests/kitemlistkeyboardsearchmanagertest.cpp

index ad859c52a7808445f906d1dbdb6fe6fa1d37fcc7..8cc9529efb57f98e80f77454d43fba479f70d76b 100644 (file)
@@ -61,6 +61,8 @@ KItemListController::KItemListController(KItemModelBase* model, KItemListView* v
             this, &KItemListController::slotChangeCurrentItem);
     connect(m_selectionManager, &KItemListSelectionManager::currentChanged,
             m_keyboardManager, &KItemListKeyboardSearchManager::slotCurrentChanged);
+    connect(m_selectionManager, &KItemListSelectionManager::selectionChanged,
+            m_keyboardManager, &KItemListKeyboardSearchManager::slotSelectionChanged);
 
     m_autoActivationTimer = new QTimer(this);
     m_autoActivationTimer->setSingleShot(true);
index 82e8aa2ff877ca76e7e6896a02664ce566b6777d..09b4eaf23ff1948e8e38d3a6e5021c0f40ba6bd5 100644 (file)
@@ -22,9 +22,9 @@
 
 #include "kitemlistkeyboardsearchmanager.h"
 
-
 KItemListKeyboardSearchManager::KItemListKeyboardSearchManager(QObject* parent) :
     QObject(parent),
+    m_isSearchRestarted(false),
     m_timeout(1000)
 {
     m_keyboardInputTime.invalidate();
@@ -64,9 +64,13 @@ 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, or
+        // 1. a new search is started and a search has not been restarted or
         // 2. a 'repeated key' search is done.
-        const bool searchFromNextItem = newSearch || sameKey;
+        const bool searchFromNextItem = (!m_isSearchRestarted && newSearch) || sameKey;
+
+        // to remember not to searchFromNextItem if selection was deselected
+        // loosing keyboard search context basically
+        m_isSearchRestarted = false;
 
         emit changeCurrentItem(sameKey ? firstKey : m_searchedString, searchFromNextItem);
     }
@@ -85,6 +89,7 @@ qint64 KItemListKeyboardSearchManager::timeout() const
 
 void KItemListKeyboardSearchManager::cancelSearch()
 {
+    m_isSearchRestarted = true;
     m_searchedString.clear();
 }
 
@@ -97,3 +102,11 @@ void KItemListKeyboardSearchManager::slotCurrentChanged(int current, int previou
         cancelSearch();
     }
 }
+
+void KItemListKeyboardSearchManager::slotSelectionChanged(const KItemSet& current, const KItemSet& previous)
+{
+    if (!previous.isEmpty() && current.isEmpty() && previous.count() > 0 && current.count() == 0) {
+        // The selection has been emptied. We should cancel the search.
+        cancelSearch();
+    }
+}
index 29bec14141c14f02b1eab498dc088da902ca73d1..9995c16b0114d6f26b42888f782e9bfc6783099a 100644 (file)
@@ -24,6 +24,7 @@
 #define KITEMLISTKEYBOARDSEARCHMANAGER_H
 
 #include "dolphin_export.h"
+#include "kitemviews/kitemset.h"
 
 #include <QElapsedTimer>
 #include <QObject>
@@ -64,6 +65,7 @@ public:
 public slots:
 
     void slotCurrentChanged(int current, int previous);
+    void slotSelectionChanged(const KItemSet& current, const KItemSet& previous);
 
 signals:
     /**
@@ -79,6 +81,7 @@ signals:
 
 private:
     QString m_searchedString;
+    bool m_isSearchRestarted;
     QElapsedTimer m_keyboardInputTime;
     qint64 m_timeout;
 };
index 2fd71483e9465a23ba4865cfe440d359556f36d5..4cb1256e33d80ad62a54c371d4a68cb41da96b0f 100644 (file)
@@ -326,6 +326,12 @@ void KItemListControllerTest::testKeyboardNavigation_data()
                         << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13))
                         << qMakePair(KeyPress(Qt::Key_Space), ViewState(14, KItemSet() << 14))
                         << qMakePair(KeyPress(Qt::Key_3), ViewState(15, KItemSet() << 15))
+                        << qMakePair(KeyPress(Qt::Key_Escape), ViewState(15, KItemSet()))
+                        << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13))
+                        << qMakePair(KeyPress(Qt::Key_E), ViewState(14, KItemSet() << 14))
+                        << qMakePair(KeyPress(Qt::Key_E), ViewState(15, KItemSet() << 15))
+                        << qMakePair(KeyPress(Qt::Key_Escape), ViewState(15, KItemSet()))
+                        << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13))
                         << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0))
                         << qMakePair(KeyPress(Qt::Key_Escape), ViewState(0, KItemSet()));
 
index c14ce87ac88014a53a1a7010ca8e1227961c1019..53ef9ec3cac349d1baba9d14ddae401b00adac5b 100644 (file)
@@ -51,7 +51,7 @@ void KItemListKeyboardSearchManagerTest::testBasicKeyboardSearch()
 
     m_keyboardSearchManager.addKeys("f");
     QCOMPARE(spy.count(), 1);
-    QCOMPARE(spy.takeFirst(), QList<QVariant>() << "f" << true);
+    QCOMPARE(spy.takeFirst(), QList<QVariant>() << "f" << false);
 
     m_keyboardSearchManager.addKeys("i");
     QCOMPARE(spy.count(), 1);
@@ -77,7 +77,7 @@ void KItemListKeyboardSearchManagerTest::testAbortedKeyboardSearch()
 
     m_keyboardSearchManager.addKeys("f");
     QCOMPARE(spy.count(), 1);
-    QCOMPARE(spy.takeFirst(), QList<QVariant>() << "f" << true);
+    QCOMPARE(spy.takeFirst(), QList<QVariant>() << "f" << false);
 
     m_keyboardSearchManager.addKeys("i");
     QCOMPARE(spy.count(), 1);
@@ -94,6 +94,13 @@ void KItemListKeyboardSearchManagerTest::testAbortedKeyboardSearch()
     m_keyboardSearchManager.addKeys("e");
     QCOMPARE(spy.count(), 1);
     QCOMPARE(spy.takeFirst(), QList<QVariant>() << "le" << false);
+
+    // the selection was deselected, for instance with Esc or a click outside the selection
+    m_keyboardSearchManager.slotSelectionChanged(KItemSet(), KItemSet() << 1);
+
+    m_keyboardSearchManager.addKeys("a");
+    QCOMPARE(spy.count(), 1);
+    QCOMPARE(spy.takeFirst(), QList<QVariant>() << "a" << false);
 }
 
 void KItemListKeyboardSearchManagerTest::testRepeatedKeyPress()
@@ -109,7 +116,7 @@ void KItemListKeyboardSearchManagerTest::testRepeatedKeyPress()
 
     m_keyboardSearchManager.addKeys("p");
     QCOMPARE(spy.count(), 1);
-    QCOMPARE(spy.takeFirst(), QList<QVariant>() << "p" << true);
+    QCOMPARE(spy.takeFirst(), QList<QVariant>() << "p" << false);
 
     m_keyboardSearchManager.addKeys("p");
     QCOMPARE(spy.count(), 1);
@@ -138,7 +145,7 @@ void KItemListKeyboardSearchManagerTest::testPressShift()
     // Simulate that the user enters "a_b".
     m_keyboardSearchManager.addKeys("a");
     QCOMPARE(spy.count(), 1);
-    QCOMPARE(spy.takeFirst(), QList<QVariant>() << "a" << true);
+    QCOMPARE(spy.takeFirst(), QList<QVariant>() << "a" << false);
 
     m_keyboardSearchManager.addKeys("");
     QCOMPARE(spy.count(), 0);