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:
Dmytro Maluka
2025-08-03 16:17:53 +02:00
parent 2c010afbe4
commit 7aa495fd3f

View File

@@ -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()
}
}