From 3c404dec9282d5976a292e7201a3313ba171165a Mon Sep 17 00:00:00 2001 From: Remco Smits Date: Wed, 31 Jul 2024 17:48:19 +0200 Subject: [PATCH] Send pane `removeItem` event before removing the item (#15541) This PR renames and added a new pane event to indicate the difference between `removing` and `removed` event. This change is needed for the debugger implementation, if you close a pane we have to send a `terminateThread` request to the adapter because it's not supported to reopen a pane. So when the pane is removing we have to know what thread it is what is stored on the panel itself, so we have to be able to get this information before the pane is actually removed. So my idea how to fix this was by adding a new event called `RemovedItem` which is a rename of `RemoveItem` which also makes a bit more sense because the item is removed at that point. And seeing the name `RemoveItem` does not really say that it's removed, more like we are removing the item. /cc @mikayla-maki Release Notes: - N/A --- crates/assistant/src/assistant_panel.rs | 2 +- crates/tab_switcher/src/tab_switcher.rs | 2 +- crates/terminal_view/src/terminal_panel.rs | 2 +- crates/workspace/src/pane.rs | 12 ++++++++---- crates/workspace/src/workspace.rs | 3 ++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index dcefcf94953c47c4f97f6c8d02e7a45cc3c74af2..e77647b667549c98128a18bda0a732ac577e96e7 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -465,7 +465,7 @@ impl AssistantPanel { true } - pane::Event::RemoveItem { .. } => { + pane::Event::RemovedItem { .. } => { cx.emit(AssistantPanelEvent::ContextEdited); true } diff --git a/crates/tab_switcher/src/tab_switcher.rs b/crates/tab_switcher/src/tab_switcher.rs index 9572a9ec37294fc86e0189dea3221c54c5bbca5f..fe8227f661bd0544d20e68810a7e2f2e3a773299 100644 --- a/crates/tab_switcher/src/tab_switcher.rs +++ b/crates/tab_switcher/src/tab_switcher.rs @@ -173,7 +173,7 @@ impl TabSwitcherDelegate { }; cx.subscribe(&pane, |tab_switcher, _, event, cx| { match event { - PaneEvent::AddItem { .. } | PaneEvent::RemoveItem { .. } | PaneEvent::Remove => { + PaneEvent::AddItem { .. } | PaneEvent::RemovedItem { .. } | PaneEvent::Remove => { tab_switcher.picker.update(cx, |picker, cx| { let selected_item_id = picker.delegate.selected_item_id(); picker.delegate.update_matches(cx); diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index 2b9e68e75fb27474f4f75c29a0f51865e6cc769f..ee9a0ae246d3faa4b4262ce5752efff36d716c3f 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -342,7 +342,7 @@ impl TerminalPanel { ) { match event { pane::Event::ActivateItem { .. } => self.serialize(cx), - pane::Event::RemoveItem { .. } => self.serialize(cx), + pane::Event::RemovedItem { .. } => self.serialize(cx), pane::Event::Remove => cx.emit(PanelEvent::Close), pane::Event::ZoomIn => cx.emit(PanelEvent::ZoomIn), pane::Event::ZoomOut => cx.emit(PanelEvent::ZoomOut), diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 3bc781e19966803d1a5026ea8aab56f745678646..0550e937e94b14e73b942e9eb50c876a8d6d6731 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -169,7 +169,8 @@ pub enum Event { AddItem { item: Box }, ActivateItem { local: bool }, Remove, - RemoveItem { item_id: EntityId }, + RemoveItem { idx: usize }, + RemovedItem { item_id: EntityId }, Split(SplitDirection), ChangeItemTitle, Focus, @@ -189,8 +190,9 @@ impl fmt::Debug for Event { .field("local", local) .finish(), Event::Remove => f.write_str("Remove"), - Event::RemoveItem { item_id } => f - .debug_struct("RemoveItem") + Event::RemoveItem { idx } => f.debug_struct("RemoveItem").field("idx", idx).finish(), + Event::RemovedItem { item_id } => f + .debug_struct("RemovedItem") .field("item_id", item_id) .finish(), Event::Split(direction) => f @@ -1302,9 +1304,11 @@ impl Pane { } } + cx.emit(Event::RemoveItem { idx: item_index }); + let item = self.items.remove(item_index); - cx.emit(Event::RemoveItem { + cx.emit(Event::RemovedItem { item_id: item.item_id(), }); if self.items.is_empty() { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 1ca28269b4993696b5ba66bc0bf70e9ae801ea69..db1224987184fe3b6dbd95b28e084ed18d1cf478 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2903,7 +2903,8 @@ impl Workspace { } self.update_window_edited(cx); } - pane::Event::RemoveItem { item_id } => { + pane::Event::RemoveItem { .. } => {} + pane::Event::RemovedItem { item_id } => { cx.emit(Event::ActiveItemChanged); self.update_window_edited(cx); if let hash_map::Entry::Occupied(entry) = self.panes_by_item.entry(*item_id) {