debugger: More focus tweaks (#31232)

Cole Miller created

- Make remembering focus work with `ActivatePaneDown` as well
- Tone down the console's focus-in behavior so clicking doesn't
misbehave

Release Notes:

- N/A

Change summary

crates/debugger_ui/src/debugger_panel.rs          | 19 +++++++++++-----
crates/debugger_ui/src/debugger_ui.rs             | 11 --------
crates/debugger_ui/src/session/running.rs         | 17 ++++++++-------
crates/debugger_ui/src/session/running/console.rs |  2 
4 files changed, 24 insertions(+), 25 deletions(-)

Detailed changes

crates/debugger_ui/src/debugger_panel.rs 🔗

@@ -68,12 +68,13 @@ pub struct DebugPanel {
     pub(crate) thread_picker_menu_handle: PopoverMenuHandle<ContextMenu>,
     pub(crate) session_picker_menu_handle: PopoverMenuHandle<ContextMenu>,
     fs: Arc<dyn Fs>,
+    _subscriptions: [Subscription; 1],
 }
 
 impl DebugPanel {
     pub fn new(
         workspace: &Workspace,
-        _window: &mut Window,
+        window: &mut Window,
         cx: &mut Context<Workspace>,
     ) -> Entity<Self> {
         cx.new(|cx| {
@@ -82,6 +83,14 @@ impl DebugPanel {
             let thread_picker_menu_handle = PopoverMenuHandle::default();
             let session_picker_menu_handle = PopoverMenuHandle::default();
 
+            let focus_subscription = cx.on_focus(
+                &focus_handle,
+                window,
+                |this: &mut DebugPanel, window, cx| {
+                    this.focus_active_item(window, cx);
+                },
+            );
+
             Self {
                 size: px(300.),
                 sessions: vec![],
@@ -93,6 +102,7 @@ impl DebugPanel {
                 fs: workspace.app_state().fs.clone(),
                 thread_picker_menu_handle,
                 session_picker_menu_handle,
+                _subscriptions: [focus_subscription],
             }
         })
     }
@@ -101,15 +111,12 @@ impl DebugPanel {
         let Some(session) = self.active_session.clone() else {
             return;
         };
-        let Some(active_pane) = session
+        let active_pane = session
             .read(cx)
             .running_state()
             .read(cx)
             .active_pane()
-            .cloned()
-        else {
-            return;
-        };
+            .clone();
         active_pane.update(cx, |pane, cx| {
             pane.focus_active_item(window, cx);
         });

crates/debugger_ui/src/debugger_ui.rs 🔗

@@ -62,16 +62,7 @@ pub fn init(cx: &mut App) {
         cx.when_flag_enabled::<DebuggerFeatureFlag>(window, |workspace, _, _| {
             workspace
                 .register_action(|workspace, _: &ToggleFocus, window, cx| {
-                    let did_focus_panel = workspace.toggle_panel_focus::<DebugPanel>(window, cx);
-                    if !did_focus_panel {
-                        return;
-                    };
-                    let Some(panel) = workspace.panel::<DebugPanel>(cx) else {
-                        return;
-                    };
-                    panel.update(cx, |panel, cx| {
-                        panel.focus_active_item(window, cx);
-                    })
+                    workspace.toggle_panel_focus::<DebugPanel>(window, cx);
                 })
                 .register_action(|workspace, _: &Pause, _, cx| {
                     if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {

crates/debugger_ui/src/session/running.rs 🔗

@@ -74,7 +74,7 @@ pub struct RunningState {
     console: Entity<Console>,
     breakpoint_list: Entity<BreakpointList>,
     panes: PaneGroup,
-    active_pane: Option<Entity<Pane>>,
+    active_pane: Entity<Pane>,
     pane_close_subscriptions: HashMap<EntityId, Subscription>,
     dock_axis: Axis,
     _schedule_serialize: Option<Task<()>>,
@@ -85,8 +85,8 @@ impl RunningState {
         self.thread_id
     }
 
-    pub(crate) fn active_pane(&self) -> Option<&Entity<Pane>> {
-        self.active_pane.as_ref()
+    pub(crate) fn active_pane(&self) -> &Entity<Pane> {
+        &self.active_pane
     }
 }
 
@@ -703,6 +703,7 @@ impl RunningState {
 
             workspace::PaneGroup::with_root(root)
         };
+        let active_pane = panes.first_pane();
 
         Self {
             session,
@@ -715,7 +716,7 @@ impl RunningState {
             stack_frame_list,
             session_id,
             panes,
-            active_pane: None,
+            active_pane,
             module_list,
             console,
             breakpoint_list,
@@ -1230,7 +1231,7 @@ impl RunningState {
                 cx.notify();
             }
             Event::Focus => {
-                this.active_pane = Some(source_pane.clone());
+                this.active_pane = source_pane.clone();
             }
             Event::ZoomIn => {
                 source_pane.update(cx, |pane, cx| {
@@ -1254,10 +1255,10 @@ impl RunningState {
         window: &mut Window,
         cx: &mut Context<Self>,
     ) {
+        let active_pane = self.active_pane.clone();
         if let Some(pane) = self
-            .active_pane
-            .as_ref()
-            .and_then(|pane| self.panes.find_pane_in_direction(pane, direction, cx))
+            .panes
+            .find_pane_in_direction(&active_pane, direction, cx)
         {
             pane.update(cx, |pane, cx| {
                 pane.focus_active_item(window, cx);

crates/debugger_ui/src/session/running/console.rs 🔗

@@ -84,7 +84,7 @@ impl Console {
                     this.update_output(window, cx)
                 }
             }),
-            cx.on_focus_in(&focus_handle, window, |console, window, cx| {
+            cx.on_focus(&focus_handle, window, |console, window, cx| {
                 if console.is_running(cx) {
                     console.query_bar.focus_handle(cx).focus(window);
                 }