From 52deecfaaa6afdbf7d2fbd631c558812a79d3194 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 11 Mar 2026 14:59:59 -0700 Subject: [PATCH] Fix flex calculation when moving agent panel Co-authored-by: Eric Holk --- crates/workspace/src/pane_group.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/crates/workspace/src/pane_group.rs b/crates/workspace/src/pane_group.rs index 55e517152a09937b1766b3232b057d59b81c2c73..4f57b5994b0bb12c4335e53571461086ddd76ecb 100644 --- a/crates/workspace/src/pane_group.rs +++ b/crates/workspace/src/pane_group.rs @@ -701,8 +701,17 @@ struct PaneAxisStateEntry { impl PaneGroupState { fn total_flex(&self) -> f32 { let state = self.0.borrow(); - state.left_entry.as_ref().map_or(0., |e| e.flex) - + state.right_entry.as_ref().map_or(0., |e| e.flex) + let left = state + .left_entry + .as_ref() + .filter(|_| state.left_entry_is_active) + .map_or(0., |e| e.flex); + let right = state + .right_entry + .as_ref() + .filter(|_| state.right_entry_is_active) + .map_or(0., |e| e.flex); + left + right } fn reset_flexes(&self) { @@ -1376,7 +1385,7 @@ pub mod element { Axis::Horizontal => px(HORIZONTAL_MIN_SIZE), Axis::Vertical => px(VERTICAL_MIN_SIZE), }; - debug_assert!(flex_values_in_bounds(&entries)); + check_flex_values_in_bounds(&entries); // Math to convert a flex value to a pixel value let size = move |ix: usize, state: &[&mut PaneAxisStateEntry]| { @@ -1546,7 +1555,7 @@ pub mod element { let len = self.children.len(); debug_assert!(entries.len() == len); - debug_assert!(flex_values_in_bounds(&entries)); + check_flex_values_in_bounds(&entries); let total_flex = len as f32; @@ -1759,7 +1768,13 @@ pub mod element { } } - fn flex_values_in_bounds(inner: &[&mut PaneAxisStateEntry]) -> bool { - (inner.iter().map(|e| e.flex).sum::() - inner.len() as f32).abs() < 0.001 + fn check_flex_values_in_bounds(inner: &[&mut PaneAxisStateEntry]) { + #[cfg(debug_assertions)] + if (inner.iter().map(|e| e.flex).sum::() - inner.len() as f32).abs() >= 0.001 { + panic!( + "flex values out of bounds: {:?}", + inner.iter().map(|e| e.flex).collect::>() + ); + } } }