mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-24 16:21:04 +00: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
2 changed files with 24 additions and 6 deletions
|
|
@ -49,7 +49,7 @@ impl Chafa {
|
||||||
let area = Rect {
|
let area = Rect {
|
||||||
x: max.x,
|
x: max.x,
|
||||||
y: max.y,
|
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,
|
height: lines.len() as u16,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ impl Folder {
|
||||||
|
|
||||||
pub fn arrow(&mut self, step: impl Into<Step>) -> bool {
|
pub fn arrow(&mut self, step: impl Into<Step>) -> bool {
|
||||||
let step = step.into() as Step;
|
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);
|
(self.cursor, self.offset, self.tracing) = (0, 0, false);
|
||||||
false
|
false
|
||||||
} else if step.is_positive() {
|
} else if step.is_positive() {
|
||||||
|
|
@ -72,8 +72,10 @@ impl Folder {
|
||||||
self.prev(step)
|
self.prev(step)
|
||||||
};
|
};
|
||||||
|
|
||||||
self.sync_page(false);
|
|
||||||
self.tracing |= b;
|
self.tracing |= b;
|
||||||
|
b |= self.squeeze_offset();
|
||||||
|
|
||||||
|
self.sync_page(false);
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,10 +113,10 @@ impl Folder {
|
||||||
let scrolloff = (limit / 2).min(MANAGER.scrolloff as usize);
|
let scrolloff = (limit / 2).min(MANAGER.scrolloff as usize);
|
||||||
|
|
||||||
self.cursor = step.add(self.cursor, limit).min(len.saturating_sub(1));
|
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) {
|
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))
|
self.offset.min(len.saturating_sub(1))
|
||||||
|
} else {
|
||||||
|
len.saturating_sub(limit).min(self.offset + self.cursor - old.0)
|
||||||
};
|
};
|
||||||
|
|
||||||
old != (self.cursor, self.offset)
|
old != (self.cursor, self.offset)
|
||||||
|
|
@ -136,6 +138,22 @@ impl Folder {
|
||||||
|
|
||||||
old != (self.cursor, self.offset)
|
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 {
|
impl Folder {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue