mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-04 06:34:26 +00:00
Make following more good
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
1cfc2f0c07
commit
92bb9a5fdc
6 changed files with 1263 additions and 1127 deletions
|
@ -4,6 +4,7 @@ use gpui::{ModelHandle, TestAppContext};
|
|||
mod channel_buffer_tests;
|
||||
mod channel_message_tests;
|
||||
mod channel_tests;
|
||||
mod following_tests;
|
||||
mod integration_tests;
|
||||
mod random_channel_buffer_tests;
|
||||
mod random_project_collaboration_tests;
|
||||
|
|
1189
crates/collab/src/tests/following_tests.rs
Normal file
1189
crates/collab/src/tests/following_tests.rs
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1090,55 +1090,30 @@ impl CollabTitlebarItem {
|
|||
},
|
||||
);
|
||||
|
||||
match (replica_id, location) {
|
||||
// If the user's location isn't known, do nothing.
|
||||
(_, None) => content.into_any(),
|
||||
|
||||
// If the user is not in this project, but is in another share project,
|
||||
// join that project.
|
||||
(None, Some(ParticipantLocation::SharedProject { project_id })) => content
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, move |_, this, cx| {
|
||||
if let Some(workspace) = this.workspace.upgrade(cx) {
|
||||
let app_state = workspace.read(cx).app_state().clone();
|
||||
workspace::join_remote_project(project_id, user_id, app_state, cx)
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
})
|
||||
.with_tooltip::<TitlebarParticipant>(
|
||||
peer_id.as_u64() as usize,
|
||||
format!("Follow {} into external project", user.github_login),
|
||||
Some(Box::new(FollowNextCollaborator)),
|
||||
theme.tooltip.clone(),
|
||||
cx,
|
||||
)
|
||||
.into_any(),
|
||||
|
||||
// Otherwise, follow the user in the current window.
|
||||
_ => content
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, move |_, item, cx| {
|
||||
if let Some(workspace) = item.workspace.upgrade(cx) {
|
||||
if let Some(task) = workspace
|
||||
.update(cx, |workspace, cx| workspace.toggle_follow(peer_id, cx))
|
||||
{
|
||||
task.detach_and_log_err(cx);
|
||||
}
|
||||
}
|
||||
})
|
||||
.with_tooltip::<TitlebarParticipant>(
|
||||
peer_id.as_u64() as usize,
|
||||
if self_following {
|
||||
format!("Unfollow {}", user.github_login)
|
||||
} else {
|
||||
format!("Follow {}", user.github_login)
|
||||
},
|
||||
Some(Box::new(FollowNextCollaborator)),
|
||||
theme.tooltip.clone(),
|
||||
cx,
|
||||
)
|
||||
.into_any(),
|
||||
if Some(peer_id) == self_peer_id {
|
||||
return content.into_any();
|
||||
}
|
||||
|
||||
content
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, move |_, this, cx| {
|
||||
let Some(workspace) = this.workspace.upgrade(cx) else {
|
||||
return;
|
||||
};
|
||||
if let Some(task) =
|
||||
workspace.update(cx, |workspace, cx| workspace.follow(peer_id, cx))
|
||||
{
|
||||
task.detach_and_log_err(cx);
|
||||
}
|
||||
})
|
||||
.with_tooltip::<TitlebarParticipant>(
|
||||
peer_id.as_u64() as usize,
|
||||
format!("Follow {}", user.github_login),
|
||||
Some(Box::new(FollowNextCollaborator)),
|
||||
theme.tooltip.clone(),
|
||||
cx,
|
||||
)
|
||||
.into_any()
|
||||
}
|
||||
|
||||
fn location_style(
|
||||
|
|
|
@ -222,7 +222,7 @@ impl Member {
|
|||
|_, _| {
|
||||
Label::new(
|
||||
format!(
|
||||
"Follow {} on their active project",
|
||||
"Follow {} to their active project",
|
||||
leader_user.github_login,
|
||||
),
|
||||
theme
|
||||
|
|
|
@ -2529,6 +2529,7 @@ impl Workspace {
|
|||
|
||||
if let Some(prev_leader_id) = self.unfollow(&pane, cx) {
|
||||
if leader_id == prev_leader_id {
|
||||
dbg!("oh no!");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
@ -2613,16 +2614,50 @@ impl Workspace {
|
|||
leader_id: PeerId,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
let room = ActiveCall::global(cx).read(cx).room()?.read(cx);
|
||||
let project = self.project.read(cx);
|
||||
|
||||
let Some(remote_participant) = room.remote_participant_for_peer_id(leader_id) else {
|
||||
dbg!("no remote participant yet...");
|
||||
return None;
|
||||
};
|
||||
|
||||
let other_project_id = match remote_participant.location {
|
||||
call::ParticipantLocation::External => None,
|
||||
call::ParticipantLocation::UnsharedProject => None,
|
||||
call::ParticipantLocation::SharedProject { project_id } => {
|
||||
if Some(project_id) == project.remote_id() {
|
||||
None
|
||||
} else {
|
||||
Some(project_id)
|
||||
}
|
||||
}
|
||||
};
|
||||
dbg!(other_project_id);
|
||||
|
||||
// if they are active in another project, follow there.
|
||||
if let Some(project_id) = other_project_id {
|
||||
let app_state = self.app_state.clone();
|
||||
return Some(crate::join_remote_project(
|
||||
project_id,
|
||||
remote_participant.user.id,
|
||||
app_state,
|
||||
cx,
|
||||
));
|
||||
}
|
||||
|
||||
// if you're already following, find the right pane and focus it.
|
||||
for (existing_leader_id, states_by_pane) in &mut self.follower_states_by_leader {
|
||||
if leader_id == *existing_leader_id {
|
||||
for (pane, _) in states_by_pane {
|
||||
dbg!("focusing pane");
|
||||
cx.focus(pane);
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not currently following, so follow.
|
||||
// Otherwise, follow.
|
||||
self.toggle_follow(leader_id, cx)
|
||||
}
|
||||
|
||||
|
@ -4214,6 +4249,7 @@ pub fn join_remote_project(
|
|||
app_state: Arc<AppState>,
|
||||
cx: &mut AppContext,
|
||||
) -> Task<Result<()>> {
|
||||
dbg!("huh??");
|
||||
cx.spawn(|mut cx| async move {
|
||||
let existing_workspace = cx
|
||||
.windows()
|
||||
|
@ -4232,8 +4268,10 @@ pub fn join_remote_project(
|
|||
.flatten();
|
||||
|
||||
let workspace = if let Some(existing_workspace) = existing_workspace {
|
||||
dbg!("huh");
|
||||
existing_workspace
|
||||
} else {
|
||||
dbg!("huh/");
|
||||
let active_call = cx.read(ActiveCall::global);
|
||||
let room = active_call
|
||||
.read_with(&cx, |call, _| call.room().cloned())
|
||||
|
@ -4249,6 +4287,7 @@ pub fn join_remote_project(
|
|||
})
|
||||
.await?;
|
||||
|
||||
dbg!("huh//");
|
||||
let window_bounds_override = window_bounds_env_override(&cx);
|
||||
let window = cx.add_window(
|
||||
(app_state.build_window_options)(
|
||||
|
@ -4271,6 +4310,7 @@ pub fn join_remote_project(
|
|||
workspace.downgrade()
|
||||
};
|
||||
|
||||
dbg!("huh///");
|
||||
workspace.window().activate(&mut cx);
|
||||
cx.platform().activate(true);
|
||||
|
||||
|
@ -4293,12 +4333,12 @@ pub fn join_remote_project(
|
|||
Some(collaborator.peer_id)
|
||||
});
|
||||
|
||||
dbg!(follow_peer_id);
|
||||
|
||||
if let Some(follow_peer_id) = follow_peer_id {
|
||||
if !workspace.is_being_followed(follow_peer_id) {
|
||||
workspace
|
||||
.toggle_follow(follow_peer_id, cx)
|
||||
.map(|follow| follow.detach_and_log_err(cx));
|
||||
}
|
||||
workspace
|
||||
.follow(follow_peer_id, cx)
|
||||
.map(|follow| follow.detach_and_log_err(cx));
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
|
Loading…
Reference in a new issue