diff --git a/crates/workspace2/src/dock.rs b/crates/workspace2/src/dock.rs index a0a90293d603a3afde61dda2c4ca59ec5fa273a1..7bae7bc4199631f0b538a99d45ecb6e1d7a4aaa5 100644 --- a/crates/workspace2/src/dock.rs +++ b/crates/workspace2/src/dock.rs @@ -133,13 +133,13 @@ pub struct Dock { panel_entries: Vec, is_open: bool, active_panel_index: usize, + focus_handle: FocusHandle, + focus_subscription: Subscription, } impl FocusableView for Dock { - fn focus_handle(&self, cx: &AppContext) -> FocusHandle { - self.panel_entries[self.active_panel_index] - .panel - .focus_handle(cx) + fn focus_handle(&self, _: &AppContext) -> FocusHandle { + self.focus_handle.clone() } } @@ -190,12 +190,20 @@ pub struct PanelButtons { } impl Dock { - pub fn new(position: DockPosition) -> Self { + pub fn new(position: DockPosition, cx: &mut ViewContext<'_, Self>) -> Self { + let focus_handle = cx.focus_handle(); + let focus_subscription = cx.on_focus(&focus_handle, |dock, cx| { + if let Some(active_entry) = dock.panel_entries.get(dock.active_panel_index) { + active_entry.panel.focus_handle(cx).focus(cx) + } + }); Self { position, panel_entries: Default::default(), active_panel_index: 0, is_open: false, + focus_handle, + focus_subscription, } } @@ -207,6 +215,7 @@ impl Dock { self.is_open } + // todo!() // pub fn has_focus(&self, cx: &WindowContext) -> bool { // self.visible_panel() // .map_or(false, |panel| panel.has_focus(cx)) diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index abf908992978ff8e870eb88efe72f7ce0e332c41..50eb69eec5b857b25cf199e8e6b142b73d4bc0a0 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -566,9 +566,9 @@ impl Workspace { cx.emit(Event::WorkspaceCreated(weak_handle.clone())); - let left_dock = cx.build_view(|_| Dock::new(DockPosition::Left)); - let bottom_dock = cx.build_view(|_| Dock::new(DockPosition::Bottom)); - let right_dock = cx.build_view(|_| Dock::new(DockPosition::Right)); + let left_dock = cx.build_view(|cx| Dock::new(DockPosition::Left, cx)); + let bottom_dock = cx.build_view(|cx| Dock::new(DockPosition::Bottom, cx)); + let right_dock = cx.build_view(|cx| Dock::new(DockPosition::Right, cx)); let left_dock_buttons = cx.build_view(|cx| PanelButtons::new(left_dock.clone(), weak_handle.clone(), cx)); let bottom_dock_buttons =