From cdae7c8a9a412cfc4cdb08905863b1179b986dd7 Mon Sep 17 00:00:00 2001 From: Hanif Ariffin Date: Thu, 9 Feb 2023 02:54:34 +0800 Subject: [PATCH] Add settings to configure the scroll speed (#2120) Feature requested here: https://github.com/lapce/lapce/issues/2085 Signed-off-by: Hanif Ariffin --- defaults/settings.toml | 1 + lapce-data/src/config.rs | 4 ++++ lapce-ui/src/scroll.rs | 6 ++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/defaults/settings.toml b/defaults/settings.toml index cdd10cfc..c5dd3ef4 100644 --- a/defaults/settings.toml +++ b/defaults/settings.toml @@ -47,6 +47,7 @@ atomic-soft-tabs = false double-click = false move-focus-while-search = true diff-context-lines=3 +scroll-speed-modifier=1 [terminal] font-family = "" diff --git a/lapce-data/src/config.rs b/lapce-data/src/config.rs index 18343b64..43ba5713 100644 --- a/lapce-data/src/config.rs +++ b/lapce-data/src/config.rs @@ -475,6 +475,10 @@ pub struct EditorConfig { desc = "Set the default number of visible lines above and below the diff block (-1 for infinite)" )] pub diff_context_lines: i32, + #[field_names( + desc = "Scroll speed modifier. The scroll delta will be multiplied by whatever the value is povided here. Defaults to 1." + )] + pub scroll_speed_modifier: f64, } impl EditorConfig { diff --git a/lapce-ui/src/scroll.rs b/lapce-ui/src/scroll.rs index 4792dfef..e32e4d4c 100644 --- a/lapce-ui/src/scroll.rs +++ b/lapce-ui/src/scroll.rs @@ -742,11 +742,13 @@ pub fn handle_scroll( port: &mut Viewport, ctx: &mut EventCtx, event: &Event, + config: &LapceConfig, env: &Env, ) { if !ctx.is_handled() { if let Event::Wheel(mouse) = event { - let mut delta = mouse.wheel_delta.round(); + let mut delta = + mouse.wheel_delta.round() * config.editor.scroll_speed_modifier; if self.vertical_scroll_for_horizontal && delta.x == 0.0 { delta.x = delta.y; } @@ -898,7 +900,7 @@ fn event(&mut self, ctx: &mut EventCtx, event: &Event, data: &mut T, env: &Env) } self.clip.with_port(|port| { - scroll_component.handle_scroll(port, ctx, event, env); + scroll_component.handle_scroll(port, ctx, event, data.get_config(), env); }); match event {