Skip to content

Commit

Permalink
Adds corresponding config setting for vimlike_scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
ElSamhaa committed Apr 7, 2024
1 parent e834242 commit 01606e0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
11 changes: 7 additions & 4 deletions src/directory_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ 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;
let start_cushion_row = first_visible_row + ScrollState::PREVIEW_CUSHION;
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
Expand Down
5 changes: 5 additions & 0 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 01606e0

Please sign in to comment.