From 9e35085573fc15b2d035c3be8f9efe5e1d2d68d6 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sat, 27 Dec 2014 17:01:57 -0800 Subject: [PATCH] Fixed some minor behavior problems in cursor movement and pageup/pagedown. --- src/editor.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index 6e26fe2..e426720 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -113,6 +113,14 @@ impl Editor { self.move_view_to_cursor(); } + pub fn cursor_to_beginning_of_buffer(&mut self) { + self.cursor = (0, 0); + } + + pub fn cursor_to_end_of_buffer(&mut self) { + self.cursor = self.buffer.pos_1d_to_closest_2d(self.buffer.len()+1); + } + pub fn cursor_left(&mut self) { let p = self.buffer.pos_2d_to_closest_1d(self.cursor); @@ -137,6 +145,9 @@ impl Editor { if self.cursor.0 > 0 { self.cursor.0 -= 1; } + else { + self.cursor_to_beginning_of_buffer(); + } self.move_view_to_cursor(); } @@ -145,6 +156,9 @@ impl Editor { if self.cursor.0 < self.buffer.newline_count() { self.cursor.0 += 1; } + else { + self.cursor_to_end_of_buffer(); + } self.move_view_to_cursor(); } @@ -163,14 +177,16 @@ impl Editor { self.cursor.0 -= self.view_pos.0; } else { - self.cursor = (0, 0); + self.cursor_to_beginning_of_buffer(); } self.view_pos.0 = 0; } } else { - self.cursor = (0, 0); + self.cursor_to_beginning_of_buffer(); } + + self.move_view_to_cursor(); } pub fn page_down(&mut self) { @@ -192,8 +208,10 @@ impl Editor { self.cursor.0 += move_amount; } else { - self.cursor = self.buffer.pos_1d_to_closest_2d(self.buffer.len()+1); + self.cursor_to_end_of_buffer(); } - } + } + + self.move_view_to_cursor(); } }