Bug 413660 - Natural sorting not working as documented
Summary: Natural sorting not working as documented
Status: RESOLVED FIXED
Alias: None
Product: dolphin
Classification: Applications
Component: view-engine: general (show other bugs)
Version: 19.04.3
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Dolphin Bug Assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-31 11:23 UTC by Werner Lehmann
Modified: 2022-11-10 20:52 UTC (History)
9 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Example of the problem (186.51 KB, image/png)
2021-08-23 18:20 UTC, Xavier Corredor Llano
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Werner Lehmann 2019-10-31 11:23:04 UTC
SUMMARY
Natural sorting does not sort numbers in filenames (anymore?). The example in the Dolphin manual does not work like documented.

STEPS TO REPRODUCE
1. Enable natural sorting.
2. In a test folder, create test files: "touch File1 File2 File10"

OBSERVED RESULT
Regardless of selected sort order in Dolphin preferences, files are always sorted like this:
File1
File10
File2

EXPECTED RESULT
In natural sort order, files are sorted like this:
File1
File2
File10


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Kubuntu 19.10 with Plasma backports
KDE Plasma Version: 5.17.2
KDE Frameworks Version: 5.62.0
Qt Version: 5.12.4

ADDITIONAL INFORMATION
The reproducible example is taken from the Dolphin manual, see
https://docs.kde.org/stable5/en/applications/dolphin/configuring-dolphin.html

See also the result of ls with -v option:

$ ls -v
File1  File2  File10

$ ls 
File1  File10  File2

Reading other bugs I realize that this may be related to locale. This is my locale info:

