This commit is contained in:
sxyazi 2024-08-30 09:18:54 +08:00
parent 839a43a6ee
commit c0ff5805cc
No known key found for this signature in database

View file

@ -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,9 +72,10 @@ impl Folder {
self.prev(step)
};
self.sync_page(false);
self.adjust_offset();
self.tracing |= b;
b |= self.squeeze_offset();
self.sync_page(false);
b
}
@ -104,21 +105,6 @@ 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).min(len).saturating_sub(scrolloff);
let new_offset = if self.cursor >= max_offset {
self.cursor.saturating_sub(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();
@ -127,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)
@ -152,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 {