diff options
| author | Mattias Andrée <maandree@operamail.com> | 2013-09-11 12:19:02 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2013-09-11 12:19:02 +0200 |
| commit | c157e38949ddcbc34cccc61ed041068697dc24b2 (patch) | |
| tree | c88f96229334a7d9fadf0f3b956df779addb41a3 /src/editor.py | |
| parent | add key combinations for undo actions (diff) | |
| download | pytagomacs-c157e38949ddcbc34cccc61ed041068697dc24b2.tar.gz pytagomacs-c157e38949ddcbc34cccc61ed041068697dc24b2.tar.bz2 pytagomacs-c157e38949ddcbc34cccc61ed041068697dc24b2.tar.xz | |
implement undo logic
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/editor.py')
| -rw-r--r-- | src/editor.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/editor.py b/src/editor.py index d76e146..d141b66 100644 --- a/src/editor.py +++ b/src/editor.py @@ -528,7 +528,24 @@ class TextArea(): if self.editring.is_empty(): self.alert('Nothing to undo') else: - pass # TODO undo/redo + (edit, undo) = self.editring.pop() + self.alert('Undo!' if undo else 'Redo!') + fix_offx = not (self.offx <= edit.x < self.offx + self.areawidth) + text = self.lines[edit.y] + if edit.deleted is not None: + a, b = max(edit.old_x, edit.new_x), min(edit.old_x, edit.new_x) + text = text[:a] + text[b:] + if edit.inserted is not None: + text = text[:edit.old_x] + edit.inserted + text[edit.old_x:] + self.lines[edit.x] = text + self.x = edit.new_x + if self.y != edit.y: + self.mark = None + fix_offx = True + self.y = edit.y + if fix_offx: + self.offx = max(edit.x - self.areawidth + 1, 0) + self.lines[self.y].draw() elif d == ctrl('X'): self.alert('C-x') sys.stdout.flush() |
