add compound change undo/redo
@@ -197,11 +197,21 @@ class Mutator(app.selectable.Selectable):
if change[0] != 'm':
self.shouldReparse = True
self.redoIndex += 1
+ self.__redoStep(change)
+ # Redo again if there is a move next.
+ if (self.redoIndex < len(self.redoChain) and
+ self.redoChain[self.redoIndex][0] == 'm'):
+ self.redo()
+
+ def __redoStep(self, change):
if change[0] == 'b':
line = self.lines[self.penRow]
self.penCol -= len(change[1])
x = self.penCol
self.lines[self.penRow] = line[:x] + line[x + len(change[1]):]
+ elif change[0] == 'cc': # Redo compound change.
+ for change in change[1]:
+ self.__redoStep(change)
elif change[0] == 'd':
line = self.lines[self.penRow]
x = self.penCol
@@ -265,10 +275,6 @@ class Mutator(app.selectable.Selectable):
self.doVerticalInsert(change)
else:
app.log.info('ERROR: unknown redo.')
- # Redo again if there is a move next.
- if (self.redoIndex < len(self.redoChain) and
- self.redoChain[self.redoIndex][0] == 'm'):
- self.redo()
def redoAddChange(self, change):
"""
@@ -381,11 +387,18 @@ class Mutator(app.selectable.Selectable):
self.shouldReparse = True
if self.debugRedo:
app.log.info('undo', self.redoIndex, repr(change))
+ return self.__undoStep(change)
+ return False
+
+ def __undoStep(self, change):
if change[0] == 'b':
line = self.lines[self.penRow]
x = self.penCol
self.lines[self.penRow] = line[:x] + change[1] + line[x:]
self.penCol += len(change[1])
+ elif change[0] == 'cc': # Undo compound change.
+ for change in change[1]:
+ self.__undoStep(change)
elif change[0] == 'd':
line = self.lines[self.penRow]
x = self.penCol
