Fix filename sort order edge cases in explorer.#97200
Fix filename sort order edge cases in explorer.#97200isidorn merged 3 commits intomicrosoft:masterfrom
Conversation
Partially addresses issue microsoft#27759 Adds compareFileNamesNumeric() and compareFileExtensionsNumeric() funcitons, and uses the new functions in explorer view. Fixes the following edge cases: 1. Sorts the same name with different case in locale order (a < A) instead of unicode order (A < a). 2. Sorts the same name with different accents or diacritics by locale (á < à) instead of in unicode order (à < á) . 3. Sorts names that are equivalent in a numeric locale comparison as shortest numeric representation first (1 < 01 < 001) instead of unicode order (001 < 01 < 1). 4. For filenames with a name plus an extension, compares names first fand then compares extensions (aggregate.go < aggregate_repo.go) instead of comparing the whole name at once (aggregate_repo.go < aggregate.go) 5. Treats dotfiles (filenames that start with a dot) as filenames without extensions, instead of either as an empty filename plus an extension (single-dot dotfile), or a filename that starts with a dot plus an extension (multi-dot dotfile). This means all dotfiles group together in their own section when sorting by file type, (.eslintignore < .eslintrc.json < file.cs < file.js < file.json) instead of being interspersed between files grouped by type (file.cs < .eslintignore < file.js < .eslintrc.json < file.json). Note: other areas of workbench may benefit from the new functions as well but only explorer has been changed so far.
|
@isidorn the PR is failing CI, but I'm seeing the same problem when I run I also see odd behavior when I first build in a new branch or in master. The build reports ~33 errors - but if I go and click on those problems to open the files with the problems, then the problems go away? Did I miss a step somewhere that would prevent this? |
|
@leilapearson thank you very much for this great PR. Overall looks very good! Also thanks a lot for tests. fyi @bpasero if you have time to review and to be aware to potentially adopt this in the quick open in the future. |
|
LGTM, no plans currently to adopt this for quick open where imho the sorting is mainly driven by the score of the results and not by any alphabetic order. |
|
Thanks for the quick review @isidorn. I'll look at these right away. Regarding Search View, it still uses the original |
|
All done I think @isidorn. Let me know if I missed anything. |
|
Thanks a lot! Merging in ☀️ |
|
Thanks again @isidorn! Wanting the ability to group files by case is the reason I got involved in this issue - so for sure I'd like to provide that functionality. These edge cases weren't on my radar at all until I ran into them when working on that other code. I'll go ahead and create an empty PR as you suggest so that we can discuss the approach. |


This PR partially addresses issue #27759
This PR adds compareFileNamesNumeric() and compareFileExtensionsNumeric()
functions, and uses the new functions in explorer view in place of
compareFileNames() and compareFileExtensions().
The PR addresses the following edge cases:
unicode order (A < a).
(á < à) instead of in unicode order (à < á) .
as shortest numeric representation first (1 < 01 < 001) instead of
unicode order (001 < 01 < 1).
fand then compares extensions (aggregate.go < aggregate_repo.go)
instead of comparing the whole name at once
(aggregate_repo.go < aggregate.go)
without extensions, instead of either as an empty filename plus
an extension (single-dot dotfile), or a filename that starts with a
dot plus an extension (multi-dot dotfile). This means all dotfiles
group together in their own section when sorting by file type,
(.eslintignore < .eslintrc.json < file.cs < file.js < file.json) instead
of being interspersed between files grouped by type
(file.cs < .eslintignore < file.js < .eslintrc.json < file.json).
Besides adding unit tests, to make it easier to see the effects of these changes, I created this repo:
You can see the results comparing the existing behavior with the new behavior here:
Note that this PR does not address issue #27759 requests to:
A separate follow-up PR will provide new options that address these requests
Also note that other areas of workbench may benefit from adopting compareFileNamesNumeric
in place of compareFileNames, or compareFileExtensionsNumeric in place of
compareFileExtensions, but this PR only changes explorer view.
cc @isidorn