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
This commit is contained in:
Cole Miller 2025-05-23 07:51:23 -04:00 committed by GitHub
parent 26318b5b6a
commit c4677c21a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 25 deletions

View file

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

View file

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

View file

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

View file

@ -84,7 +84,7 @@ impl Console {
this.update_output(window, cx) 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) { if console.is_running(cx) {
console.query_bar.focus_handle(cx).focus(window); console.query_bar.focus_handle(cx).focus(window);
} }