fix: sort file names with leading zeros, prefixes, and numeric chunks correctly - #3036
Closed
AlexAndBear wants to merge 4 commits into
Closed
fix: sort file names with leading zeros, prefixes, and numeric chunks correctly#3036AlexAndBear wants to merge 4 commits into
AlexAndBear wants to merge 4 commits into
Conversation
AlexAndBear
force-pushed
the
issues/2993
branch
4 times, most recently
from
August 5, 2026 12:52
583389d to
616fdc5
Compare
AlexAndBear
marked this pull request as ready for review
August 5, 2026 12:52
AlexAndBear
force-pushed
the
issues/2993
branch
from
August 6, 2026 07:55
e933b12 to
d3f1913
Compare
AlexAndBear
force-pushed
the
issues/2993
branch
from
August 6, 2026 08:15
7cc9796 to
ee251e7
Compare
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.
Description
Improved file and folder name sorting to match Windows Explorer behavior, with proper handling of leading zeros, numeric prefixes, and complex naming patterns.
Problems Fixed (compared to main branch)
Main Branch Issues:
0,00,000were sorted inconsistently instead of by zero-countreportandreport finalwere not sorted as prefix/suffix pairsimg2,img02,img10didn't sort correctly (should beimg2<img02<img10)Examples of incorrect sorting in main:
00,000,0→ now correctly:0,00,000report final,report→ now correctly:report,report finalimg10,img2→ now correctly:img2,img10Project Archive,Project→ now correctly:Project,Project ArchiveWhat Changed
New Sorting Features
1. Correct Natural Sorting
0<00<000(longer zeros sort later when values equal)compareStringChunks()(sortInternals.ts:334-404)2. File Prefix/Suffix Detection
reportcomes beforereport finalcompareFileNamesByBasePrefix()(sortInternals.ts:172-229)3. Performance Optimization for Non-Name Sorting
4. Case/Accent Tiebreaking
finalTiebreakerCollatorwithsensitivity: 'variant'(sortInternals.ts:36-39)Apfel<Äpfel,File.txt<file.txt5. Comprehensive Test Coverage
.toEqual()instead of partial.filter().toMatchObject()File Structure
New:
sortInternals.ts- Core sorting logic (405 lines)sortItemsByField- Main entry point with Schwartzian transformcompareStringChunks- Unified chunk-based comparisoncompareFileNamesByBasePrefix- File-specific prefix/extension logicUpdated:
useSort.ts- Delegates tosortInternals.sortItemsByField()Performance Benchmarks
Comparison with main branch (20,000 items):
Trade-offs:
Testing
Unit Tests - All 5 tests pass:
spaceQuota.total)0,00,000sorted by count)report,report final)Äpfel/Apfel,Straße/Strasse)Quality Checks:
pnpm check:typespassespnpm format:checkpassespnpm test:unit --runpassesRelated Issue
Fixes #2993
Types of changes