diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-01-22 22:01:14 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-01-22 22:01:14 +0100 |
commit | b5e5f95536a5c1db3d985a85c0d9e7db9b9bbb24 (patch) | |
tree | f13fc32445c9adfcef622b2a0adeb34180fab192 /src | |
parent | d5404b15ff258663b8fa24907fdc1e327d9c4cb7 (diff) |
tree: refactor tree window
Diffstat (limited to 'src')
-rw-r--r-- | src/preview.rs | 23 |
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) |