From 01606e0e6006a9d6ef3492975d573565121d306c Mon Sep 17 00:00:00 2001 From: Ahmed ElSamhaa Date: Mon, 8 Apr 2024 00:14:29 +0300 Subject: [PATCH] Adds corresponding config setting for vimlike_scrolling --- src/config.rs | 3 +++ src/directory_buffer.rs | 11 +++++++---- src/init.lua | 5 +++++ src/ui.rs | 6 +++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index db08f86..05f9998 100644 --- a/src/config.rs +++ b/src/config.rs @@ -353,6 +353,9 @@ pub struct GeneralConfig { #[serde(default)] pub global_key_bindings: KeyBindings, + + #[serde(default)] + pub vimlike_scrolling: bool, } #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] diff --git a/src/directory_buffer.rs b/src/directory_buffer.rs index cf6a5c1..b25798a 100644 --- a/src/directory_buffer.rs +++ b/src/directory_buffer.rs @@ -18,7 +18,12 @@ impl ScrollState { self.current_focus = current_focus; } - pub fn calc_skipped_rows(&mut self, height: usize, total: usize) -> usize { + pub fn calc_skipped_rows( + &mut self, + height: usize, + total: usize, + vimlike_scrolling: bool, + ) -> usize { let current_focus = self.current_focus; let last_focus = self.last_focus; let first_visible_row = self.skipped_rows; @@ -26,9 +31,7 @@ impl ScrollState { let end_cushion_row = (first_visible_row + height) .saturating_sub(ScrollState::PREVIEW_CUSHION + 1); - let vim_scrolling_enabled = true; - - if !vim_scrolling_enabled { + if !vimlike_scrolling { height * (self.current_focus / height.max(1)) } else if last_focus == None { // Just entered the directory diff --git a/src/init.lua b/src/init.lua index a36ddb7..48a5f54 100644 --- a/src/init.lua +++ b/src/init.lua @@ -91,6 +91,11 @@ xplr.config.general.enable_recover_mode = false -- Type: boolean xplr.config.general.hide_remaps_in_help_menu = false +-- Set it to `true` if you want vim-like scrolling. +-- +-- Type: boolean +xplr.config.general.vimlike_scrolling = false + -- Set it to `true` if you want the cursor to stay in the same position when -- the focus is on the first path and you navigate to the previous path -- (by pressing `up`/`k`), or when the focus is on the last path and you diff --git a/src/ui.rs b/src/ui.rs index 838b1ef..2f92c6e 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -737,7 +737,11 @@ fn draw_table( .directory_buffer .as_mut() .map(|dir| { - dir.scroll_state.skipped_rows = dir.scroll_state.calc_skipped_rows(height, dir.total); + dir.scroll_state.skipped_rows = dir.scroll_state.calc_skipped_rows( + height, + dir.total, + app.config.general.vimlike_scrolling, + ); dir.nodes .iter() .enumerate()