mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: add scrolloff in [manager]
This commit is contained in:
parent
b027487d12
commit
b6c70aa012
3 changed files with 21 additions and 4 deletions
|
|
@ -11,6 +11,7 @@ sort_dir_first = false
|
|||
linemode = "none"
|
||||
show_hidden = false
|
||||
show_symlink = true
|
||||
scrolloff = 5
|
||||
|
||||
[preview]
|
||||
tab_size = 2
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue