mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-26 20:22:30 +00:00
Replicate editor state when following into channel notes
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
24141c2f16
commit
90f22cb0d2
2 changed files with 46 additions and 12 deletions
|
@ -168,6 +168,13 @@ impl FollowableItem for ChannelView {
|
||||||
self.channel_buffer.read(cx).channel(cx).map(|channel| {
|
self.channel_buffer.read(cx).channel(cx).map(|channel| {
|
||||||
proto::view::Variant::ChannelView(proto::view::ChannelView {
|
proto::view::Variant::ChannelView(proto::view::ChannelView {
|
||||||
channel_id: channel.id,
|
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::Pane>,
|
_: ViewHandle<workspace::Pane>,
|
||||||
workspace: ViewHandle<workspace::Workspace>,
|
workspace: ViewHandle<workspace::Workspace>,
|
||||||
remote_id: workspace::ViewId,
|
remote_id: workspace::ViewId,
|
||||||
state_proto: &mut Option<proto::view::Variant>,
|
state: &mut Option<proto::view::Variant>,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
) -> Option<gpui::Task<anyhow::Result<ViewHandle<Self>>>> {
|
) -> Option<gpui::Task<anyhow::Result<ViewHandle<Self>>>> {
|
||||||
let Some(proto::view::Variant::ChannelView(_)) = state_proto else { return None };
|
let Some(proto::view::Variant::ChannelView(_)) = state else { return None };
|
||||||
let Some(proto::view::Variant::ChannelView(state)) = state_proto.take() else { unreachable!() };
|
let Some(proto::view::Variant::ChannelView(state)) = state.take() else { unreachable!() };
|
||||||
|
|
||||||
let channel_store = &workspace.read(cx).app_state().channel_store.clone();
|
let channel_store = &workspace.read(cx).app_state().channel_store.clone();
|
||||||
let open_channel_buffer = channel_store.update(cx, |store, cx| {
|
let open_channel_buffer = channel_store.update(cx, |store, cx| {
|
||||||
|
@ -202,7 +209,29 @@ impl FollowableItem for ChannelView {
|
||||||
this
|
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)
|
Ok(this)
|
||||||
}))
|
}))
|
||||||
|
@ -210,20 +239,24 @@ impl FollowableItem for ChannelView {
|
||||||
|
|
||||||
fn add_event_to_update_proto(
|
fn add_event_to_update_proto(
|
||||||
&self,
|
&self,
|
||||||
_: &Self::Event,
|
event: &Self::Event,
|
||||||
_: &mut Option<proto::update_view::Variant>,
|
update: &mut Option<proto::update_view::Variant>,
|
||||||
_: &AppContext,
|
cx: &AppContext,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
false
|
self.editor
|
||||||
|
.read(cx)
|
||||||
|
.add_event_to_update_proto(event, update, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_update_proto(
|
fn apply_update_proto(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: &ModelHandle<Project>,
|
project: &ModelHandle<Project>,
|
||||||
_: proto::update_view::Variant,
|
message: proto::update_view::Variant,
|
||||||
_: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> gpui::Task<anyhow::Result<()>> {
|
) -> gpui::Task<anyhow::Result<()>> {
|
||||||
gpui::Task::ready(Ok(()))
|
self.editor.update(cx, |editor, cx| {
|
||||||
|
editor.apply_update_proto(project, message, cx)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_leader_replica_id(
|
fn set_leader_replica_id(
|
||||||
|
|
|
@ -1136,6 +1136,7 @@ message View {
|
||||||
|
|
||||||
message ChannelView {
|
message ChannelView {
|
||||||
uint64 channel_id = 1;
|
uint64 channel_id = 1;
|
||||||
|
Editor editor = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue