Bug 416025

Summary: Sorting by name takes the dot of file extension into account when sorting files
Product: [Applications] dolphin Reporter: Riccardo Robecchi <sephiroth_pk>
Component: generalAssignee: Dolphin Bug Assignee <dolphin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: kfm-devel, mail, mudo_jacal, php4fan
Priority: NOR    
Version: 19.12.1   
Target Milestone: ---   
Platform: Neon   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: File sorting example

Description Riccardo Robecchi 2020-01-08 21:21:05 UTC
Created attachment 124982 [details]
File sorting example

SUMMARY
The current implementation of natural sorting takes the dot of the file extension into account, and this makes it so that files with numbers in their name are shown before those with the same name but without numbers. It seems like the dot of the extension is treated as part of the file name; while it is indeed part of the file name in UNIX-like OSes due to magic numbers, from a user perspective this is unintuitive as we humans treat the file name and the extension as two separate things, with the dot acting as the separator.

STEPS TO REPRODUCE
1. create three files: "file.txt", "file 2.txt", "file 3.txt";
2. use sorting by name.

OBSERVED RESULT
The files are shown in the following order: "file 2.txt", "file 3.txt", "file.txt".

EXPECTED RESULT
The files should be sorted in what we might call a "natural" way: files with a space and a number following their name should come after those without space and number in their file name. This behaviour is seen in all other desktop environments (e.g. GNOME) and operating systems (e.g. Windows).

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: KDE neon
KDE Plasma Version: 5.17.4
KDE Frameworks Version: 5.65.0
Qt Version: 5.13.2

ADDITIONAL INFORMATION
Comment 1 Julian Steinmann 2020-01-10 20:22:41 UTC
Can confirm this behavior. Change proposed does seem sensible.
Comment 2 php4fan 2023-01-11 16:17:42 UTC
This is not just a sensible change proposal, this is a bug. Sorting file names like this is just wrong, there's no argument in favor of it (unless you can make one) and I've never seen file names being sorted like this anywhere outside of KDE. Even those pieces of software that are as non-smart as to put all uppercase letters before all lowercase letters, correctly put the dot before most other characters.

Actually I think this is a  regression and it used to behave correctly, but here I could be confused and it could just be when I started using KDE.
Comment 3 mudo_jacal 2023-05-23 11:00:04 UTC
I agree, this way of sorting is unique and can be slightly annoying.
Comment 4 Bug Janitor Service 2024-11-17 16:14:50 UTC
A possibly relevant merge request was started @ https://invent.kde.org/system/dolphin/-/merge_requests/858
Comment 5 Méven 2024-11-19 09:09:06 UTC
Git commit e4cc6e69430049366434e3383b1d2ef283ed22cc by Méven Car, on behalf of Eren Karakas.
Committed on 19/11/2024 at 09:08.
Pushed by meven into branch 'master'.

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.
Related: bug 470538, bug 421869, bug 312027

M  +18   -1    src/kitemviews/kfileitemmodel.cpp
M  +8    -2    src/kitemviews/kfileitemmodel.h
M  +78   -0    src/tests/kfileitemmodeltest.cpp

https://invent.kde.org/system/dolphin/-/commit/e4cc6e69430049366434e3383b1d2ef283ed22cc