Remove trailing checkpoints when user does some editing on the current chackpoint

This commit is contained in:
Kovid Goyal 2014-02-02 13:14:57 +05:30
parent 40621fe116
commit deb87d7700
2 changed files with 12 additions and 7 deletions

View File

@ -1102,6 +1102,8 @@ class Boss(QObject):
self.apply_current_editor_state() self.apply_current_editor_state()
if is_modified: if is_modified:
self.set_modified() self.set_modified()
self.global_undo.truncate()
self.update_global_history_actions()
# }}} # }}}
def apply_current_editor_state(self): def apply_current_editor_state(self):

View File

@ -81,13 +81,7 @@ class GlobalUndoHistory(QAbstractListModel):
self.pos = 0 self.pos = 0
self.reset() self.reset()
def add_savepoint(self, new_container, message): def truncate(self):
try:
self.states[self.pos].rewind_message = self.states[self.pos].message
self.states[self.pos].message = message
except IndexError:
raise IndexError('The checkpoint stack has an incorrect position pointer. This should never happen: self.pos = %r, len(self.states) = %r' % (
self.pos, len(self.states)))
extra = self.states[self.pos+1:] extra = self.states[self.pos+1:]
if extra: if extra:
self.beginRemoveRows(ROOT, self.pos+1, len(self.states) - 1) self.beginRemoveRows(ROOT, self.pos+1, len(self.states) - 1)
@ -95,6 +89,15 @@ class GlobalUndoHistory(QAbstractListModel):
self.states = self.states[:self.pos+1] self.states = self.states[:self.pos+1]
if extra: if extra:
self.endRemoveRows() self.endRemoveRows()
def add_savepoint(self, new_container, message):
try:
self.states[self.pos].rewind_message = self.states[self.pos].message
self.states[self.pos].message = message
except IndexError:
raise IndexError('The checkpoint stack has an incorrect position pointer. This should never happen: self.pos = %r, len(self.states) = %r' % (
self.pos, len(self.states)))
self.truncate()
self.beginInsertRows(ROOT, self.pos+1, self.pos+1) self.beginInsertRows(ROOT, self.pos+1, self.pos+1)
self.states.append(State(new_container)) self.states.append(State(new_container))
self.pos += 1 self.pos += 1