git_ui: Fix open diff for untracked files when sorting by path enabled (#39862)

Fixes the `Open Diff` action for untracked files when the `sort_by_path`
setting is enabled. The `ProjectDiff` wasn't correctly moving the
multibuffer's cursor to the untracked file because, when that setting is
enabled, it's sort prefix is changed to the tracked files sort prefix, and that
wasn't accounted for in `move_to_entry`.

Before these changes, the `sort_prefix` field for `PathKey` was called `namespace`, it was renamed to be clearer what its purpose is.

Closes #39529 

Release Notes:

- Fixed 'Open Diff' action for untracked files when `sort_by_path` is
enabled

---------

Co-authored-by: David Kleingeld <davidsk@zed.dev>
This commit is contained in:
Dino
2025-10-09 14:34:52 +00:00
committed by GitHub
co-authored by David Kleingeld
parent dd5da592f0
commit c58931ac04
6 changed files with 103 additions and 43 deletions
+6 -5
View File
@@ -161,24 +161,25 @@ impl MultiBufferDiffHunk {
#[derive(PartialEq, Eq, Ord, PartialOrd, Clone, Hash, Debug)]
pub struct PathKey {
namespace: Option<u64>,
// Used by the derived PartialOrd & Ord
sort_prefix: Option<u64>,
path: Arc<RelPath>,
}
impl PathKey {
pub fn namespaced(namespace: u64, path: Arc<RelPath>) -> Self {
pub fn with_sort_prefix(sort_prefix: u64, path: Arc<RelPath>) -> Self {
Self {
namespace: Some(namespace),
sort_prefix: Some(sort_prefix),
path,
}
}
pub fn for_buffer(buffer: &Entity<Buffer>, cx: &App) -> Self {
if let Some(file) = buffer.read(cx).file() {
Self::namespaced(file.worktree_id(cx).to_proto(), file.path().clone())
Self::with_sort_prefix(file.worktree_id(cx).to_proto(), file.path().clone())
} else {
Self {
namespace: None,
sort_prefix: None,
path: RelPath::unix(&buffer.entity_id().to_string())
.unwrap()
.into_arc(),