From 4eb75f058f44b3d0cc8fd569cacd761d259ef82e Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 9 Mar 2023 12:00:58 -0800 Subject: [PATCH] Fix bug with wrong view ids being passed --- crates/workspace/src/dock.rs | 3 ++- crates/workspace/src/workspace.rs | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index fd7638c5fb..f5ee8cad51 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -181,6 +181,7 @@ pub struct Dock { impl Dock { pub fn new( + workspace_id: usize, default_item_factory: DockDefaultItemFactory, background_actions: BackgroundActions, cx: &mut ViewContext, @@ -189,7 +190,7 @@ impl Dock { let pane = cx.add_view(|cx| { Pane::new( - cx.handle().id(), + workspace_id, Some(position.anchor()), background_actions, cx, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index ef14bfa2fe..b4b164ec3f 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -606,9 +606,10 @@ impl Workspace { }) .detach(); - let workspace_view_id = cx.handle().id(); + let weak_handle = cx.weak_handle(); + let center_pane = - cx.add_view(|cx| Pane::new(workspace_view_id, None, background_actions, cx)); + cx.add_view(|cx| Pane::new(weak_handle.id(), None, background_actions, cx)); let pane_id = center_pane.id(); cx.subscribe(¢er_pane, move |this, _, event, cx| { this.handle_pane_event(pane_id, event, cx) @@ -616,7 +617,12 @@ impl Workspace { .detach(); cx.focus(¢er_pane); cx.emit(Event::PaneAdded(center_pane.clone())); - let dock = Dock::new(dock_default_factory, background_actions, cx); + let dock = Dock::new( + weak_handle.id(), + dock_default_factory, + background_actions, + cx, + ); let dock_pane = dock.pane().clone(); let fs = project.read(cx).fs().clone(); @@ -639,7 +645,6 @@ impl Workspace { } }); let handle = cx.handle(); - let weak_handle = cx.weak_handle(); // All leader updates are enqueued and then processed in a single task, so // that each asynchronous operation can be run in order. @@ -1440,7 +1445,14 @@ impl Workspace { } fn add_pane(&mut self, cx: &mut ViewContext) -> ViewHandle { - let pane = cx.add_view(|cx| Pane::new(cx.handle().id(), None, self.background_actions, cx)); + let pane = cx.add_view(|cx| { + Pane::new( + dbg!(self.weak_handle().id()), + None, + self.background_actions, + cx, + ) + }); let pane_id = pane.id(); cx.subscribe(&pane, move |this, _, event, cx| { this.handle_pane_event(pane_id, event, cx)