From 0192cbbc6b66114c247279b2d4c96f73a2cfd58b Mon Sep 17 00:00:00 2001 From: mars Date: Tue, 11 Apr 2023 17:44:10 -0400 Subject: [PATCH] Fix bad EOF behavior --- src/main.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 27ffff7..c37c41b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,6 +45,11 @@ impl Buffer { out.execute(cursor::MoveTo(0, 0))?; for (row, line) in (0..rows).zip(self.text.lines_at(scroll.line)) { + // only the last line is empty and should be skipped + if line.len_chars() == 0 { + break; + } + let row = row as usize + scroll.line; write!(out, "{:width$} ", row, width = lr_width as usize)?; @@ -89,7 +94,7 @@ impl Buffer { } } Direction::Down => { - if cursor.line < self.text.len_lines() { + if cursor.line + 2 < self.text.len_lines() { cursor.line += 1; } } @@ -101,7 +106,7 @@ impl Buffer { Direction::Right => { let line = self.text.line(cursor.line); if cursor.column + 2 > line.len_chars() { - if enable_linewrap && cursor.line < self.text.len_lines() { + if enable_linewrap && cursor.line + 2 < self.text.len_lines() { cursor.line += 1; cursor.column = 0; }