summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-01-22 22:01:14 +0100
committerqkzk <qu3nt1n@gmail.com>2023-01-22 22:01:14 +0100
commitb5e5f95536a5c1db3d985a85c0d9e7db9b9bbb24 (patch)
treef13fc32445c9adfcef622b2a0adeb34180fab192
parentd5404b15ff258663b8fa24907fdc1e327d9c4cb7 (diff)
tree: refactor tree window
-rw-r--r--src/preview.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/preview.rs b/src/preview.rs
index e0554ba..8573ee9 100644
--- a/src/preview.rs
+++ b/src/preview.rs
@@ -644,21 +644,16 @@ impl Directory {
/// is selected and the size of the window used to display.
pub fn calculate_tree_window(&self, height: usize) -> (usize, usize, usize) {
let length = self.content.len();
- let mut top = if self.selected_index < height - 1 {
- 0
- } else {
- self.selected_index - 1
- };
- let mut bottom = if self.selected_index < height - 1 {
- height - 1
- } else {
- self.selected_index + height - 1
- };
- let padding = std::cmp::max(10, height / 2);
- if self.selected_index >= height - 1 {
- top -= padding;
- bottom += padding;
+ let top: usize;
+ let bottom: usize;
+ if self.selected_index < height - 1 {
+ top = 0;
+ bottom = height - 1;
+ } else {
+ let padding = std::cmp::max(10, height / 2);
+ top = self.selected_index - 1 - padding;
+ bottom = self.selected_index + height - 1 + padding;
}
(top, bottom, length)