diff options
| author | Mattias Andrée <maandree@operamail.com> | 2013-09-10 20:32:34 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2013-09-10 20:32:34 +0200 |
| commit | 8df69e653a1d45dc1840c79c473dde3ebdcfe2dd (patch) | |
| tree | dd1dc8e5cff1212a22a4c2a5988b61755b22ef22 /src/editring.py | |
| parent | implement edit reverse, direction change and add specification for push and pop to editring (diff) | |
| download | pytagomacs-8df69e653a1d45dc1840c79c473dde3ebdcfe2dd.tar.gz pytagomacs-8df69e653a1d45dc1840c79c473dde3ebdcfe2dd.tar.bz2 pytagomacs-8df69e653a1d45dc1840c79c473dde3ebdcfe2dd.tar.xz | |
push and pop the editring
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/editring.py')
| -rw-r--r-- | src/editring.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/editring.py b/src/editring.py index ac3db90..8a3c2ad 100644 --- a/src/editring.py +++ b/src/editring.py @@ -86,13 +86,27 @@ class Editring(): @param edit:Edit The edit to insert ''' - pass + self.editdir = -1 + self.editring[:] = self.editring[:self.editptr] + [edit] + self.editring[self.editptr:] + if len(self.editring) > self.editmax: + i = (self.editptr + self.editmax // 2) % self.editmax + self.editring[:] = self.editring[:i] + self.editring[i + 1:] def pop(self): ''' Get the next undo or redo - @return :(Edit, bool) The edit to preform (not reverse) and whether it is a undo + @return :(Edit, bool)? The edit to preform (not reverse) and whether it is a undo ''' - pass + if is_empty(): + return None + if self.editptr < 0: + self.editptr = min(1, len(self.editring)) + self.editdir = 1 + elif self.editptr == len(self.editring): + self.editptr = max(1, len(self.editring) - 2) + self.editdir = -1 + edit = self.editring[self.editptr] + self.editptr += self.editdir + return (edit, True) if self.editdir < 0 else (edit.reverse(), False) |
