Adds corresponding config setting for vimlike_scrolling

pull/704/head
Ahmed ElSamhaa 1 month ago
parent e834242f5d
commit 01606e0e60

@ -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)]

@ -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

@ -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

@ -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()

Loading…
Cancel
Save