fix: adjust offset value after resizing window (#1458)

This commit is contained in:
Lipman 2024-08-15 16:37:04 +08:00 committed by sxyazi
parent 598104492b
commit ebb4aef84f
No known key found for this signature in database

View file

@ -73,6 +73,7 @@ impl Folder {
};
self.sync_page(false);
self.adjust_offset();
self.tracing |= b;
b
}
@ -103,6 +104,18 @@ impl Folder {
}
}
pub fn adjust_offset(&mut self) {
let len = self.files.len();
let limit = LAYOUT.load().current.height as usize;
let scrolloff = (limit / 2).min(MANAGER.scrolloff as usize);
let max_offset = (self.offset + limit).saturating_sub(scrolloff).min(len);
let new_offset =
if self.cursor >= max_offset { self.cursor - limit + scrolloff } else { self.offset };
self.offset = new_offset.min(len.saturating_sub(limit));
}
fn next(&mut self, step: Step) -> bool {
let old = (self.cursor, self.offset);
let len = self.files.len();