diff options
| author | Mattias Andrée <maandree@operamail.com> | 2013-09-11 12:26:29 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2013-09-11 12:26:29 +0200 |
| commit | dbe5f898484ef246dd451362aa4e26e6f97b8c10 (patch) | |
| tree | 6c73b8b17f8b921fafc14bfd8ff5a6176d78b82d /src/editor.py | |
| parent | implement undo logic (diff) | |
| download | pytagomacs-dbe5f898484ef246dd451362aa4e26e6f97b8c10.tar.gz pytagomacs-dbe5f898484ef246dd451362aa4e26e6f97b8c10.tar.bz2 pytagomacs-dbe5f898484ef246dd451362aa4e26e6f97b8c10.tar.xz | |
some necessary refinements
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/editor.py')
| -rw-r--r-- | src/editor.py | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/editor.py b/src/editor.py index d141b66..52414ec 100644 --- a/src/editor.py +++ b/src/editor.py @@ -22,6 +22,7 @@ import sys from subprocess import Popen, PIPE from killring import * +from editring import * @@ -432,6 +433,15 @@ class TextArea(): stored = ctrl('L') edited = False + def redraw(): + print('\033[H\033[2J', end='') + preredrawer() + for line in self.lines: + line.draw() + postredrawer() + self.realert() + self.restatus() + def store(key, value_map, required_next = None): nonlocal stored if key in value_map: @@ -463,12 +473,12 @@ class TextArea(): 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 + if self.y < self.offy: + self.offy = self.y + if self.y - self.offy > self.height - 3: + self.offy = self.y - self.height + 3 update_status() - stored = ctrl('L') + redraw() update_status() while True: @@ -496,7 +506,7 @@ class TextArea(): self.offy = max(0, self.offy) self.y = self.offy update_status() - stored = ctrl('L') + redraw() self.mark, self.x, self.offx = None, 0, 0 else: self.y = self.offy @@ -509,7 +519,7 @@ class TextArea(): self.y = min(self.y, len(self.lines) - 1) self.offy = max(0, self.y - self.height + 3) update_status() - stored = ctrl('L') + redraw() self.mark, self.x, self.offx = None, 0, 0 else: self.y = self.offy + self.height - 3 @@ -546,6 +556,8 @@ class TextArea(): if fix_offx: self.offx = max(edit.x - self.areawidth + 1, 0) self.lines[self.y].draw() + if not (self.offy <= edit.y < self.offy + self.height - 2): + ensure_y() elif d == ctrl('X'): self.alert('C-x') sys.stdout.flush() @@ -589,14 +601,7 @@ class TextArea(): elif d == ctrl('E'): move_point(len(self.lines[self.y].text) - self.x, 'At end') elif d == ctrl('B'): move_point(-1, 'At beginning') elif d == ctrl('A'): move_point(-(self.x), 'At beginning') - elif d == ctrl('L'): - print('\033[H\033[2J', end='') - preredrawer() - for line in self.lines: - line.draw() - postredrawer() - self.realert() - self.restatus() + elif d == ctrl('L'): redraw() elif d == '\033': d = sys.stdin.read(1) if d == '[': |
