diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 7afc79f8b3..d0457eba5a 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -158,6 +158,10 @@ impl FollowableItem for Editor { } Ok(()) } + + fn should_unfollow_on_event(event: &Self::Event, cx: &AppContext) -> bool { + false + } } fn serialize_selection(selection: &Selection) -> proto::Selection { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 387bfa9b6e..5ce61824e3 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -270,6 +270,7 @@ pub trait FollowableItem: Item { message: proto::update_view::Variant, cx: &mut ViewContext, ) -> Result<()>; + fn should_unfollow_on_event(event: &Self::Event, cx: &AppContext) -> bool; } pub trait FollowableItemHandle: ItemHandle { @@ -285,6 +286,7 @@ pub trait FollowableItemHandle: ItemHandle { message: proto::update_view::Variant, cx: &mut MutableAppContext, ) -> Result<()>; + fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool; } impl FollowableItemHandle for ViewHandle { @@ -313,6 +315,14 @@ impl FollowableItemHandle for ViewHandle { ) -> Result<()> { self.update(cx, |this, cx| this.apply_update_message(message, cx)) } + + fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool { + if let Some(event) = event.downcast_ref() { + T::should_unfollow_on_event(event, cx) + } else { + false + } + } } pub trait ItemHandle: 'static + fmt::Debug { @@ -421,6 +431,12 @@ impl ItemHandle for ViewHandle { return; }; + if let Some(item) = item.to_followable_item_handle(cx) { + if item.should_unfollow_on_event(event, cx) { + workspace.unfollow(&pane, cx); + } + } + if T::should_close_item_on_event(event) { pane.update(cx, |pane, cx| pane.close_item(item.id(), cx)); return;