Skip to content

Conversation

lparry
Copy link

@lparry lparry commented Oct 14, 2025

Closes #4533 (partly at least)

Release Notes:

  • Added 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 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

Agent 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

Copy link

cla-bot bot commented Oct 14, 2025

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'.

@lparry
Copy link
Author

lparry commented Oct 14, 2025

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 14, 2025
Copy link

cla-bot bot commented Oct 14, 2025

The cla-bot has been summoned, and re-checked this pull request!

@lparry lparry force-pushed the lparry/more-file-sort-options branch 3 times, most recently from 5cc0a83 to 0f247cf Compare October 20, 2025 00:24
 ## 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
@lparry lparry force-pushed the lparry/more-file-sort-options branch from 0f247cf to d43b0be Compare October 20, 2025 00:29
@lparry
Copy link
Author

lparry commented Oct 20, 2025

I believe I have resolved the conflict & style linting problems now

@smitbarmase
Copy link
Member

@lparry I think there are still a bunch of errors when I try to compile it with cargo run. Can you give it a try and fix those errors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide an option to sort the files under folders in the sidebar

2 participants