diff options
author | Tim Oram <mitmaro@gmail.com> | 2017-01-29 00:05:45 -0330 |
---|---|---|
committer | Tim Oram <mitmaro@gmail.com> | 2017-01-29 10:20:52 -0330 |
commit | c5c63c099a7533de6f7ad39c453bc0180755ed44 (patch) | |
tree | ef6004285ce685cdbe8c91bb9ce3efd121a4ff49 /src | |
parent | a672cacfefeabef9de007e9c8d6dbcb1429e78b1 (diff) |
Fixed overflow on move
Caused by window being a greater height than number of items
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index b33eef4..cb0de7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -245,11 +245,7 @@ impl Window { fn draw(&self, git_interactive: &GitInteractive) { self.window.clear(); self.draw_title(); - let window_height = match self.window.get_max_y() { - // 4 removed for other UI lines - x if x >= 4 => x - 4, - _ => 4 - } as usize; + let window_height = self.get_window_height(); if self.top > 0 { self.draw_more_indicator(self.top); @@ -400,10 +396,10 @@ impl Window { } fn set_top(&mut self, git_interactive: &GitInteractive) { - // 4 removed for other UI lines - let window_height = (self.window.get_max_y() - 4) as usize; + let window_height = self.get_window_height(); self.top = match git_interactive.selected_line { + _ if git_interactive.lines.len() <= window_height => 0, s if s == git_interactive.lines.len() => git_interactive.lines.len() - window_height, s if self.top + 1 > s => s - 1, s if self.top + window_height <= s => s - window_height + 1, @@ -411,6 +407,14 @@ impl Window { }; } + fn get_window_height(&self) -> usize { + return match self.window.get_max_y() { + // 4 removed for other UI lines + x if x >= 4 => x - 4, + _ => 4 + } as usize; + } + fn endwin(&self) { self.window.clear(); self.window.refresh(); |