Add vsc-unicode-natural sort order (VS Code / Windows Explorer style)#246
Open
siakun wants to merge 1 commit intoSebastianMC:masterfrom
Open
Add vsc-unicode-natural sort order (VS Code / Windows Explorer style)#246siakun wants to merge 1 commit intoSebastianMC:masterfrom
siakun wants to merge 1 commit intoSebastianMC:masterfrom
Conversation
Introduces a new sort order token 'vsc-unicode-natural' (alias: 'unicode-charcode-natural') which combines the existing vsc-unicode ordering with numeric-aware digit-run comparison. This mimics the default file sort behavior of VS Code and Windows Explorer. Implementation uses Intl.Collator with a fixed 'en' locale, base sensitivity, and numeric mode: - Punctuation and symbols precede letters via UCA weights (e.g. "[TODO]" < "CLAUDE") - Digit runs compared numerically, not lexically (e.g. "Part 2" < "Part 10") - Latin precedes CJK scripts regardless of the user's system locale (e.g. "Part" < "부록"), which is the main gap vs plain 'a-z' - Base sensitivity (case-insensitive, accent-insensitive) - Extension-inclusive comparison via sortStringWithExt, matching VS Code's behavior for files with identical basenames This addresses a limitation where users on non-Latin system locales (e.g. ko-KR) see CJK-first ordering when using 'a-z', and where 'vsc-unicode' alone lacks natural-number sorting so "Part 10" < "Part 2". Changes: - CustomSortOrder enum: vscUnicodeNatural / vscUnicodeNaturalReverse - custom-sort.ts: CollatorCompareVscNatural + Sorters entries - sorting-spec-processor.ts: register 'vsc-unicode-natural' and 'unicode-charcode-natural' tokens; place them before 'vsc-unicode' so the startsWith-based matcher does not pick the shorter name first - tests: add parser recognition test paralleling existing vsc-unicode coverage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new sort order token
vsc-unicode-natural(alias:unicode-charcode-natural) that combines the existingvsc-unicodeordering with numeric-aware digit-run comparison. This mimics the default file sort behavior of VS Code and Windows Explorer.Motivation
Users whose system locale is non-Latin (e.g.
ko-KR,ja-JP) currently face a gap between the two closest existing options:< a-z< vsc-unicodePart 10 < Part 2< vsc-unicode-natural(new)Concrete example from a Korean-locale vault with a book folder containing
Part 0throughPart 8,부록 A,부록 B,부록 C:< a-z→부록 A,부록 B,부록 C,Part 0, ... (CJK first)< vsc-unicode→Part 0, ...,Part 8,부록 A, ... (ok for now) butPart 10would sort beforePart 2< vsc-unicode-natural→ correct Windows/VSCode order, scales toPart 10+Implementation
Uses
+ 'Intl.Collator' +(' +'en'+, { numeric: true, sensitivity: 'base' })`:enlocale so collation is consistent across user machines; CJK stays after Latin via UCA defaultsnumeric: trueenables natural digit-run comparisonsensitivity: 'base'matches the existing alphabetical comparator's case/accent-insensitivity[TODO]correctly sorts beforeCLAUDE(matches VS Code behavior)sortStringWithExtso files with identical basenames but different suffixes (e.g.+ 'name (variant).md' +vs+ 'name.md' +) sort the way VS Code orders themChanges
CustomSortOrderenum: addvscUnicodeNatural/vscUnicodeNaturalReversecustom-sort.ts: addCollatorCompareVscNaturaland twoSortersentriessorting-spec-processor.ts: registervsc-unicode-naturalandunicode-charcode-naturaltokens. Important: these are placed before the existingvsc-unicode/unicode-charcodeentries because the parser uses astartsWithmatch onObject.keys(OrderLiterals)in declaration order, otherwisevsc-unicode-naturalis partially matched asvsc-unicodewith-naturalas trailing garbagesorting-spec-processor.spec.ts: add a parser recognition test that parallels the existingvsc-unicodecoverageTests
All 831 existing tests pass, plus the new test for
vsc-unicode-natural/unicode-charcode-naturaltoken recognition.Example usage
Notes
manifest.json,package.json, orversions.jsonsince those are release-time concerns< vsc-unicodeor< a-zcontinue to work unchangedvsc-unicode-numeric), add more tests, or split into smaller PRs if preferred