Skip to content

Commit 59c8a52

Browse files
authored
Merge pull request #19 from MitMaro/fix-overflow-bug
Fixed overflow on move
2 parents a672cac + c5c63c0 commit 59c8a52

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/main.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,7 @@ impl Window {
245245
fn draw(&self, git_interactive: &GitInteractive) {
246246
self.window.clear();
247247
self.draw_title();
248-
let window_height = match self.window.get_max_y() {
249-
// 4 removed for other UI lines
250-
x if x >= 4 => x - 4,
251-
_ => 4
252-
} as usize;
248+
let window_height = self.get_window_height();
253249

254250
if self.top > 0 {
255251
self.draw_more_indicator(self.top);
@@ -400,17 +396,25 @@ impl Window {
400396
}
401397

402398
fn set_top(&mut self, git_interactive: &GitInteractive) {
403-
// 4 removed for other UI lines
404-
let window_height = (self.window.get_max_y() - 4) as usize;
399+
let window_height = self.get_window_height();
405400

406401
self.top = match git_interactive.selected_line {
402+
_ if git_interactive.lines.len() <= window_height => 0,
407403
s if s == git_interactive.lines.len() => git_interactive.lines.len() - window_height,
408404
s if self.top + 1 > s => s - 1,
409405
s if self.top + window_height <= s => s - window_height + 1,
410406
_ => self.top
411407
};
412408
}
413409

410+
fn get_window_height(&self) -> usize {
411+
return match self.window.get_max_y() {
412+
// 4 removed for other UI lines
413+
x if x >= 4 => x - 4,
414+
_ => 4
415+
} as usize;
416+
}
417+
414418
fn endwin(&self) {
415419
self.window.clear();
416420
self.window.refresh();

0 commit comments

Comments
 (0)