Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send pane removeItem event before removing the item #15541

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/assistant/src/assistant_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ impl AssistantPanel {
true
}

pane::Event::RemoveItem { .. } => {
pane::Event::RemovedItem { .. } => {
cx.emit(AssistantPanelEvent::ContextEdited);
true
}
Expand Down
2 changes: 1 addition & 1 deletion crates/tab_switcher/src/tab_switcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/terminal_view/src/terminal_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
12 changes: 8 additions & 4 deletions crates/workspace/src/pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ pub enum Event {
AddItem { item: Box<dyn ItemHandle> },
ActivateItem { local: bool },
Remove,
RemoveItem { item_id: EntityId },
RemoveItem { idx: usize },
RemovedItem { item_id: EntityId },
Split(SplitDirection),
ChangeItemTitle,
Focus,
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading