┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMéven Car <[email protected]>2019-10-20 12:35:52 +0200
committerMéven Car <[email protected]>2019-10-20 16:05:19 +0200
commit56a38da57a020ed5617d5293013c4f8cc2d04fc3 (patch)
tree472d22057e1834aaaa8f9d29906fe219c9156e19 /src
parente3f1d50b73c95155c1409242baae7be55651d664 (diff)
Avoid emitting twice twice selectionChanged when keyboard changes the selection, fix slotChangeCurrentItem
Summary: In KItemListController::slotChangeCurrentItem searchFromNextItem use was bugged : The two branches of `if (searchFromNextItem)` both looked for the next keyboard with indexForKeyboardSearch(text, currentIndex (the first one with just a +1 modulo). But when searchFromNextItem is false, we are supposed to start to look for the next indexKeyboard from the start of the list `0`, not from the `currentIndex` Reviewers: elvisangelaccio, #dolphin Reviewed By: elvisangelaccio, #dolphin Subscribers: kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D24505
Diffstat (limited to 'src')
-rw-r--r--src/kitemviews/kitemlistcontroller.cpp7
-rw-r--r--src/kitemviews/kitemlistselectionmanager.cpp10
-rw-r--r--src/kitemviews/kitemlistselectionmanager.h7
3 files changed, 20 insertions, 4 deletions
diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp
index 82553ddda..ad859c52a 100644
--- a/src/kitemviews/kitemlistcontroller.cpp
+++ b/src/kitemviews/kitemlistcontroller.cpp
@@ -472,19 +472,18 @@ void KItemListController::slotChangeCurrentItem(const QString& text, bool search
if (!m_model || m_model->count() == 0) {
return;
}
- const int currentIndex = m_selectionManager->currentItem();
int index;
if (searchFromNextItem) {
+ const int currentIndex = m_selectionManager->currentItem();
index = m_model->indexForKeyboardSearch(text, (currentIndex + 1) % m_model->count());
} else {
- index = m_model->indexForKeyboardSearch(text, currentIndex);
+ index = m_model->indexForKeyboardSearch(text, 0);
}
if (index >= 0) {
m_selectionManager->setCurrentItem(index);
if (m_selectionBehavior != NoSelection) {
- m_selectionManager->clearSelection();
- m_selectionManager->setSelected(index, 1);
+ m_selectionManager->replaceSelection(index);
m_selectionManager->beginAnchoredSelection(index);
}
diff --git a/src/kitemviews/kitemlistselectionmanager.cpp b/src/kitemviews/kitemlistselectionmanager.cpp
index d16c5e2d3..1b4f7db45 100644
--- a/src/kitemviews/kitemlistselectionmanager.cpp
+++ b/src/kitemviews/kitemlistselectionmanager.cpp
@@ -173,6 +173,16 @@ void KItemListSelectionManager::clearSelection()
}
}
+void KItemListSelectionManager::replaceSelection(int index, int count)
+{
+ const KItemSet previous = selectedItems();
+ if (!previous.isEmpty()) {
+ m_selectedItems.clear();
+ m_isAnchoredSelectionActive = false;
+ }
+ setSelected(index, count);
+}
+
void KItemListSelectionManager::beginAnchoredSelection(int anchor)
{
if (anchor >= 0 && m_model && anchor < m_model->count()) {
diff --git a/src/kitemviews/kitemlistselectionmanager.h b/src/kitemviews/kitemlistselectionmanager.h
index 4bb503a80..6f5710006 100644
--- a/src/kitemviews/kitemlistselectionmanager.h
+++ b/src/kitemviews/kitemlistselectionmanager.h
@@ -62,6 +62,13 @@ public:
bool hasSelection() const;
void setSelected(int index, int count = 1, SelectionMode mode = Select);
+ /**
+ * Equivalent to:
+ * clearSelection();
+ * setSelected(index, count);
+ * but emitting once only selectionChanged signal
+ */
+ void replaceSelection(int index, int count = 1);
void clearSelection();
void beginAnchoredSelection(int anchor);