]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistselectionmanager.cpp
Merge branch 'Applications/19.08'
[dolphin.git] / src / kitemviews / kitemlistselectionmanager.cpp
index 5d7b08eeb08b9df754dcba26596a42c5a3cc970d..d16c5e2d31f0966401fd60dd01237d5b11a4b530 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "kitemlistselectionmanager.h"
 
-#include "kitemmodelbase.h"
-
 KItemListSelectionManager::KItemListSelectionManager(QObject* parent) :
     QObject(parent),
     m_currentItem(-1),
@@ -237,6 +235,9 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges)
         // Calling setCurrentItem would trigger the selectionChanged signal, but we want to
         // emit it only once in this function -> change the current item manually and emit currentChanged
         m_currentItem += inc;
+        if (m_currentItem >= m_model->count()) {
+            m_currentItem = -1;
+        }
         emit currentChanged(m_currentItem, previousCurrent);
     }
 
@@ -330,6 +331,9 @@ void KItemListSelectionManager::itemsMoved(const KItemRange& itemRange, const QL
     // Store the current selection (needed in the selectionChanged() signal)
     const KItemSet previousSelection = selectedItems();
 
+    // Store whether we were doing an anchored selection
+    const bool wasInAnchoredSelection = isAnchoredSelectionActive();
+
     // endAnchoredSelection() adds all items between m_currentItem and
     // m_anchorItem to m_selectedItems. They can then be moved
     // individually later in this function.
@@ -347,7 +351,9 @@ void KItemListSelectionManager::itemsMoved(const KItemRange& itemRange, const QL
     }
 
     // Start a new anchored selection.
-    beginAnchoredSelection(m_currentItem);
+    if (wasInAnchoredSelection) {
+        beginAnchoredSelection(m_currentItem);
+    }
 
     // Update the selections
     if (!m_selectedItems.isEmpty()) {