mirror of
https://github.com/sxyazi/yazi.git
synced 2024-11-24 01:48:00 +03:00
fix: squeeze offset
of the file list after resizing window (#1500)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
598104492b
commit
69e7c8ff0d
@ -49,7 +49,7 @@ impl Chafa {
|
||||
let area = Rect {
|
||||
x: max.x,
|
||||
y: max.y,
|
||||
width: first.spans.into_iter().map(|s| s.content.chars().count() as u16).sum(),
|
||||
width: first.width() as u16,
|
||||
height: lines.len() as u16,
|
||||
};
|
||||
|
||||
|
@ -63,7 +63,7 @@ impl Folder {
|
||||
|
||||
pub fn arrow(&mut self, step: impl Into<Step>) -> bool {
|
||||
let step = step.into() as Step;
|
||||
let b = if self.files.is_empty() {
|
||||
let mut b = if self.files.is_empty() {
|
||||
(self.cursor, self.offset, self.tracing) = (0, 0, false);
|
||||
false
|
||||
} else if step.is_positive() {
|
||||
@ -72,8 +72,10 @@ impl Folder {
|
||||
self.prev(step)
|
||||
};
|
||||
|
||||
self.sync_page(false);
|
||||
self.tracing |= b;
|
||||
b |= self.squeeze_offset();
|
||||
|
||||
self.sync_page(false);
|
||||
b
|
||||
}
|
||||
|
||||
@ -111,10 +113,10 @@ impl Folder {
|
||||
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(scrolloff) {
|
||||
len.saturating_sub(limit).min(self.offset + self.cursor - old.0)
|
||||
} else {
|
||||
self.offset = if self.cursor < (self.offset + limit).min(len).saturating_sub(scrolloff) {
|
||||
self.offset.min(len.saturating_sub(1))
|
||||
} else {
|
||||
len.saturating_sub(limit).min(self.offset + self.cursor - old.0)
|
||||
};
|
||||
|
||||
old != (self.cursor, self.offset)
|
||||
@ -136,6 +138,22 @@ impl Folder {
|
||||
|
||||
old != (self.cursor, self.offset)
|
||||
}
|
||||
|
||||
fn squeeze_offset(&mut self) -> bool {
|
||||
let old = self.offset;
|
||||
let len = self.files.len();
|
||||
|
||||
let limit = LAYOUT.load().current.height as usize;
|
||||
let scrolloff = (limit / 2).min(MANAGER.scrolloff as usize);
|
||||
|
||||
self.offset = if self.cursor < (self.offset + limit).min(len).saturating_sub(scrolloff) {
|
||||
len.saturating_sub(limit).min(self.offset)
|
||||
} else {
|
||||
len.saturating_sub(limit).min(self.cursor.saturating_sub(limit) + scrolloff)
|
||||
};
|
||||
|
||||
old != self.offset
|
||||
}
|
||||
}
|
||||
|
||||
impl Folder {
|
||||
|
Loading…
Reference in New Issue
Block a user