Bug 312027 - Natural sorting should correctly sort associated numbered and unnumbered files
Summary: Natural sorting should correctly sort associated numbered and unnumbered files
Status: RESOLVED FIXED
Alias: None
Product: dolphin
Classification: Applications
Component: general (show other bugs)
Version: 2.1.85
Platform: Gentoo Packages Linux
: NOR wishlist
Target Milestone: ---
Assignee: Dolphin Bug Assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-21 09:44 UTC by Stefan Radermacher
Modified: 2024-11-19 09:08 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 Stefan Radermacher 2012-12-21 09:44:04 UTC
Given, for example, three files named as follows: File.ext, File 2.ext, and File 3. ext, Dolphin sorts these as follows, both with, or without natural sorting activated:

File 2.ext
File 3.ext
File.ext

This happens, of course, because the dot has a higher ASCII code than the space, but is is contrary to what you would expect, given natural sorting:

File.ext
File 2.ext
File 3.ext

Reproducible: Always
Comment 1 Christoph Feck 2012-12-21 14:34:28 UTC
So you want natural sorting to _only_ sort by alphabetical characters and numbers, ignoring any other characters (space, punctuation)? I doubt you will be able to come up with a fully specified sorting scheme, that works on all Unicode characters, and still fulfills your "expectation". For example, how to sort "File_1.txt" and "File#2.txt" ?
Comment 2 Stefan Radermacher 2012-12-21 15:41:20 UTC
I could imagine it working in a way that would disregard the extension of files named like this (including the dot) when sorting, and only take it into account when two or more files have the same name otherwise,
Comment 3 Justin Zobel 2021-03-09 02:18:26 UTC
Thank you for the bug report.

As this report hasn't seen any changes in 5 years or more, we ask if you can please confirm that the issue still persists.

If this bug is no longer persisting or relevant please change the status to resolved.
Comment 4 Stefan Radermacher 2021-03-09 08:39:23 UTC
(In reply to Justin Zobel from comment #3)
> Thank you for the bug report.
> 
> As this report hasn't seen any changes in 5 years or more, we ask if you can
> please confirm that the issue still persists.
> 
> If this bug is no longer persisting or relevant please change the status to
> resolved.

The behavior is still the same as originally reported.
Comment 5 spamless.9v5xj 2022-03-28 01:53:15 UTC
The solution frankly is less complex than everyone makes it out to be - all that needs to be done is make the dot/period have the highest priority when sorting. I don't believe anyone has particularly strong opinions on what the order of punctuation would be, so a slight idiosyncracy such as

a.file.txt
a file.txt
a_file.txt

is an acceptable tradeoff IMO.
Comment 6 Méven 2024-11-19 09:08:57 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 421869

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