Skip to content

Commit

Permalink
feat: add new scrolloff option to [manager] (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
dedukun authored Feb 15, 2024
1 parent b027487 commit b55c5dc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"0.2","language":"en","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank"]}
{"language":"en","flagWords":[],"version":"0.2","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff"]}
1 change: 1 addition & 0 deletions yazi-config/preset/yazi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ sort_dir_first = false
linemode = "none"
show_hidden = false
show_symlink = true
scrolloff = 5

[preview]
tab_size = 2
Expand Down
1 change: 1 addition & 0 deletions yazi-config/src/manager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 9 additions & 4 deletions yazi-core/src/folder/folder.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -108,8 +108,10 @@ impl Folder {
let len = self.files.len();

let limit = LAYOUT.load().current.height as usize;
let scrolloff = (limit / 2).min(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))
Expand All @@ -122,8 +124,11 @@ 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 scrolloff = (limit / 2).min(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)
Expand Down

0 comments on commit b55c5dc

Please sign in to comment.