Ensure leader updates don't change the active pane of followers

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-03-22 16:44:59 +01:00
parent 9885c4f6ba
commit c78bcf7116

View file

@ -4454,7 +4454,7 @@ mod tests {
// Client B opens an editor. // Client B opens an editor.
let workspace_b = client_b.build_workspace(&project_b, cx_b); let workspace_b = client_b.build_workspace(&project_b, cx_b);
let pane_b1 = workspace_a.read_with(cx_a, |workspace, _| workspace.active_pane().clone()); let pane_b1 = workspace_b.read_with(cx_b, |workspace, _| workspace.active_pane().clone());
let _editor_b1 = workspace_b let _editor_b1 = workspace_b
.update(cx_b, |workspace, cx| { .update(cx_b, |workspace, cx| {
workspace.open_path((worktree_id, "2.txt"), cx) workspace.open_path((worktree_id, "2.txt"), cx)
@ -4491,13 +4491,15 @@ mod tests {
workspace_a workspace_a
.update(cx_a, |workspace, cx| { .update(cx_a, |workspace, cx| {
workspace.activate_next_pane(cx); workspace.activate_next_pane(cx);
assert_eq!(*workspace.active_pane(), pane_a1);
workspace.open_path((worktree_id, "3.txt"), cx) workspace.open_path((worktree_id, "3.txt"), cx)
}) })
.await .await
.unwrap(); .unwrap();
workspace_b workspace_b
.update(cx_a, |workspace, cx| { .update(cx_b, |workspace, cx| {
workspace.activate_next_pane(cx); workspace.activate_next_pane(cx);
assert_eq!(*workspace.active_pane(), pane_b1);
workspace.open_path((worktree_id, "4.txt"), cx) workspace.open_path((worktree_id, "4.txt"), cx)
}) })
.await .await
@ -4506,20 +4508,42 @@ mod tests {
// Ensure leader updates don't change the active pane of followers // Ensure leader updates don't change the active pane of followers
workspace_a.read_with(cx_a, |workspace, _| { workspace_a.read_with(cx_a, |workspace, _| {
assert_ne!(*workspace.active_pane(), pane_a1); assert_eq!(*workspace.active_pane(), pane_a1);
}); });
workspace_b.read_with(cx_b, |workspace, _| { workspace_b.read_with(cx_b, |workspace, _| {
assert_ne!(*workspace.active_pane(), pane_b1); assert_eq!(*workspace.active_pane(), pane_b1);
}); });
// Ensure peers following each other doesn't cause an infinite loop. // Ensure peers following each other doesn't cause an infinite loop.
assert_eq!( assert_eq!(
workspace_b.read_with(cx_b, |workspace, cx| workspace workspace_a.read_with(cx_a, |workspace, cx| workspace
.active_item(cx) .active_item(cx)
.unwrap() .unwrap()
.project_path(cx)), .project_path(cx)),
Some((worktree_id, "3.txt").into()) Some((worktree_id, "3.txt").into())
); );
workspace_a.update(cx_a, |workspace, cx| {
assert_eq!(
workspace.active_item(cx).unwrap().project_path(cx),
Some((worktree_id, "3.txt").into())
);
workspace.activate_next_pane(cx);
assert_eq!(
workspace.active_item(cx).unwrap().project_path(cx),
Some((worktree_id, "4.txt").into())
);
});
workspace_b.update(cx_b, |workspace, cx| {
assert_eq!(
workspace.active_item(cx).unwrap().project_path(cx),
Some((worktree_id, "4.txt").into())
);
workspace.activate_next_pane(cx);
assert_eq!(
workspace.active_item(cx).unwrap().project_path(cx),
Some((worktree_id, "3.txt").into())
);
});
} }
#[gpui::test(iterations = 10)] #[gpui::test(iterations = 10)]