From 7aa495fd3f824250e8e181247e6d79169b374c9d Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Sun, 3 Aug 2025 16:17:53 +0200 Subject: [PATCH] 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. --- internal/buffer/buffer.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index bc33abfd..72f6a8b8 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -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() } }