fix(file-tree): sort file names numerically instead of lexicographically - #31756
fix(file-tree): sort file names numerically instead of lexicographically#31756beenotung wants to merge 2 commits into
Conversation
This fix addresses issue anomalyco#20459 where file names with numbers were sorted lexicographically rather than numerically (e.g., lesson-1, lesson-10, lesson-11, lesson-2 instead of lesson-1, lesson-2, lesson-3, lesson-10, lesson-11). The fix implements numeric sorting logic based on the pretty-sort library reference from the issue. The sorting algorithm: - Compares common prefix/suffix - Parses leading numbers from strings - Compares numbers when both strings have leading numbers - Falls back to string comparison when no numbers are present This affects both the main file tree component and the diff viewer file tree utilities. Co-authored-by: openhands <openhands@all-hands.dev>
Add tests to verify that file names with numbers are sorted numerically instead of lexicographically. Tests cover: - Basic numeric sorting (lesson-1, lesson-2, lesson-10, lesson-11) - Directory vs file sorting (directories before files) - Alphabetical sorting within groups - Mixed alphanumeric names - Leading zero handling Also add tests for the diff viewer file tree utilities to ensure consistent numeric sorting behavior. Co-authored-by: openhands <openhands@all-hands.dev>
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #20459
Type of change
What does this PR do?
This PR fixes the file tree sorting to sort file names numerically instead of lexicographically. Previously, files like 'file2.txt' would incorrectly appear after 'file10.txt' because the sorting was done character by character. Now it properly handles numeric sequences, so 'file2.txt' correctly appears before 'file10.txt'.
How did you verify your code works?
The PR includes tests that verify the numeric sorting behavior works correctly.
Checklist