Skip to content

Commit

Permalink
Refactors the calc_skipped_rows function to make it more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
ElSamhaa committed Apr 7, 2024
1 parent 4aa367c commit 8780550
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/directory_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -63,7 +67,9 @@ impl ScrollState {
} else {
current_focus.saturating_sub(ScrollState::PREVIEW_CUSHION)
}
}
};

new_skipped_rows
}
}

Expand Down

0 comments on commit 8780550

Please sign in to comment.