Skip to content

Commit 40a611b

Browse files
authored
tab_switcher: Subscribe to workspace events instead of pane events (#44101)
Closes #43171 Previously the tab switcher only subscribed to events from a single pane so closing tabs in other panes wouldn't cause the tab switcher to update. This PR changes that so the tab switcher subscribes to the whole workspace and thus updates when tabs in other panes are closed. It also modifies the work in #44006 to sync selected index across the whole workspace instead of just the original pane in the case of the all-panes tab switcher. Release Notes: - Fixed all-panes tab switcher not updating in response to changes in other panes
1 parent 8ad3a15 commit 40a611b

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

crates/tab_switcher/src/tab_switcher.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use ui::{
2323
};
2424
use util::ResultExt;
2525
use workspace::{
26-
ModalView, Pane, SaveIntent, Workspace,
26+
Event as WorkspaceEvent, ModalView, Pane, SaveIntent, Workspace,
2727
item::{ItemHandle, ItemSettings, ShowDiagnostics, TabContentParams},
28-
pane::{Event as PaneEvent, render_item_indicator, tab_details},
28+
pane::{render_item_indicator, tab_details},
2929
};
3030

3131
const PANEL_WIDTH_REMS: f32 = 28.;
@@ -322,7 +322,7 @@ impl TabSwitcherDelegate {
322322
cx: &mut Context<TabSwitcher>,
323323
original_items: Vec<(Entity<Pane>, usize)>,
324324
) -> Self {
325-
Self::subscribe_to_updates(&pane, window, cx);
325+
Self::subscribe_to_updates(&workspace, window, cx);
326326
Self {
327327
select_last,
328328
tab_switcher,
@@ -338,34 +338,36 @@ impl TabSwitcherDelegate {
338338
}
339339

340340
fn subscribe_to_updates(
341-
pane: &WeakEntity<Pane>,
341+
workspace: &WeakEntity<Workspace>,
342342
window: &mut Window,
343343
cx: &mut Context<TabSwitcher>,
344344
) {
345-
let Some(pane) = pane.upgrade() else {
345+
let Some(workspace) = workspace.upgrade() else {
346346
return;
347347
};
348-
cx.subscribe_in(&pane, window, |tab_switcher, _, event, window, cx| {
348+
cx.subscribe_in(&workspace, window, |tab_switcher, _, event, window, cx| {
349349
match event {
350-
PaneEvent::AddItem { .. } | PaneEvent::Remove { .. } => {
350+
WorkspaceEvent::ItemAdded { .. } | WorkspaceEvent::PaneRemoved => {
351351
tab_switcher.picker.update(cx, |picker, cx| {
352352
let query = picker.query(cx);
353353
picker.delegate.update_matches(query, window, cx);
354354
cx.notify();
355355
})
356356
}
357-
PaneEvent::RemovedItem { .. } => tab_switcher.picker.update(cx, |picker, cx| {
358-
let query = picker.query(cx);
359-
picker.delegate.update_matches(query, window, cx);
360-
361-
// When the Tab Switcher is being used and an item is
362-
// removed, there's a chance that the new selected index
363-
// will not match the actual tab that is now being displayed
364-
// by the pane, as such, the selected index needs to be
365-
// updated to match the pane's state.
366-
picker.delegate.sync_selected_index(cx);
367-
cx.notify();
368-
}),
357+
WorkspaceEvent::ItemRemoved { .. } => {
358+
tab_switcher.picker.update(cx, |picker, cx| {
359+
let query = picker.query(cx);
360+
picker.delegate.update_matches(query, window, cx);
361+
362+
// When the Tab Switcher is being used and an item is
363+
// removed, there's a chance that the new selected index
364+
// will not match the actual tab that is now being displayed
365+
// by the pane, as such, the selected index needs to be
366+
// updated to match the pane's state.
367+
picker.delegate.sync_selected_index(cx);
368+
cx.notify();
369+
})
370+
}
369371
_ => {}
370372
};
371373
})
@@ -563,7 +565,14 @@ impl TabSwitcherDelegate {
563565
/// as the pane's active item can be indirectly updated and this method
564566
/// ensures that the picker can react to those changes.
565567
fn sync_selected_index(&mut self, cx: &mut Context<Picker<TabSwitcherDelegate>>) {
566-
let Ok(Some(item)) = self.pane.read_with(cx, |pane, _cx| pane.active_item()) else {
568+
let item = if self.is_all_panes {
569+
self.workspace
570+
.read_with(cx, |workspace, cx| workspace.active_item(cx))
571+
} else {
572+
self.pane.read_with(cx, |pane, _cx| pane.active_item())
573+
};
574+
575+
let Ok(Some(item)) = item else {
567576
return;
568577
};
569578

0 commit comments

Comments
 (0)