mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-05 06:30:28 +09:00
Remove backup when buffer becomes unmodified
We should cancel previously requested periodic backup (and remove this backup if it has already been created) not only when saving or closing the buffer but also in other cases when the buffer's state changes from modified to unmodified, i.e. when the user undoes all unsaved changes. Otherwise, if micro terminates abnormally before the buffer is closed, this backup will not get removed (so next time micro will suggest the user to recover this file), even though all changes to this file were successfully saved.
This commit is contained in:
@@ -152,6 +152,12 @@ func (b *SharedBuffer) setModified() {
|
||||
b.calcHash(&buff)
|
||||
b.isModified = buff != b.origHash
|
||||
}
|
||||
|
||||
if b.isModified {
|
||||
b.RequestBackup()
|
||||
} else {
|
||||
b.CancelBackup()
|
||||
}
|
||||
}
|
||||
|
||||
// calcHash calculates md5 hash of all lines in the buffer
|
||||
@@ -525,8 +531,6 @@ func (b *Buffer) Insert(start Loc, text string) {
|
||||
b.EventHandler.cursors = b.cursors
|
||||
b.EventHandler.active = b.curCursor
|
||||
b.EventHandler.Insert(start, text)
|
||||
|
||||
b.RequestBackup()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -536,8 +540,6 @@ func (b *Buffer) Remove(start, end Loc) {
|
||||
b.EventHandler.cursors = b.cursors
|
||||
b.EventHandler.active = b.curCursor
|
||||
b.EventHandler.Remove(start, end)
|
||||
|
||||
b.RequestBackup()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user