-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Add configurable sort modes to file explorer/project panel #40160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
We require contributors to sign our Contributor License Agreement, and we don't have @lparry on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
5cc0a83
to
0f247cf
Compare
## Summary Adds three sorting modes for the project panel to give users more control over how files and directories are displayed: - **`directories_first`** (default): Current behaviour - directories grouped before files - **`interleaved`**: Files and directories sorted together alphabetically - **`macos_like`**: Like interleaved, but with case-insensitive sorting (Finder-style) ## Motivation Users coming from different editors and file managers have different expectations for file sorting. Some prefer directories grouped at the top (traditional), while others prefer the macOS Finder-style interleaved sorting where "Apple1/", "apple2.tsx" and "Apple3/" appear alphabetically mixed together. ## Changes ### Core Implementation - Added `ProjectPanelSortMode` enum to settings with three variants - Implemented `compare_rel_paths_interleaved()` for mixed file/directory sorting - Implemented `compare_rel_paths_macos_like()` for case-insensitive interleaved sorting - Refactored sorting functions to accept a mode parameter while maintaining backward compatibility - Added `sort_mode` field to `ProjectPanelSettings` with `directories_first` as default ### User Experience - Settings UI integration with dropdown selector in Panels section - Real-time panel updates when sort mode changes - Documentation added to visual-customization.md - All three modes use natural sorting for numbers (e.g., "file2" < "file10") ### Testing & Performance - Comprehensive test coverage including edge cases (basename collisions, nested paths, stability) - Benchmark suite to measure performance across all three modes (interleaved is fastest, followed by macos-like, followed by the current implementation) - Fixed hard-coded path in benchmark to use `CARGO_MANIFEST_DIR` ## Technical Details **Sorting Implementations:** 1. **`directories_first`**: Uses existing `compare_rel_paths()` - directories have inherent priority, then natural sort within each group 2. **`interleaved`**: New `compare_rel_paths_interleaved()` - removes directory/file bias, compares by natural sort with deterministic full-path tie-breaking for entries like `foo/` vs `foo.rs` 3. **`macos_like`**: New `compare_rel_paths_macos_like()` - case-insensitive variant of interleaved using `natural_sort_case_insensitive()` helper **Key Design Decisions:** - Maintained backward compatibility with legacy `sort_worktree_entries()` functions - Used mode-aware wrappers (`sort_worktree_entries_with_mode()`) for new code - Settings observer triggers `update_visible_entries()` when sort mode changes - All sorting happens in-place for performance
0f247cf
to
d43b0be
Compare
I believe I have resolved the conflict & style linting problems now |
@lparry I think there are still a bunch of errors when I try to compile it with |
Closes #4533 (partly at least)
Release Notes:
project_panel.sort_mode
option to control explorer file sort (Directories first, interleaved, macOS-like)Summary
Adds three sorting modes for the project panel to give users more control over how files and directories are displayed:
directories_first
(default): Current behaviour - directories grouped before filesinterleaved
: Files and directories sorted together alphabeticallymacos_like
: Like interleaved, but with case-insensitive sorting (Finder-style)Motivation
Users coming from different editors and file managers have different expectations for file sorting. Some prefer directories grouped at the top (traditional), while others prefer the macOS Finder-style interleaved sorting where "Apple1/", "apple2.tsx" and "Apple3/" appear alphabetically mixed together.
Changes
Core Implementation
ProjectPanelSortMode
enum to settings with three variantscompare_rel_paths_interleaved()
for mixed file/directory sortingcompare_rel_paths_macos_like()
for case-insensitive interleaved sortingsort_mode
field toProjectPanelSettings
withdirectories_first
as defaultUser Experience
Testing & Performance
CARGO_MANIFEST_DIR
Technical Details
Sorting Implementations:
directories_first
: Uses existingcompare_rel_paths()
- directories have inherent priority, then natural sort within each groupinterleaved
: Newcompare_rel_paths_interleaved()
- removes directory/file bias, compares by natural sort with deterministic full-path tie-breaking for entries likefoo/
vsfoo.rs
macos_like
: Newcompare_rel_paths_macos_like()
- case-insensitive variant of interleaved usingnatural_sort_case_insensitive()
helperKey Design Decisions:
sort_worktree_entries()
functionssort_worktree_entries_with_mode()
) for new codeupdate_visible_entries()
when sort mode changesAgent usage
Co-pilot/claude-code + claude sonnet 4.5 helped out a lot. I'm not from a rust background, but really wanted this solved