]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.cpp
Improvements for selections, smooth scrolling, tooltips and info-panel
[dolphin.git] / src / kitemviews / kfileitemmodel.cpp
index b191abab606f7769b8aab7e0ff2576c22464e515..ddc56209b8df72e1f319838640cb2e17f0dfd6a0 100644 (file)
@@ -403,8 +403,9 @@ void KFileItemModel::insertItems(const KFileItemList& items)
     KItemRangeList itemRanges;
     int targetIndex = 0;
     int sourceIndex = 0;
-    int insertedAtIndex = -1;
-    int insertedCount = 0;
+    int insertedAtIndex = -1;         // Index for the current item-range
+    int insertedCount = 0;            // Count for the current item-range
+    int previouslyInsertedCount = 0;  // Sum of previously inserted items for all ranges
     while (sourceIndex < sortedItems.count()) {
         // Find target index from m_items to insert the current item
         // in a sorted order
@@ -418,7 +419,8 @@ void KFileItemModel::insertItems(const KFileItemList& items)
 
         if (targetIndex - previousTargetIndex > 0 && insertedAtIndex >= 0) {
             itemRanges << KItemRange(insertedAtIndex, insertedCount);
-            insertedAtIndex = targetIndex;
+            previouslyInsertedCount += insertedCount;
+            insertedAtIndex = targetIndex - previouslyInsertedCount;
             insertedCount = 0;
         }
 
@@ -431,6 +433,7 @@ void KFileItemModel::insertItems(const KFileItemList& items)
 
         if (insertedAtIndex < 0) {
             insertedAtIndex = targetIndex;
+            Q_ASSERT(previouslyInsertedCount == 0);
         }
         ++targetIndex;
         ++sourceIndex;