From 90f22cb0d24abb5d73dc6801990e5ce741e6a18d Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 24 Aug 2023 12:36:01 -0700 Subject: [PATCH] Replicate editor state when following into channel notes Co-authored-by: Mikayla --- crates/collab_ui/src/channel_view.rs | 57 ++++++++++++++++++++++------ crates/rpc/proto/zed.proto | 1 + 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/crates/collab_ui/src/channel_view.rs b/crates/collab_ui/src/channel_view.rs index dd3969d351..be186fc2e2 100644 --- a/crates/collab_ui/src/channel_view.rs +++ b/crates/collab_ui/src/channel_view.rs @@ -168,6 +168,13 @@ impl FollowableItem for ChannelView { self.channel_buffer.read(cx).channel(cx).map(|channel| { proto::view::Variant::ChannelView(proto::view::ChannelView { channel_id: channel.id, + editor: if let Some(proto::view::Variant::Editor(proto)) = + self.editor.read(cx).to_state_proto(cx) + { + Some(proto) + } else { + None + }, }) }) } @@ -176,11 +183,11 @@ impl FollowableItem for ChannelView { _: ViewHandle, workspace: ViewHandle, remote_id: workspace::ViewId, - state_proto: &mut Option, + state: &mut Option, cx: &mut AppContext, ) -> Option>>> { - let Some(proto::view::Variant::ChannelView(_)) = state_proto else { return None }; - let Some(proto::view::Variant::ChannelView(state)) = state_proto.take() else { unreachable!() }; + let Some(proto::view::Variant::ChannelView(_)) = state else { return None }; + let Some(proto::view::Variant::ChannelView(state)) = state.take() else { unreachable!() }; let channel_store = &workspace.read(cx).app_state().channel_store.clone(); let open_channel_buffer = channel_store.update(cx, |store, cx| { @@ -202,7 +209,29 @@ impl FollowableItem for ChannelView { this }) }) - .ok_or_else(|| anyhow::anyhow!("workspace droppped"))?; + .ok_or_else(|| anyhow::anyhow!("workspace dropped"))?; + + if let Some(state) = state.editor { + let task = this.update(&mut cx, |this, cx| { + this.editor.update(cx, |editor, cx| { + editor.apply_update_proto( + &this.project, + proto::update_view::Variant::Editor(proto::update_view::Editor { + selections: state.selections, + pending_selection: state.pending_selection, + scroll_top_anchor: state.scroll_top_anchor, + scroll_x: state.scroll_x, + scroll_y: state.scroll_y, + ..Default::default() + }), + cx, + ) + }) + }); + if let Some(task) = task { + task.await?; + } + } Ok(this) })) @@ -210,20 +239,24 @@ impl FollowableItem for ChannelView { fn add_event_to_update_proto( &self, - _: &Self::Event, - _: &mut Option, - _: &AppContext, + event: &Self::Event, + update: &mut Option, + cx: &AppContext, ) -> bool { - false + self.editor + .read(cx) + .add_event_to_update_proto(event, update, cx) } fn apply_update_proto( &mut self, - _: &ModelHandle, - _: proto::update_view::Variant, - _: &mut ViewContext, + project: &ModelHandle, + message: proto::update_view::Variant, + cx: &mut ViewContext, ) -> gpui::Task> { - gpui::Task::ready(Ok(())) + self.editor.update(cx, |editor, cx| { + editor.apply_update_proto(project, message, cx) + }) } fn set_leader_replica_id( diff --git a/crates/rpc/proto/zed.proto b/crates/rpc/proto/zed.proto index 827468b280..f032ccce51 100644 --- a/crates/rpc/proto/zed.proto +++ b/crates/rpc/proto/zed.proto @@ -1136,6 +1136,7 @@ message View { message ChannelView { uint64 channel_id = 1; + Editor editor = 2; } }