diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 5ef739510b6047d212ffe04127a8a945648eeb5b..d4163ce353eda5d54afac069d86dc833de9f4d61 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -50,21 +50,15 @@ impl FollowableItem for Editor { })) } - fn to_state_message(&self, cx: &AppContext) -> proto::view::Variant { - let buffer_id = self - .buffer - .read(cx) - .as_singleton() - .unwrap() - .read(cx) - .remote_id(); - proto::view::Variant::Editor(proto::view::Editor { + fn to_state_message(&self, cx: &AppContext) -> Option { + let buffer_id = self.buffer.read(cx).as_singleton()?.read(cx).remote_id(); + Some(proto::view::Variant::Editor(proto::view::Editor { buffer_id, scroll_top: self .scroll_top_anchor .as_ref() .map(|anchor| language::proto::serialize_anchor(&anchor.text_anchor)), - }) + })) } fn to_update_message( diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 386eba66eb76290b70a53299eb32834faaff7248..2e84f6c55cb2b5b42f2439257545c55231f4f203 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -247,7 +247,7 @@ pub trait FollowableItem: Item { state: &mut Option, cx: &mut MutableAppContext, ) -> Option>>>; - fn to_state_message(&self, cx: &AppContext) -> proto::view::Variant; + fn to_state_message(&self, cx: &AppContext) -> Option; fn to_update_message( &self, event: &Self::Event, @@ -261,7 +261,7 @@ pub trait FollowableItem: Item { } pub trait FollowableItemHandle: ItemHandle { - fn to_state_message(&self, cx: &AppContext) -> proto::view::Variant; + fn to_state_message(&self, cx: &AppContext) -> Option; fn to_update_message( &self, event: &dyn Any, @@ -275,7 +275,7 @@ pub trait FollowableItemHandle: ItemHandle { } impl FollowableItemHandle for ViewHandle { - fn to_state_message(&self, cx: &AppContext) -> proto::view::Variant { + fn to_state_message(&self, cx: &AppContext) -> Option { self.read(cx).to_state_message(cx) } @@ -381,13 +381,15 @@ impl ItemHandle for ViewHandle { cx: &mut ViewContext, ) { if let Some(followed_item) = self.to_followable_item_handle(cx) { - workspace.update_followers( - proto::update_followers::Variant::CreateView(proto::View { - id: followed_item.id() as u64, - variant: Some(followed_item.to_state_message(cx)), - }), - cx, - ); + if let Some(message) = followed_item.to_state_message(cx) { + workspace.update_followers( + proto::update_followers::Variant::CreateView(proto::View { + id: followed_item.id() as u64, + variant: Some(message), + }), + cx, + ); + } } let pane = pane.downgrade(); @@ -1523,7 +1525,7 @@ impl Workspace { .filter_map(|item| { let id = item.id() as u64; let item = item.to_followable_item_handle(cx)?; - let variant = item.to_state_message(cx); + let variant = item.to_state_message(cx)?; Some(proto::View { id, variant: Some(variant),