From a9ff4012bdca0dbdbc77bc6e53a430689fc899be Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Fri, 22 May 2026 00:12:53 +0300 Subject: feat: add configurable mouse scroll lines refs #236 --- src/config/model.rs | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/config') diff --git a/src/config/model.rs b/src/config/model.rs index e099d510..f270a69c 100644 --- a/src/config/model.rs +++ b/src/config/model.rs @@ -1,7 +1,10 @@ +use std::num::NonZeroUsize; + use serde::{Deserialize, Deserializer, Serialize}; use super::{ - BindingConfig, CommandKeybindConfig, SoundConfig, ThemeConfig, DEFAULT_SCROLLBACK_LIMIT_BYTES, + BindingConfig, CommandKeybindConfig, SoundConfig, ThemeConfig, DEFAULT_MOUSE_SCROLL_LINES, + DEFAULT_SCROLLBACK_LIMIT_BYTES, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Default)] @@ -193,6 +196,8 @@ pub struct UiConfig { pub sidebar_max_width: u16, /// Capture mouse input for Herdr's mouse UI. Default: true. pub mouse_capture: bool, + /// Lines to scroll per mouse wheel notch. Default: 3. + pub mouse_scroll_lines: Option, /// Ask for confirmation before closing a workspace. Default: true. pub confirm_close: bool, /// Ask for a tab name before creating a new tab. Default: true. @@ -328,6 +333,7 @@ impl Default for UiConfig { sidebar_min_width: 18, sidebar_max_width: 36, mouse_capture: true, + mouse_scroll_lines: None, confirm_close: true, prompt_new_tab_name: true, show_agent_labels_on_pane_borders: false, @@ -339,6 +345,14 @@ impl Default for UiConfig { } } +impl UiConfig { + pub fn mouse_scroll_lines(&self) -> usize { + self.mouse_scroll_lines + .map(NonZeroUsize::get) + .unwrap_or(DEFAULT_MOUSE_SCROLL_LINES) + } +} + impl Default for ToastConfig { fn default() -> Self { Self { @@ -516,6 +530,31 @@ mouse_capture = false assert!(!config.ui.mouse_capture); } + #[test] + fn mouse_scroll_lines_defaults_to_three_and_parses() { + let default_config = Config::default(); + assert_eq!( + default_config.ui.mouse_scroll_lines(), + DEFAULT_MOUSE_SCROLL_LINES + ); + + let toml = r#" +[ui] +mouse_scroll_lines = 1 +"#; + let config: Config = toml::from_str(toml).unwrap(); + assert_eq!(config.ui.mouse_scroll_lines(), 1); + } + + #[test] + fn mouse_scroll_lines_rejects_zero() { + let toml = r#" +[ui] +mouse_scroll_lines = 0 +"#; + assert!(toml::from_str::(toml).is_err()); + } + #[test] fn toast_config_parses() { let toml = r#" -- cgit v1.2.3