mirror of
https://github.com/sayanarijit/xplr.git
synced 2024-09-11 19:07:47 +03:00
Refactors the calc_skipped_rows function to make it more readable
This commit is contained in:
parent
4aa367ca7c
commit
87805509c5
@ -31,18 +31,22 @@ impl ScrollState {
|
||||
let current_focus = self.current_focus;
|
||||
let last_focus = self.last_focus;
|
||||
let first_visible_row = self.skipped_rows;
|
||||
|
||||
// Calculate the cushion rows at the start and end of the view port
|
||||
let start_cushion_row = first_visible_row + ScrollState::PREVIEW_CUSHION;
|
||||
let end_cushion_row = (first_visible_row + height)
|
||||
.saturating_sub(ScrollState::PREVIEW_CUSHION + 1);
|
||||
|
||||
if !vimlike_scrolling {
|
||||
let new_skipped_rows = if !vimlike_scrolling {
|
||||
height * (self.current_focus / height.max(1))
|
||||
} else if last_focus == None {
|
||||
// Just entered the directory
|
||||
0
|
||||
} else if current_focus == 0 {
|
||||
// Focus on first node
|
||||
0
|
||||
} else if current_focus == total.saturating_sub(1) {
|
||||
// Focus on last node
|
||||
total.saturating_sub(height)
|
||||
} else if current_focus > last_focus.unwrap() {
|
||||
// Scrolling down
|
||||
@ -63,7 +67,9 @@ impl ScrollState {
|
||||
} else {
|
||||
current_focus.saturating_sub(ScrollState::PREVIEW_CUSHION)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
new_skipped_rows
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user