From 5ffb460c743d9eda86a52d0eec57da14086abfba Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 10 Sep 2013 12:52:22 +0200 Subject: implement up and down browsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/editor.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/editor.py b/src/editor.py index f09c5b2..180e6e3 100644 --- a/src/editor.py +++ b/src/editor.py @@ -454,13 +454,22 @@ class TextArea(): self.alert(error_message) def update_status(): - below = len(self.lines) + 2 - self.height + below = len(self.lines) - (self.offy + self.height - 2) mode_text = 'modified' if modified else 'unmodified' ins_text = ' override' if override else '' above = ' +%i↑' % self.offy if self.offy > 0 else '' below = ' +%i↓' % below if below > 0 else '' self.status(mode_text + ins_text + above + below) + def ensure_y(): + nonlocal stored + if self.y - self.offy < 0: + self.offy -= 1 + if self.y - self.offy >= self.height - 2: + self.offy += 1 + update_status() + stored = ctrl('L') + update_status() while True: if atleast(oldmark, 0) or atleast(self.mark, 0): @@ -515,6 +524,7 @@ class TextArea(): self.alert('At first line') else: self.y -= 1 + ensure_y() self.mark, self.x, self.offx = None, 0, 0 update_status() elif d == ctrl('N'): @@ -522,6 +532,7 @@ class TextArea(): self.alert('At last line') else: self.y += 1 + ensure_y() self.mark, self.x, self.offx = None, 0, 0 update_status() elif d == ctrl('D'): edit(lambda L : L.delete(), 'At end') -- cgit v1.2.3-70-g09d2