┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/kfileitemmodel.h
diff options
context:
space:
mode:
authorEren Karakas <[email protected]>2024-11-19 09:08:45 +0000
committerMéven Car <[email protected]>2024-11-19 09:08:45 +0000
commite4cc6e69430049366434e3383b1d2ef283ed22cc (patch)
treebd7e42cc1413a368545027ba23bbb2ed355e5bd0 /src/kitemviews/kfileitemmodel.h
parente893ceebb5a7295268ecf0ae2be5fb3fe07dfdbd (diff)
natural sort: exclude extension when comparing filenames
Currently natural sort compares the entire filenames (basename.extension) when sorting. This causes eg. "a 2.txt" to appear before "a.txt" when sorted by ascending. This is unintuitive since people prioritize basenames more than file extensions. Instead, change natural sort to compare by basename only and fallback to comparing extensions if basenames were equal. This change causes "a.txt" to appear before "a 2.txt" and matches how other platforms such as GNOME and Windows behave. BUG: 416025 BUG: 470538 BUG: 421869 BUG: 312027
Diffstat (limited to 'src/kitemviews/kfileitemmodel.h')
-rw-r--r--src/kitemviews/kfileitemmodel.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h
index 5662d4fa8..10be27128 100644
--- a/src/kitemviews/kfileitemmodel.h
+++ b/src/kitemviews/kfileitemmodel.h
@@ -365,7 +365,11 @@ private:
ItemData *parent;
};
- enum RemoveItemsBehavior { KeepItemData, DeleteItemData, DeleteItemDataIfUnfiltered };
+ enum RemoveItemsBehavior {
+ KeepItemData,
+ DeleteItemData,
+ DeleteItemDataIfUnfiltered
+ };
void insertItems(QList<ItemData *> &items);
void removeItems(const KItemRangeList &itemRanges, RemoveItemsBehavior behavior);
@@ -588,7 +592,9 @@ inline bool KFileItemModel::isRoleValueNatural(RoleType roleType)
inline bool KFileItemModel::nameLessThan(const ItemData *a, const ItemData *b)
{
- return a->item.text() < b->item.text();
+ // Split extension, taking into account it can be empty
+ constexpr QString::SectionFlags flags = QString::SectionSkipEmpty | QString::SectionIncludeLeadingSep;
+ return a->item.text().section('.', 0, 0, flags) < b->item.text().section('.', 0, 0, flags);
}
inline bool KFileItemModel::isChildItem(int index) const