Skip to content

Commit 2d97eff

Browse files
Prevent a crash is UndoBuffer is modified but no undo was done.
If the list is empty consider it was not modified
1 parent b86f674 commit 2d97eff

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/beamui/core/undo.d

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class UndoBuffer
101101
/// True if the content has been changed since last `saved()` or `clear()` call
102102
@property bool modified() const
103103
{
104-
return _savedState !is _undoStack.back;
104+
return !_undoStack.empty && _savedState !is _undoStack.back;
105105
}
106106

107107
/// True if saved state is in redo stack
@@ -110,3 +110,12 @@ class UndoBuffer
110110
return _savedState && _savedState in _redoStack;
111111
}
112112
}
113+
114+
unittest
115+
{
116+
auto buffer = new UndoBuffer;
117+
assert(!buffer.modified);
118+
assert(!buffer.savedInRedo);
119+
assert(buffer.undo() is null);
120+
assert(buffer.redo() is null);
121+
}

0 commit comments

Comments
 (0)