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:
@@ -4973,6 +4973,7 @@ mod tests {
|
||||
use settings::SettingsStore;
|
||||
use theme::LoadThemes;
|
||||
use util::path;
|
||||
use util::rel_path::rel_path;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -5595,6 +5596,68 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_open_diff(cx: &mut TestAppContext) {
|
||||
init_test(cx);
|
||||
|
||||
let fs = FakeFs::new(cx.background_executor.clone());
|
||||
fs.insert_tree(
|
||||
path!("/project"),
|
||||
json!({
|
||||
".git": {},
|
||||
"tracked": "tracked\n",
|
||||
"untracked": "\n",
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
|
||||
fs.set_head_and_index_for_repo(
|
||||
path!("/project/.git").as_ref(),
|
||||
&[("tracked", "old tracked\n".into())],
|
||||
);
|
||||
|
||||
let project = Project::test(fs.clone(), [Path::new(path!("/project"))], cx).await;
|
||||
let workspace =
|
||||
cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
let cx = &mut VisualTestContext::from_window(*workspace, cx);
|
||||
let panel = workspace.update(cx, GitPanel::new).unwrap();
|
||||
|
||||
// Enable the `sort_by_path` setting and wait for entries to be updated,
|
||||
// as there should no longer be separators between Tracked and Untracked
|
||||
// files.
|
||||
cx.update(|_window, cx| {
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
store.update_user_settings(cx, |settings| {
|
||||
settings.git_panel.get_or_insert_default().sort_by_path = Some(true);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
cx.update_window_entity(&panel, |panel, _, _| {
|
||||
std::mem::replace(&mut panel.update_visible_entries_task, Task::ready(()))
|
||||
})
|
||||
.await;
|
||||
|
||||
// Confirm that `Open Diff` still works for the untracked file, updating
|
||||
// the Project Diff's active path.
|
||||
panel.update_in(cx, |panel, window, cx| {
|
||||
panel.selected_entry = Some(1);
|
||||
panel.open_diff(&Confirm, window, cx);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
let _ = workspace.update(cx, |workspace, _window, cx| {
|
||||
let active_path = workspace
|
||||
.item_of_type::<ProjectDiff>(cx)
|
||||
.expect("ProjectDiff should exist")
|
||||
.read(cx)
|
||||
.active_path(cx)
|
||||
.expect("active_path should exist");
|
||||
|
||||
assert_eq!(active_path.path, rel_path("untracked").into_arc());
|
||||
});
|
||||
}
|
||||
|
||||
fn assert_entry_paths(entries: &[GitListEntry], expected_paths: &[Option<&str>]) {
|
||||
assert_eq!(entries.len(), expected_paths.len());
|
||||
for (entry, expected_path) in entries.iter().zip(expected_paths) {
|
||||
|
||||
Reference in New Issue
Block a user