diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 7cc91d7e68ffcf5f73fdbe5661bcf5261cea0f7b..7dab90e75b6dab3d2b2aa6ac97347d3e8fab40e3 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -7012,8 +7012,7 @@ impl Workspace { view: Entity, cx: &mut Context, ) { - let focus_handle = view.focus_handle(cx); - self.left_drawer = Some(Drawer::new(view.into(), focus_handle)); + self.left_drawer = Some(Drawer::new(view)); cx.notify(); } @@ -7022,8 +7021,7 @@ impl Workspace { view: Entity, cx: &mut Context, ) { - let focus_handle = view.focus_handle(cx); - self.right_drawer = Some(Drawer::new(view.into(), focus_handle)); + self.right_drawer = Some(Drawer::new(view)); cx.notify(); } @@ -7282,8 +7280,9 @@ impl Workspace { } }; + let focus_handle = drawer.focus_handle(cx); let base = div() - .track_focus(&drawer.focus_handle) + .track_focus(&focus_handle) .flex() .flex_col() .overflow_hidden() @@ -7921,20 +7920,25 @@ pub enum DrawerPosition { pub struct Drawer { view: AnyView, - focus_handle: FocusHandle, + focus_handle_fn: Box FocusHandle>, open: bool, custom_width: Option, } impl Drawer { - fn new(view: AnyView, focus_handle: FocusHandle) -> Self { + fn new(view: Entity) -> Self { + let entity = view.clone(); Self { - view, - focus_handle, + view: view.into(), + focus_handle_fn: Box::new(move |cx| entity.focus_handle(cx)), open: true, custom_width: None, } } + + fn focus_handle(&self, cx: &App) -> FocusHandle { + (self.focus_handle_fn)(cx) + } } #[derive(Clone)]