From 0a20eab6e972b2b000d3cd2e941459303212c7f8 Mon Sep 17 00:00:00 2001 From: John Costa Date: Wed, 18 Nov 2026 11:47:15 -0800 Subject: [PATCH 1/2] resizable: Expose whether a handle is being dragged Add `ResizableState::is_resizing`, which reports whether one of the group's resize handles is being dragged. `ResizablePanelEvent::Resized` only arrives once a drag ends, so render code had no way to tell that a drag is in progress. Closes #4037 --- crates/base/src/resizable/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/base/src/resizable/mod.rs b/crates/base/src/resizable/mod.rs index edc21d8365..114b4b0d54 100644 --- a/crates/base/src/resizable/mod.rs +++ b/crates/base/src/resizable/mod.rs @@ -59,6 +59,11 @@ impl ResizableState { &self.sizes } + /// Whether a resize handle is being dragged. + pub fn is_resizing(&self) -> bool { + self.resizing_panel_ix.is_some() + } + /// Programmatically resize the panel at `ix` to `size`, redistributing /// space among siblings using the same logic as a drag. /// @@ -850,6 +855,7 @@ mod tests { fn dragging_the_handle_resizes_and_emits_once(cx: &mut TestAppContext) { let (cx, state, resizes) = harness(cx); let boundary = cx.debug_bounds("second-panel").unwrap().left(); + assert!(!state.read_with(cx, |state, _| state.is_resizing())); cx.simulate_mouse_down( point(boundary - px(2.), px(50.)), @@ -866,6 +872,7 @@ mod tests { Some(MouseButton::Left), Modifiers::default(), ); + assert!(state.read_with(cx, |state, _| state.is_resizing())); cx.simulate_mouse_up( point(px(220.), px(50.)), MouseButton::Left, @@ -874,6 +881,7 @@ mod tests { state.read_with(cx, |state, _| { assert_eq!(state.sizes(), &vec![px(220.), px(180.)]); + assert!(!state.is_resizing()); }); assert_eq!(resizes.get(), 1); } From ed31dc88890b8a3c8c7cddcf7f09c83a64cf591b Mon Sep 17 00:00:00 2001 From: John Costa Date: Wed, 18 Nov 2026 16:33:10 -0800 Subject: [PATCH 2/2] resizable: Reset is_resizing when the drag is cleared or cancelled clear() now resets the flag, and a drag stopped with stop_active_drag is ended on the next frame, as a mouse up would, so is_resizing() cannot stay true after the drag ends. --- crates/base/src/resizable/mod.rs | 61 ++++++++++++++++++++++++++++++ crates/base/src/resizable/panel.rs | 21 +++++++++- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/crates/base/src/resizable/mod.rs b/crates/base/src/resizable/mod.rs index 114b4b0d54..06cb20536e 100644 --- a/crates/base/src/resizable/mod.rs +++ b/crates/base/src/resizable/mod.rs @@ -60,6 +60,9 @@ impl ResizableState { } /// Whether a resize handle is being dragged. + /// + /// Starting a drag does not notify, so read this while rendering during + /// the drag rather than relying on a notification when it starts. pub fn is_resizing(&self) -> bool { self.resizing_panel_ix.is_some() } @@ -271,6 +274,7 @@ impl ResizableState { pub fn clear(&mut self) { self.panels.clear(); self.sizes.clear(); + self.resizing_panel_ix = None; } #[inline] @@ -995,6 +999,63 @@ mod tests { }); } + #[gpui::test] + fn clearing_mid_drag_stops_resizing(cx: &mut TestAppContext) { + let (cx, state, _) = harness(cx); + let boundary = cx.debug_bounds("second-panel").unwrap().left(); + cx.simulate_mouse_down( + point(boundary - px(2.), px(50.)), + MouseButton::Left, + Modifiers::default(), + ); + cx.simulate_mouse_move( + point(boundary + px(10.), px(50.)), + Some(MouseButton::Left), + Modifiers::default(), + ); + assert!(state.read_with(cx, |state, _| state.is_resizing())); + + state.update(cx, |state, _| state.clear()); + assert!(!state.read_with(cx, |state, _| state.is_resizing())); + } + + #[gpui::test] + fn stopping_the_drag_ends_resizing(cx: &mut TestAppContext) { + let (cx, state, resizes) = harness(cx); + let boundary = cx.debug_bounds("second-panel").unwrap().left(); + cx.simulate_mouse_down( + point(boundary - px(2.), px(50.)), + MouseButton::Left, + Modifiers::default(), + ); + cx.simulate_mouse_move( + point(px(220.), px(50.)), + Some(MouseButton::Left), + Modifiers::default(), + ); + assert!(state.read_with(cx, |state, _| state.is_resizing())); + + // No mouse up follows a cancelled drag. + cx.update(|window, cx| { + cx.stop_active_drag(window); + window.draw(cx).clear(cx); + }); + let sizes = state.read_with(cx, |state, _| { + assert!(!state.is_resizing()); + state.sizes().clone() + }); + assert_eq!(resizes.get(), 1); + + // Moving the mouse afterwards no longer resizes. + cx.simulate_mouse_move( + point(px(260.), px(50.)), + Some(MouseButton::Left), + Modifiers::default(), + ); + assert_eq!(state.read_with(cx, |state, _| state.sizes().clone()), sizes); + assert_eq!(resizes.get(), 1); + } + /// Reports every state its divider is rendered in, so a drag can be watched /// from outside the handle. /// diff --git a/crates/base/src/resizable/panel.rs b/crates/base/src/resizable/panel.rs index c0567ae527..ea2ba4e9f2 100644 --- a/crates/base/src/resizable/panel.rs +++ b/crates/base/src/resizable/panel.rs @@ -470,13 +470,30 @@ impl Element for ResizePanelGroupElement { _: &mut Self::RequestLayoutState, _: &mut Self::PrepaintState, window: &mut Window, - _: &mut App, + cx: &mut App, ) { + // A drag cancelled with `cx.stop_active_drag` gets no mouse up, so end + // it after this frame instead of leaving `is_resizing()` stuck. + if self.state.read(cx).resizing_panel_ix.is_some() && !cx.has_active_drag() { + let state = self.state.clone(); + let on_resize = self.on_resize.clone(); + window.defer(cx, move |window, cx| { + if state.read(cx).resizing_panel_ix.is_none() || cx.has_active_drag() { + return; + } + state.update(cx, |state, cx| { + state.done_resizing(cx); + cx.notify(); + }); + on_resize(&state, window, cx); + }); + } + window.on_mouse_event({ let state = self.state.clone(); let axis = self.axis; move |e: &MouseMoveEvent, phase, window, cx| { - if !phase.bubble() { + if !phase.bubble() || !cx.has_active_drag() { return; } let Some(ix) = state.read(cx).resizing_panel_ix else {