LANG=en_US.UTF-8
LANGUAGE=en_US:de
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=de_DE.UTF-8
LC_TIME=de_DE.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES=POSIX
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=
Comment 1 Méven Car 2019-12-14 09:33:09 UTC
I don't reproduce it on Dolphin 20.04 / Plasma 5.18 / KF 5.65 from sources.
My locale is french.
Comment 2 Werner Lehmann 2020-01-26 00:15:58 UTC
Still present with 19.12.1. Here is a screenshot:
https://i.imgur.com/3anjuXt.png
Comment 3 Méven Car 2020-01-26 17:06:13 UTC
Have tried changing the setting (leave on natural) quit dolphin, launch it again and see if the behavior has changed ?
Comment 4 Werner Lehmann 2020-01-26 22:14:16 UTC
(In reply to Méven Car from comment #3)
> Have tried changing the setting (leave on natural) quit dolphin, launch it
> again and see if the behavior has changed ?

I have the setting on natural all the time anyway and had many Dolphin starts in the few months since reporting this. But I tried it and there is no difference. 

There is a minor other bug (I would say): after changing the sort order and closing the options dialog the file list is not resorted right away. Seems to be cached. On reopening the options dialog it is resorted, before changing any option. Keeping this in mind I can confirm that alphabetical order with or without case sensitivity works as expected. Natural seems to work exactly like alphabetical, case insensitive.
Comment 5 Christoph Feck 2020-02-14 13:58:57 UTC
Fixed with the commit for bug 406296.
Comment 6 Werner Lehmann 2020-02-14 21:35:17 UTC
(In reply to Christoph Feck from comment #5)
> Fixed with the commit for bug 406296.

Doesn't look fixed to me: https://i.imgur.com/xpex4OR.png - still sorted File1, File10, File2, not File1, File2, File10. Or is there a misunderstanding?
Comment 7 Christoph Feck 2020-02-14 21:39:37 UTC
You are right, I am running Dolphin from master instead of branch. It will be fixed with the next point release in April.
Comment 8 Werner Lehmann 2020-02-15 09:36:35 UTC
Thanks. Looking forward to it :-)
Comment 9 Andrés Cabero 2020-07-01 21:05:25 UTC
(In reply to Christoph Feck from comment #7)
> You are right, I am running Dolphin from master instead of branch. It will
> be fixed with the next point release in April.

I'm on the kde-unstable repo on Plasma 5.19 and it's not working
Comment 10 Andrés Cabero 2020-07-01 21:07:15 UTC
It might be relevant that the steps to reproduce involved files, but I
'm having this issue with folders
Comment 11 Christoph Feck 2020-07-01 21:15:46 UTC
The Plasma version is irrelevant. Make sure you have Dolphin 20.04.x. On my system, also folder names are correctly naturally sorted:

    cd /tmp; mkdir Test12; mkdir Test2

Order shown in Dolphin is: Test2 Test12
Comment 12 Andrés Cabero 2020-07-02 10:01:05 UTC
I have Dolphin 20.04.2, and it's not working

Proof: https://drive.google.com/drive/folders/1_FuuQsIoziYYH5ixzU2zHTiTbMn5LI3L?usp=sharing
Comment 13 Andrés Cabero 2020-07-02 10:03:35 UTC
(In reply to Christoph Feck from comment #11)
> The Plasma version is irrelevant. Make sure you have Dolphin 20.04.x. On my
> system, also folder names are correctly naturally sorted:
> 
>     cd /tmp; mkdir Test12; mkdir Test2
> 
> Order shown in Dolphin is: Test2 Test12

I ran that command, and it doesn't
Comment 14 Méven Car 2020-07-03 08:58:13 UTC
I noticed something on your screenshots, Andrés Cabero, you are using the details view but it is not sorted by Name : there should be an arrow pointing down in the name column header. Unless your theme hides it.
So can you check your sorting setting, Right Click > Sort by ?
Comment 15 Andrés Cabero 2020-07-03 09:08:08 UTC
(In reply to Méven Car from comment #14)
> I noticed something on your screenshots, Andrés Cabero, you are using the
> details view but it is not sorted by Name : there should be an arrow
> pointing down in the name column header. Unless your theme hides it.
> So can you check your sorting setting, Right Click > Sort by ?

It is actually sorted by name. The arrow doesn't appear because Dolphin was spanning half the viewport, but when it's set to fullscreen it does (may be related to my theme). It is also set to natural sorting, in case you wonder if I set it alphabetical
Comment 16 Méven Car 2020-07-03 10:06:34 UTC
Something else on your screenshot I noticed. You are using dolphin version control plugins.

And once I installed dolphin-plugins on my system in a git version controlled folder, I was able to reproduce the bug everywhere. (Test12 was before TEST2)
It is a different bug from the original though although close.

Even after uninstalling dolphin-plugins, the wrong behavior occurs.
This should help pinpointing the bug origin.
Comment 17 Andrés Cabero 2020-07-03 10:12:11 UTC
This is actually really weird, possibly another bug. The folder in the screenshot (it's a external hard drive) isn't even a git repository, but Dolphin treats it as one.
Comment 18 Méven Car 2020-07-06 07:37:28 UTC
Well I have reinstalled dolphin-plugins and I can't reproduce the bug anymore, so there is something weird somewhere.
(I test with Dolphin 19.12.3 btw)
Comment 19 Szczepan Hołyszewski 2020-09-08 19:11:24 UTC
NOT fixed in 20.04.0. Running 20.08.0, still experiencing the issue. Can't get natural sorting to work in any scenario whatsoever.
Comment 20 Szczepan Hołyszewski 2020-09-08 19:12:40 UTC
Everyone affected please vote!
Comment 21 Christoph Feck 2020-09-30 01:44:16 UTC
I saw this bug when I had misconfigured my locale settings.
Comment 22 Yamashita Ren 2020-11-12 22:32:26 UTC
I have this bug too.
Latest Archlinux.
Natural sorting, by name, alphabetically.
https://pix.louiz.org/o/lMtOl.jpg
Comment 24 Méven Car 2020-11-13 05:53:37 UTC
https://commits.kde.org/dolphin/9e3418bd558293a92b2e8bcba55f5a3f5d3cc5a4 was not a fix for this, it added natural sorting ordering on all columns not just on the title one.

This workaround seems to points out that the value LC_COLLATE is the major factor.

The formats kcm allows to set it, and update it (after a plasma logout/login), but by default does not read it or change it.

So my question for those who are affected:
 - what is your distro (it might be related to how the distro set your locate)
 - what is the value of your environment variables LANG and LC_COLLATE and whether or not it is set
 - Does setting the workaround, setting a ordering setting in systemsettings formats and restart plasma, fix the issue
Comment 25 Yamashita Ren 2020-11-17 22:13:12 UTC
- My distro is Archlinux. (A month old installation btw)
- LANG=fr_FR.UTF-8
  LC_COLLATE=fr_FR.UTF-8
- As said in my previous post, specifying the fr_FR ordering setting worked around the issue. 

Before the change, "Detailed setting was not ticked", the custom parameters were greyed out.
I think the greyed out "ordering setting" was showing "C" rather than "no modifications".
Comment 26 Méven Car 2020-11-18 06:53:49 UTC
(In reply to Yamashita Ren from comment #25)
> - My distro is Archlinux. (A month old installation btw)
> - LANG=fr_FR.UTF-8
>   LC_COLLATE=fr_FR.UTF-8
> - As said in my previous post, specifying the fr_FR ordering setting worked
> around the issue. 
> 
> Before the change, "Detailed setting was not ticked", the custom parameters
> were greyed out.

I would need those settings in the condition the bug reproduce.

> I think the greyed out "ordering setting" was showing "C" rather than "no
> modifications".

That's helpful, it confirms what I suspected : some distro (here arch) don't help users having LC_COLLATE adapted to their LANG.
In the kcm the ordering is LC_COLLATE.
We should probably try to warn users, to set a good LC_COLLATE value.
The Arch Linux french wiki documents this well https://wiki.archlinux.fr/locale#Ordre_de_tri
Anyway I believe this remaining bug is not much in fact kde-related.
Comment 27 Yamashita Ren 2020-11-18 08:12:28 UTC
What do you mean ?
My LC_COLLATE (as shown in `locale`) IS fr_FR.UTF-8.
The issue looks like that kcm, for whatever reason, default to C (or whatever it was) instead of respecting my system LC_COLLATE setting.

Which is why I had to manually specify LC_COLLATE=fr_FR.UTF-8 in the kcm.
Comment 28 Yamashita Ren 2020-11-18 08:23:50 UTC
kcm in bug situation : https://pix.louiz.org/o/iqaEm.jpg
Comment 29 Méven Car 2020-11-18 08:24:55 UTC
(In reply to Yamashita Ren from comment #27)
> What do you mean ?
> My LC_COLLATE (as shown in `locale`) IS fr_FR.UTF-8.
> The issue looks like that kcm, for whatever reason, default to C (or
> whatever it was) instead of respecting my system LC_COLLATE setting.
> 
By default the KCM does nothing, the system defined LC_COLLATE is used.
Probably LC_COLLATE=C was your default set LC_COLLATE.

> Which is why I had to manually specify LC_COLLATE=fr_FR.UTF-8 in the kcm.

This way would overwrote your system settings (plasma on startup uses the set value in the kcm to set the LC_COLLATE value).
Comment 30 Yamashita Ren 2020-11-18 08:33:46 UTC
Then how can I show you my system defined LC_COLLATE ?

Because for some unexplained reason, you don't seem to believe me when I tell you that my system LC_COLLATE is fr_FR.UTF-8...
Comment 31 Méven Car 2020-11-18 08:44:58 UTC
(In reply to Yamashita Ren from comment #30)
> Then how can I show you my system defined LC_COLLATE ?
> 
`env | grep LC_COLLATE`
or
`echo $LC_COLLATE`
(I don't have it set on my Kubuntu or neon installs)

> Because for some unexplained reason, you don't seem to believe me when I
> tell you that my system LC_COLLATE is fr_FR.UTF-8...

I believe you.

> > Probably LC_COLLATE=C was your default set LC_COLLATE.

For when you still experienced the bug.

The kcm settings are stored in `~/.config/plasma-localerc`.
If you don't have "useDetailed=true" in it, plasma does nothing to your settings and the kcm greys out the detailed parameters.
Comment 32 Yamashita Ren 2020-11-18 09:23:10 UTC
(In reply to Méven Car from comment #31)
> > > Probably LC_COLLATE=C was your default set LC_COLLATE.
> 
> For when you still experienced the bug.

This is the thing. My LC_COLLATE has been fr_FR.UTF8 for weeks. The locale is one of the first things I set up.

$ env | grep LC_COLLATE; echo $LC_COLLATE
LC_COLLATE=fr_FR.UTF-8
fr_FR.UTF-8

So THERE IS a bug. And I was a victim of it until I got fed up and looked how to fix it a week ago.

Moreover, you can see that KCM itself says that C is the default sort order : https://pix.louiz.org/o/iqaEm.jpg

Is it related to the bug ? I don't know.
All I know is that there is a bug to fix.
Comment 33 Méven Car 2020-11-18 10:00:41 UTC
(In reply to Yamashita Ren from comment #32)
> (In reply to Méven Car from comment #31)
> > > > Probably LC_COLLATE=C was your default set LC_COLLATE.
> > 
> > For when you still experienced the bug.
> 
> This is the thing. My LC_COLLATE has been fr_FR.UTF8 for weeks. The locale
> is one of the first things I set up.
> 
> $ env | grep LC_COLLATE; echo $LC_COLLATE
> LC_COLLATE=fr_FR.UTF-8
> fr_FR.UTF-8
> 
> So THERE IS a bug. And I was a victim of it until I got fed up and looked
> how to fix it a week ago.
> 
> Moreover, you can see that KCM itself says that C is the default sort order
> : https://pix.louiz.org/o/iqaEm.jpg
> 
> Is it related to the bug ? I don't know.
> All I know is that there is a bug to fix.

Thanks, could you copy here the content of ~/.config/plasma-localerc

I have an hypothesis as to what cause the issue and a possible fix.
Comment 34 Yamashita Ren 2020-11-18 10:48:01 UTC
$ cat ~/.config/plasma-localerc
[Formats]
LANG=fr_FR.UTF-8

[Translations]
LANGUAGE=fr:en_US
Comment 35 Méven Car 2020-11-27 10:25:06 UTC
(In reply to Yamashita Ren from comment #34)
> $ cat ~/.config/plasma-localerc
> [Formats]
> LANG=fr_FR.UTF-8
> 
> [Translations]
> LANGUAGE=fr:en_US

Have you logged out of your session since you applied your fix ?
How did you set your LC_COLLATE, I mean in the commandline or through bash_profile or equivalent ?
Comment 36 Méven Car 2020-11-27 10:29:40 UTC
(In reply to Yamashita Ren from comment #34)
> $ cat ~/.config/plasma-localerc
> [Formats]
> LANG=fr_FR.UTF-8
> 
> [Translations]
> LANGUAGE=fr:en_US

Have you logged out of your session since you applied your fix ?
How did you set your LC_COLLATE, I mean in the commandline or through bash_profile or equivalent ?
Comment 37 Xavier Corredor Llano 2021-08-23 18:20:39 UTC
Created attachment 140986 [details]
Example of the problem

I can confirm this ugly bug (tested with different LC_COLLATE, it doesn't affect at all in the sorting mode).

Dolphin Version 21.08.0
KDE framework: 5.85
Comment 38 Xavier Corredor Llano 2021-08-23 18:36:46 UTC
Indeed, the natural sorting mode shows different patterns with or without strings around, all are wrong:

$ mkdir {1..15}
$ mkdir {1..15}s
$ mkdir s{1..15}
Comment 39 Xavier Corredor Llano 2021-08-23 22:46:34 UTC
I can confirm that the problem is due to LC_COLLATE variable set to "C" (LC_COLLATE=C and maybe other values), I fixed not setting that variable (just delete in the config or doing export LC_COLLATE=""). 

I think this is not directly a bug or problem directly related to Dolphin, so I'm going to close it.
Comment 40 Luciano 2022-11-10 20:52:23 UTC
I was having this bug in Dolphin 22.08.3 and i followed this arch wiki's guide https://wiki.archlinux.org/title/KDE#Plasma_desktop_does_not_respect_locale/language_settings
---
I edited my `/etc/locale.conf` file and replaced the LANG key with value "C.UTF-8" with my language locale (in my case "en_US.UTF-8"), i also created the entry LC_COLLATE="en_US.UTF-8" (this entry is the important one i think)
Then i deleted `~/.config/plasma-localerc`
Ran `sudo locale-gen` (not necessary according to the wiki guide)
Logged out and in again
And i had natural sort working.
Hope this helps someone!