feat: add scrolloff in [manager]

This commit is contained in:
Diogo Duarte 2024-02-14 20:15:38 +00:00
parent b027487d12
commit b6c70aa012
3 changed files with 21 additions and 4 deletions

View file

@ -11,6 +11,7 @@ sort_dir_first = false
linemode = "none"
show_hidden = false
show_symlink = true
scrolloff = 5
[preview]
tab_size = 2

View file

@ -19,6 +19,7 @@ pub struct Manager {
pub linemode: String,
pub show_hidden: bool,
pub show_symlink: bool,
pub scrolloff: u8,
}
impl Default for Manager {

View file

@ -1,7 +1,7 @@
use std::{mem, time::SystemTime};
use ratatui::layout::Rect;
use yazi_config::LAYOUT;
use yazi_config::{LAYOUT, MANAGER};
use yazi_shared::fs::{File, FilesOp, Url};
use super::FolderStage;
@ -108,8 +108,15 @@ impl Folder {
let len = self.files.len();
let limit = LAYOUT.load().current.height as usize;
let half_screen = limit / 2;
let scrolloff = if MANAGER.scrolloff as usize > half_screen {
half_screen
} else {
MANAGER.scrolloff as usize
};
self.cursor = step.add(self.cursor, limit).min(len.saturating_sub(1));
self.offset = if self.cursor >= (self.offset + limit).min(len).saturating_sub(5) {
self.offset = if self.cursor >= (self.offset + limit).min(len).saturating_sub(scrolloff) {
len.saturating_sub(limit).min(self.offset + self.cursor - old.0)
} else {
self.offset.min(len.saturating_sub(1))
@ -122,8 +129,16 @@ impl Folder {
let old = (self.cursor, self.offset);
let max = self.files.len().saturating_sub(1);
self.cursor = step.add(self.cursor, LAYOUT.load().current.height as usize).min(max);
self.offset = if self.cursor < self.offset + 5 {
let limit = LAYOUT.load().current.height as usize;
let half_screen = limit / 2;
let scrolloff = if MANAGER.scrolloff as usize > half_screen {
half_screen
} else {
MANAGER.scrolloff as usize
};
self.cursor = step.add(self.cursor, limit).min(max);
self.offset = if self.cursor < self.offset + scrolloff {
self.offset.saturating_sub(old.0 - self.cursor)
} else {
self.offset.min(max)