]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Ensure stable sort order when sorting by size
authorChristian Muehlhaeuser <muesli@gmail.com>
Sat, 10 Jul 2021 17:35:26 +0000 (19:35 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Tue, 13 Jul 2021 19:48:41 +0000 (21:48 +0200)
Folders with equal size caused the sort operation to become unstable,
as the result of lessThan was non-deterministic.

We need the fallback mechanisms at the bottom of the function to
resovle the situation and provide a stable sort order.

This also fixes expanding the contents of a folder into the wrong
parent.

BUG: 433247
FIXED-IN: 21.08

src/kitemviews/kfileitemmodel.cpp

index 9441bc8714c4ad6cd020b90b782dec060c2a9f41..e03ec7c0e9f2533a9d5e96a96fadbbb3955e9313 100644 (file)
@@ -1798,17 +1798,25 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
             auto valueB = b->values.value("count");
             if (valueA.isNull()) {
                 if (valueB.isNull()) {
-                    return 0;
+                    result = 0;
+                    break;
                 } else {
-                    return -1;
+                    result = -1;
+                    break;
                 }
             } else if (valueB.isNull()) {
-                return +1;
+                result = +1;
+                break;
             } else {
                 if (valueA.toLongLong() < valueB.toLongLong()) {
-                    return -1;
+                    result = -1;
+                    break;
+                } else if (valueA.toLongLong() > valueB.toLongLong()) {
+                    result = +1;
+                    break;
                 } else {
-                    return +1;
+                    result = 0;
+                    break;
                 }
             }
         }