From c4677c21a97fcec4af971b9f9e13a43efac6b10f Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Fri, 23 May 2025 07:51:23 -0400 Subject: [PATCH] debugger: More focus tweaks (#31232) - 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 --- crates/debugger_ui/src/debugger_panel.rs | 19 +++++++++++++------ crates/debugger_ui/src/debugger_ui.rs | 11 +---------- crates/debugger_ui/src/session/running.rs | 17 +++++++++-------- .../src/session/running/console.rs | 2 +- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/crates/debugger_ui/src/debugger_panel.rs b/crates/debugger_ui/src/debugger_panel.rs index 1597bf294d..079d91f182 100644 --- a/crates/debugger_ui/src/debugger_panel.rs +++ b/crates/debugger_ui/src/debugger_panel.rs @@ -68,12 +68,13 @@ pub struct DebugPanel { pub(crate) thread_picker_menu_handle: PopoverMenuHandle, pub(crate) session_picker_menu_handle: PopoverMenuHandle, fs: Arc, + _subscriptions: [Subscription; 1], } impl DebugPanel { pub fn new( workspace: &Workspace, - _window: &mut Window, + window: &mut Window, cx: &mut Context, ) -> Entity { 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); }); diff --git a/crates/debugger_ui/src/debugger_ui.rs b/crates/debugger_ui/src/debugger_ui.rs index 528a687af7..980f0bce4f 100644 --- a/crates/debugger_ui/src/debugger_ui.rs +++ b/crates/debugger_ui/src/debugger_ui.rs @@ -62,16 +62,7 @@ pub fn init(cx: &mut App) { cx.when_flag_enabled::(window, |workspace, _, _| { workspace .register_action(|workspace, _: &ToggleFocus, window, cx| { - let did_focus_panel = workspace.toggle_panel_focus::(window, cx); - if !did_focus_panel { - return; - }; - let Some(panel) = workspace.panel::(cx) else { - return; - }; - panel.update(cx, |panel, cx| { - panel.focus_active_item(window, cx); - }) + workspace.toggle_panel_focus::(window, cx); }) .register_action(|workspace, _: &Pause, _, cx| { if let Some(debug_panel) = workspace.panel::(cx) { diff --git a/crates/debugger_ui/src/session/running.rs b/crates/debugger_ui/src/session/running.rs index 2a2bb942b4..ea530f3c59 100644 --- a/crates/debugger_ui/src/session/running.rs +++ b/crates/debugger_ui/src/session/running.rs @@ -74,7 +74,7 @@ pub struct RunningState { console: Entity, breakpoint_list: Entity, panes: PaneGroup, - active_pane: Option>, + active_pane: Entity, pane_close_subscriptions: HashMap, dock_axis: Axis, _schedule_serialize: Option>, @@ -85,8 +85,8 @@ impl RunningState { self.thread_id } - pub(crate) fn active_pane(&self) -> Option<&Entity> { - self.active_pane.as_ref() + pub(crate) fn active_pane(&self) -> &Entity { + &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, ) { + 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); diff --git a/crates/debugger_ui/src/session/running/console.rs b/crates/debugger_ui/src/session/running/console.rs index d12b88af04..73a399d78c 100644 --- a/crates/debugger_ui/src/session/running/console.rs +++ b/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); }