Beispiel #1
0
 def __undoChange(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 += columnWidth(change[1])
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
     elif change[0] == 'bw':
         line = self.lines[self.penRow]
         x = self.penCol
         self.lines[self.penRow] = line[:x] + change[1] + line[x:]
         self.penCol += columnWidth(change[1])
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
     elif change[0] == 'd':
         line = self.lines[self.penRow]
         x = self.penCol
         self.lines[self.penRow] = line[:x] + change[1] + line[x:]
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
     elif change[0] == 'dr':  # Undo delete range.
         self.insertLinesAt(change[1][0], change[1][1], change[2],
                            app.selectable.kSelectionCharacter)
     elif change[0] == 'ds':  # Undo delete selection.
         self.insertLines(change[1])
     elif change[0] == 'f':  # Undo fence.
         pass
     elif change[0] == 'i':  # Undo insert.
         line = self.lines[self.penRow]
         x = self.penCol
         width = columnWidth(change[1])
         self.penCol -= width
         self.lines[self.penRow] = line[:x - width] + line[x:]
         self.goalCol = self.penCol
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
     elif change[0] == 'j':  # Undo join lines.
         line = self.lines[self.penRow]
         self.lines.insert(self.penRow + 1, line[self.penCol:])
         self.lines[self.penRow] = line[:self.penCol]
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
     elif change[0] == 'ld':  # Undo line diff.
         lines = []
         index = 0
         for ii in change[1]:
             if type(ii) is type(0):
                 for line in self.lines[index:index + ii]:
                     lines.append(line)
                 index += ii
             elif ii[0] == '+':
                 index += 1
             elif ii[0] == '-':
                 lines.append(ii[2:])
         self.lines = lines
         firstChangedRow = change[1][0] if type(
             change[1][0]) is type(0) else 0
         if self.upperChangedRow > firstChangedRow:
             self.upperChangedRow = firstChangedRow
     elif change[0] == 'm':
         self.__undoMove(change)
     elif change[0] == 'ml':
         # Undo move lines
         begin, end, to = change[1]
         count = end - begin
         if begin < to:
             self.__doMoveLines(to - 1, to + count - 1, begin + count - 1)
         else:
             self.__doMoveLines(to, to + count, begin + count)
     elif change[0] == 'n':
         # Undo split lines.
         self.__undoMove(change[2])
         self.lines[self.penRow] += self.lines[self.penRow + change[1]]
         for _ in range(change[1]):
             del self.lines[self.penRow + 1]
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
     elif change[0] == 'v':  # undo paste
         clip = change[1]
         row = self.penRow
         col = self.penCol
         app.log.info('len clip', len(clip))
         if len(clip) == 1:
             self.lines[row] = (self.lines[row][:col] +
                                self.lines[row][col + len(clip[0]):])
         else:
             self.lines[row] = (
                 self.lines[row][:col] +
                 self.lines[row + len(clip) - 1][len(clip[-1]):])
             delLineCount = len(clip[1:-1])
             del self.lines[row + 1:row + 1 + delLineCount + 1]
         if self.upperChangedRow > row:
             self.upperChangedRow = row
     elif change[0] == 'vb':
         row = min(self.markerRow, self.penRow)
         endRow = max(self.markerRow, self.penRow)
         for _ in range(row, endRow + 1):
             line = self.lines[self.penRow]
             x = self.penCol
             self.lines[self.penRow] = line[:x] + change[1] + line[x:]
         self.penCol += columnWidth(change[1])
         if self.upperChangedRow > row:
             self.upperChangedRow = row
     elif change[0] == 'vd':  # Undo vertical delete
         self.__doVerticalInsert(change)
     elif change[0] == 'vi':  # Undo vertical insert
         self.__doVerticalDelete(change)
     else:
         app.log.info('ERROR: unknown undo.')
Beispiel #2
0
 def __undoChange(self, change):
     if change[0] == 'b':
         self.parser.insert(self.penRow, self.penCol, change[1])
         position = self.parser.nextCharRowCol(self.penRow, self.penCol)
         if position is not None:
             self.penRow += position[0]
             self.penCol += position[1]
     elif change[0] == 'bw':  # Undo backspace word.
         self.parser.insert(self.penRow, self.penCol, change[1])
         self.penCol += columnWidth(change[1])
     elif change[0] == 'd':
         self.parser.insert(self.penRow, self.penCol, change[1])
     elif change[0] == 'dr':  # Undo delete range.
         self.insertLinesAt(change[1][0], change[1][1], change[2],
                            app.selectable.kSelectionCharacter)
     elif change[0] == 'ds':  # Undo delete selection.
         self.insertLines(change[1])
     elif change[0] == 'f':  # Undo fence.
         pass
     elif change[0] == 'i':  # Undo insert.
         width = columnWidth(change[1])
         self.parser.deleteRange(self.penRow, self.penCol - width,
                                 self.penRow, self.penCol)
         self.penCol -= width
         self.goalCol = self.penCol
     elif change[0] == 'j':  # Undo join lines.
         self.parser.insert(self.penRow, self.penCol, u"\n")
     elif change[0] == 'ld':  # Undo line diff.
         assert False  # Not used.
         lines = []
         index = 0
         for ii in change[1]:
             if type(ii) is type(0):
                 for line in self.parser.textLines(index, index + ii):
                     lines.append(line)
                 index += ii
             elif ii[0] == '+':
                 index += 1
             elif ii[0] == '-':
                 lines.append(ii[2:])
         self.parser.data = lines.join(u"\n")
         firstChangedRow = change[1][0] if type(
             change[1][0]) is type(0) else 0
     elif change[0] == 'm':
         self.__undoMove(change)
     elif change[0] == 'ml':
         # Undo move lines
         begin, end, to = change[1]
         count = end - begin
         if begin < to:
             self.__doMoveLines(to - 1, to + count - 1, begin + count - 1)
         else:
             self.__doMoveLines(to, to + count, begin + count)
     elif change[0] == 'n':
         # Undo split lines.
         self.__undoMove(change[2])
         self.parser.backspace(self.penRow + 1, 0)
     elif change[0] == 'v':  # undo paste
         clip = change[1]
         if len(clip) == 1:
             self.parser.deleteRange(self.penRow, self.penCol,
                                     self.penRow + len(clip) - 1,
                                     self.penCol + len(clip[-1]))
         else:
             self.parser.deleteRange(self.penRow, self.penCol,
                                     self.penRow + len(clip) - 1,
                                     len(clip[-1]))
     elif change[0] == 'vb':  # Undo vertical backspace.
         assert False  # Not yet used.
         self.parser.insertBlock(self.penRow, self.penCol, change[1])
         self.penCol += columnWidth(change[1][0])
     elif change[0] == 'vd':  # Undo vertical delete
         self.__doVerticalInsert(change)
     elif change[0] == 'vi':  # Undo vertical insert
         self.__doVerticalDelete(change)
     else:
         app.log.info('ERROR: unknown undo.')
Beispiel #3
0
 def __redoChange(self, change):
     if change[0] == 'b':  # Redo backspace.
         line = self.lines[self.penRow]
         width = columnWidth(change[1])
         self.penCol -= width
         x = self.penCol
         self.lines[self.penRow] = line[:x] + line[x + width:]
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
     elif change[0] == 'bw':  # Redo backspace word.
         line = self.lines[self.penRow]
         width = columnWidth(change[1])
         self.penCol -= width
         x = self.penCol
         self.lines[self.penRow] = line[:x] + line[x + width:]
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
     elif change[0] == 'd':  # Redo delete character.
         line = self.lines[self.penRow]
         x = self.penCol
         self.lines[self.penRow] = line[:x] + line[x +
                                                   columnWidth(change[1]):]
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
     elif change[0] == 'dr':  # Redo delete range.
         self.doDelete(*change[1])
     elif change[0] == 'ds':  # Redo delete selection.
         self.doDeleteSelection()
     elif change[0] == 'f':  # Redo fence.
         pass
     elif change[0] == 'i':  # Redo insert.
         line = self.lines[self.penRow]
         x = self.penCol
         self.lines[self.penRow] = line[:x] + change[1] + line[x:]
         self.penCol += columnWidth(change[1])
         self.goalCol = self.penCol
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
     elif change[0] == 'j':  # Redo join lines (delete \n).
         self.lines[self.penRow] += self.lines[self.penRow + 1]
         del self.lines[self.penRow + 1]
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
     elif change[0] == 'ld':  # Redo line diff.
         lines = []
         index = 0
         for ii in change[1]:
             if type(ii) is type(0):
                 for line in self.lines[index:index + ii]:
                     lines.append(line)
                 index += ii
             elif ii[0] == '+':
                 lines.append(ii[2:])
             elif ii[0] == '-':
                 index += 1
         self.lines = lines
         firstChangedRow = change[1][0] if type(
             change[1][0]) is type(0) else 0
         if self.upperChangedRow > firstChangedRow:
             self.upperChangedRow = firstChangedRow
     elif change[0] == 'm':  # Redo move
         self.__redoMove(change)
     elif change[0] == 'ml':  # Redo move lines
         begin, end, to = change[1]
         self.__doMoveLines(begin, end, to)
     elif change[0] == 'n':  # Redo split lines (insert \n).
         line = self.lines[self.penRow]
         self.lines.insert(self.penRow + 1, line[self.penCol:])
         self.lines[self.penRow] = line[:self.penCol]
         for i in range(max(change[1] - 1, 0)):
             self.lines.insert(self.penRow + 1, u"")
         if self.upperChangedRow > self.penRow:
             self.upperChangedRow = self.penRow
         self.__redoMove(change[2])
     elif change[0] == 'v':  # Redo paste.
         self.insertLines(change[1])
     elif change[0] == 'vb':  # Redo vertical backspace.
         self.penCol -= columnWidth(change[1])
         row = min(self.markerRow, self.penRow)
         rowEnd = max(self.markerRow, self.penRow)
         for i in range(row, rowEnd + 1):
             line = self.lines[i]
             x = self.penCol
             self.lines[
                 self.penRow] = line[:x] + line[x + columnWidth(change[1]):]
         if self.upperChangedRow > row:
             self.upperChangedRow = row
     elif change[0] == 'vd':  # Redo vertical delete.
         self.__doVerticalDelete(change)
     elif change[0] == 'vi':  # Redo vertical insert.
         self.__doVerticalInsert(change)
     else:
         app.log.info('ERROR: unknown redo.')
     return False
Beispiel #4
0
 def __redoChange(self, change):
     if change[0] == 'b':  # Redo backspace.
         self.penRow, self.penCol = self.parser.backspace(
             self.penRow, self.penCol)
     elif change[0] == 'bw':  # Redo backspace word.
         width = columnWidth(change[1])
         self.parser.deleteRange(self.penRow, self.penCol - width,
                                 self.penRow, self.penCol)
         self.penCol -= width
     elif change[0] == 'd':  # Redo delete character.
         self.parser.deleteChar(self.penRow, self.penCol)
     elif change[0] == 'dr':  # Redo delete range.
         self.doDelete(*change[1])
     elif change[0] == 'ds':  # Redo delete selection.
         self.doDeleteSelection()
     elif change[0] == 'f':  # Redo fence.
         pass
     elif change[0] == 'i':  # Redo insert.
         self.parser.insert(self.penRow, self.penCol, change[1])
         self.penCol += columnWidth(change[1])
         self.goalCol = self.penCol
     elif change[0] == 'j':  # Redo join lines (delete \n).
         self.parser.deleteChar(self.penRow, self.penCol)
     elif change[0] == 'ld':  # Redo line diff.
         assert False  # Not used.
         lines = []
         index = 0
         for ii in change[1]:
             if type(ii) is type(0):
                 for line in self.parser.textLines(index, index + ii):
                     lines.append(line)
                 index += ii
             elif ii[0] == '+':
                 lines.append(ii[2:])
             elif ii[0] == '-':
                 index += 1
         self.parser.data = lines.join(u"\n")
         firstChangedRow = change[1][0] if type(
             change[1][0]) is type(0) else 0
     elif change[0] == 'm':  # Redo move
         self.__redoMove(change)
     elif change[0] == 'ml':  # Redo move lines
         begin, end, to = change[1]
         self.__doMoveLines(begin, end, to)
     elif change[0] == 'n':  # Redo split lines (insert \n).
         self.parser.insert(self.penRow, self.penCol, u"\n")
         self.__redoMove(change[2])
     elif change[0] == 'v':  # Redo paste.
         self.insertLines(change[1])
     elif change[0] == 'vb':  # Redo vertical backspace.
         assert False  # Not yet used.
         width = columnWidth(change[1][0])
         self.parser.deleteBlock(self.penRow, self.penCol - width,
                                 self.penRow + len(change[1]), self.penCol)
         self.penCol -= width
     elif change[0] == 'vd':  # Redo vertical delete.
         self.__doVerticalDelete(change)
     elif change[0] == 'vi':  # Redo vertical insert.
         self.__doVerticalInsert(change)
     else:
         app.log.info('ERROR: unknown redo.')
     return False