]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Avoid emitting twice twice selectionChanged when keyboard changes the selection,...
authorMéven Car <meven29@gmail.com>
Sun, 20 Oct 2019 10:35:52 +0000 (12:35 +0200)
committerMéven Car <meven29@gmail.com>
Sun, 20 Oct 2019 14:05:19 +0000 (16:05 +0200)
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

src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemlistselectionmanager.cpp
src/kitemviews/kitemlistselectionmanager.h

index 82553ddda257473b07f93e7e4b187b54786479f9..ad859c52a7808445f906d1dbdb6fe6fa1d37fcc7 100644 (file)
@@ -472,19 +472,18 @@ void KItemListController::slotChangeCurrentItem(const QString& text, bool search
     if (!m_model || m_model->count() == 0) {
         return;
     }
     if (!m_model || m_model->count() == 0) {
         return;
     }
-    const int currentIndex = m_selectionManager->currentItem();
     int index;
     if (searchFromNextItem) {
     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 + 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) {
     }
     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);
         }
 
             m_selectionManager->beginAnchoredSelection(index);
         }
 
index d16c5e2d31f0966401fd60dd01237d5b11a4b530..1b4f7db45fe6c9aa507b2778014356a6b66a3c16 100644 (file)
@@ -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()) {
 void KItemListSelectionManager::beginAnchoredSelection(int anchor)
 {
     if (anchor >= 0 && m_model && anchor < m_model->count()) {
index 4bb503a802bdd4b3a1108f19a80a43b6e8085dde..6f57100066029ee9704da3a6b41f2fb028aeae37 100644 (file)
@@ -62,6 +62,13 @@ public:
     bool hasSelection() const;
 
     void setSelected(int index, int count = 1, SelectionMode mode = Select);
     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);
     void clearSelection();
 
     void beginAnchoredSelection(int anchor);