From 3189ede2b9225b1b930cc43368248c6b4f3a4daf Mon Sep 17 00:00:00 2001 From: "CHIH,GODLEE" <61595521+ChihGodlee@users.noreply.github.com> Date: Mon, 18 May 2026 20:27:43 +0800 Subject: feat: configure sidebar min/max width via [ui] (#135) * feat: configure sidebar min/max width via [ui] Expose the previously hardcoded MIN_SIDEBAR_WIDTH / MAX_SIDEBAR_WIDTH clamps as [ui] sidebar_min_width / sidebar_max_width. Defaults remain 18 / 36 so existing configs are unchanged. Hot-reload is wired through the existing [ui] block; reload re-clamps the live width to the new bounds so tightening takes effect immediately. Reject inverted bounds (min > max) at every entry point so a bad config can never reach u16::clamp(min, max), which panics: App::new falls back to defaults, and apply_live_config treats the whole [ui] section as invalid and returns a partial reload report. refs #132 * test: keep sidebar reload width within bounds refs #132 --------- Co-authored-by: Ogulcan Celik --- src/app/input/sidebar.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/app/input') diff --git a/src/app/input/sidebar.rs b/src/app/input/sidebar.rs index e8e1e094..94feaf93 100644 --- a/src/app/input/sidebar.rs +++ b/src/app/input/sidebar.rs @@ -244,8 +244,7 @@ impl AppState { pub(super) fn set_manual_sidebar_width(&mut self, divider_col: u16) { let sidebar = self.view.sidebar_rect; let width = divider_col.saturating_sub(sidebar.x).saturating_add(1); - self.sidebar_width = - width.clamp(crate::ui::MIN_SIDEBAR_WIDTH, crate::ui::MAX_SIDEBAR_WIDTH); + self.sidebar_width = width.clamp(self.sidebar_min_width, self.sidebar_max_width); self.sidebar_width_source = crate::app::state::SidebarWidthSource::Manual; self.mark_session_dirty(); } @@ -1239,6 +1238,28 @@ mod tests { assert_eq!(snapshot.sidebar_width, Some(31)); } + #[test] + fn dragging_past_max_clamps_to_configured_max() { + let mut app = app_for_mouse_test(); + app.state.sidebar_max_width = 30; + + app.handle_mouse(mouse(MouseEventKind::Down(MouseButton::Left), 25, 5)); + app.handle_mouse(mouse(MouseEventKind::Drag(MouseButton::Left), 50, 5)); + + assert_eq!(app.state.sidebar_width, 30); + } + + #[test] + fn dragging_below_min_clamps_to_configured_min() { + let mut app = app_for_mouse_test(); + app.state.sidebar_min_width = 22; + + app.handle_mouse(mouse(MouseEventKind::Down(MouseButton::Left), 25, 5)); + app.handle_mouse(mouse(MouseEventKind::Drag(MouseButton::Left), 5, 5)); + + assert_eq!(app.state.sidebar_width, 22); + } + #[test] fn dragging_sidebar_section_divider_sets_split_ratio() { let mut app = app_for_mouse_test(); -- cgit v1.2.3