Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Prevent multibuffer items from switching active repository (#58795)

mengh04418f89714891
diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs
index 38d08718c82..75a28b0d9a9 100644
--- a/crates/git_ui/src/project_diff.rs
+++ b/crates/git_ui/src/project_diff.rs
@@ -273,6 +273,7 @@ impl ProjectDiff {
}
});
let diff_observation = cx.observe(&diff, |_, _, cx| cx.notify());
+
Self {
project,
workspace: workspace.downgrade(),
@@ -1367,6 +1368,18 @@ mod tests {
let paths_b = diff_item.read_with(cx, |diff, cx| diff.excerpt_paths(cx));
assert_eq!(paths_b.len(), 1);
assert_eq!(*paths_b[0], *"b.txt");
+
+ let active_repository_path = project.read_with(cx, |project, cx| {
+ project
+ .active_repository(cx)
+ .map(|repository| repository.read(cx).work_directory_abs_path.clone())
+ });
+
+ assert_eq!(
+ active_repository_path.as_deref(),
+ Some(Path::new(path!("/project_b"))),
+ "Project B should remain the active repository"
+ );
}
#[gpui::test]
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index b244a36e9b3..8bebe70702a 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -6623,7 +6623,16 @@ impl Workspace {
project.set_active_path(active_entry.clone(), cx)
});
- if focus_changed && let Some(project_path) = &active_entry {
+ // Infer the active repository only from singleton items.
+ // A multibuffer's active path represents the cursor's location within
+ // an aggregate view, so we assume it's not the user's intent to switch
+ // repositories.
+ if focus_changed
+ && let Some(project_path) = &active_entry
+ && self
+ .active_item(cx)
+ .is_some_and(|item| item.buffer_kind(cx) == ItemBufferKind::Singleton)
+ {
let git_store_entity = self.project.read(cx).git_store().clone();
git_store_entity.update(cx, |git_store, cx| {
git_store.set_active_repo_for_path(project_path, cx);