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);
#include "kitemlistkeyboardsearchmanager.h"
-
KItemListKeyboardSearchManager::KItemListKeyboardSearchManager(QObject* parent) :
QObject(parent),
+ m_isSearchRestarted(false),
m_timeout(1000)
{
m_keyboardInputTime.invalidate();
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);
}
void KItemListKeyboardSearchManager::cancelSearch()
{
+ m_isSearchRestarted = true;
m_searchedString.clear();
}
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();
+ }
+}
#define KITEMLISTKEYBOARDSEARCHMANAGER_H
#include "dolphin_export.h"
+#include "kitemviews/kitemset.h"
#include <QElapsedTimer>
#include <QObject>
public slots:
void slotCurrentChanged(int current, int previous);
+ void slotSelectionChanged(const KItemSet& current, const KItemSet& previous);
signals:
/**
private:
QString m_searchedString;
+ bool m_isSearchRestarted;
QElapsedTimer m_keyboardInputTime;
qint64 m_timeout;
};
<< 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()));
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);
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);
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()
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);
// 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);