Bug 421869 - Natural sorting does not sort shorter filename first when another one have underscore
Summary: Natural sorting does not sort shorter filename first when another one have un...
Status: RESOLVED FIXED
Alias: None
Product: dolphin
Classification: Applications
Component: view-engine: general (show other bugs)
Version: 19.12.3
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Dolphin Bug Assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-21 16:59 UTC by Eric Hoffman
Modified: 2024-11-25 12:09 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Hoffman 2020-05-21 16:59:05 UTC
SUMMARY
First, this is not the same as 420555 (I have found that too and saw the bug report for it).

When you have natural sorting enabled, Dolphin will not list the shorter file before a longer one if the longer one have an underscore at the position of the shorter file dot.

For example, I have files:
- file.txt
- file_with_underscore.txt

In natural mode, Dolphin will list them as

- file_with_underscore.txt
- file.txt

In alphabetical mode, it will list them in 'correct' order.

STEPS TO REPRODUCE

- Have sorting set to 'natural mode' (note that you must take care of bug 420555, which require you to re-open the config dialog if you changed the setting)
- Create 2 files in a directory, named "file.txt" and "file_with_underscore.txt"

OBSERVED RESULT

You see:
- file_with_underscore.txt
- file.txt

EXPECTED RESULT

Should discard extension part when comparing file names, as in alphabetical sort mode, or more specifically, as you get when you do ls -l with LC_COLLATE=C.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Kubuntu 20.04
KDE Plasma Version: 5.18.4
KDE Frameworks Version: 5.68.0
Qt Version: 5.12.8
Comment 1 Bug Janitor Service 2022-06-14 01:48:26 UTC
A possibly relevant merge request was started @ https://invent.kde.org/system/dolphin/-/merge_requests/410
Comment 2 Méven 2024-11-19 09:09:14 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 416025, bug 470538, 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
Comment 3 Carl Schwan 2024-11-25 12:09:32 UTC
Git commit 06f46b97a018133a9b9851c61c0e00622c6addb3 by Carl Schwan.
Committed on 25/11/2024 at 12:09.
Pushed by carlschwan into branch 'release/24.12'.

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 416025, bug 470538, bug 312027


(cherry picked from commit e4cc6e69430049366434e3383b1d2ef283ed22cc)

23a12f69 natural sort: exclude extension when comparing filenames
9d2d518b natural sort: refactors based on review
46695e10 natural sort: add testcase to compare against alphabetical sort

Co-authored-by: Eren Karakas <erenkarakas202@hotmail.com>

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/06f46b97a018133a9b9851c61c0e00622c6addb3