From 45ea41b93b0e23bf393820a8266561caad81f3be Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Sun, 15 Nov 2026 10:46:49 +0700 Subject: [PATCH] layout: initialize split pane widths on first render --- crates/layout/src/panel.rs | 10 +++++++++- crates/layout/src/resizable.rs | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/layout/src/panel.rs b/crates/layout/src/panel.rs index a9a07b3..afc38fa 100644 --- a/crates/layout/src/panel.rs +++ b/crates/layout/src/panel.rs @@ -5,7 +5,7 @@ use gpui::{ AnyElement, AnyView, App, Axis, Div, ElementId, IntoElement, ParentElement as _, RenderOnce, - StyleRefinement, Styled as _, Window, div, + StyleRefinement, Styled as _, Window, div, rems, }; use gpui_native_theme::ActiveTheme as _; @@ -70,6 +70,7 @@ impl RenderOnce for Panel { let theme = cx.theme(); let app_background = theme.colors.muted; let id = self.id.clone(); + let gutter = rems(0.5).to_pixels(window.rem_size()); let main = island( div() @@ -85,6 +86,13 @@ impl RenderOnce for Panel { .use_keyed_state("panel-sizes", cx, |_, _| ResizableState::default()) .clone() }); + let extent = window.viewport_size().width - gutter * 2.0; + + if sizes.read(cx).sizes().is_empty() { + sizes.update(cx, |state, cx| { + state.set_pane_width(0, (extent - gutter) / 2.0, cx) + }); + } div().w_full().h_full().child( Resizable::new((id.clone(), "split"), sizes) diff --git a/crates/layout/src/resizable.rs b/crates/layout/src/resizable.rs index 1778a05..a15bc22 100644 --- a/crates/layout/src/resizable.rs +++ b/crates/layout/src/resizable.rs @@ -105,6 +105,17 @@ impl ResizableState { } } + /// Sets pane `ix`'s width, backfilling earlier panes. + pub fn set_pane_width(&mut self, ix: usize, width: Pixels, cx: &mut Context) { + while self.sizes.len() <= ix { + self.sizes.push(width); + } + if self.sizes[ix] != width { + self.sizes[ix] = width; + cx.notify(); + } + } + /// Restores pane `ix` to the equal split, as a double-click does. fn reset_pane(&mut self, ix: usize, pane_count: usize, cx: &mut Context) { let split = self.equal_split(pane_count);