Merge pull request #1032 from zed-industries/clear-redo-stack-on-edit

Clear redo stack on edit
This commit is contained in:
Antonio Scandurra
2022-05-23 08:25:38 +02:00
committed by GitHub
3 changed files with 24 additions and 0 deletions
+12
View File
@@ -2479,6 +2479,7 @@ impl History {
self.undo_stack.pop();
false
} else {
self.redo_stack.clear();
let transaction = self.undo_stack.last_mut().unwrap();
transaction.last_edit_at = now;
for (buffer_id, transaction_id) in buffer_transactions {
@@ -2511,6 +2512,7 @@ impl History {
};
if !transaction.buffer_transactions.is_empty() {
self.undo_stack.push(transaction);
self.redo_stack.clear();
}
}
@@ -3935,6 +3937,16 @@ mod tests {
buffer_1.update(cx, |buffer_1, cx| buffer_1.redo(cx));
assert_eq!(multibuffer.read(cx).text(), "ABCD1234\nAB5678");
// Redo stack gets cleared after an edit.
now += 2 * group_interval;
multibuffer.start_transaction_at(now, cx);
multibuffer.edit([(0..0, "X")], cx);
multibuffer.end_transaction_at(now, cx);
assert_eq!(multibuffer.read(cx).text(), "XABCD1234\nAB5678");
multibuffer.redo(cx);
assert_eq!(multibuffer.read(cx).text(), "XABCD1234\nAB5678");
multibuffer.undo(cx);
assert_eq!(multibuffer.read(cx).text(), "ABCD1234\nAB5678");
multibuffer.undo(cx);
assert_eq!(multibuffer.read(cx).text(), "1234\n5678");
});
+10
View File
@@ -529,6 +529,16 @@ fn test_history() {
assert!(buffer.end_transaction_at(now).is_none());
buffer.undo();
assert_eq!(buffer.text(), "12cde6");
// Redo stack gets cleared after performing an edit.
buffer.edit([(0..0, "X")]);
assert_eq!(buffer.text(), "X12cde6");
buffer.redo();
assert_eq!(buffer.text(), "X12cde6");
buffer.undo();
assert_eq!(buffer.text(), "12cde6");
buffer.undo();
assert_eq!(buffer.text(), "123456");
}
#[test]
+2
View File
@@ -216,6 +216,7 @@ impl History {
self.undo_stack.pop();
None
} else {
self.redo_stack.clear();
let entry = self.undo_stack.last_mut().unwrap();
entry.last_edit_at = now;
Some(entry)
@@ -276,6 +277,7 @@ impl History {
last_edit_at: now,
suppress_grouping: false,
});
self.redo_stack.clear();
}
fn push_undo(&mut self, op_id: clock::Local) {