mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-28 17:21:40 +03:00
Don't push empty transactions onto the undo stack
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
77af9ef902
commit
d36805c464
@ -318,10 +318,15 @@ impl History {
|
||||
assert_ne!(self.transaction_depth, 0);
|
||||
self.transaction_depth -= 1;
|
||||
if self.transaction_depth == 0 {
|
||||
let transaction = self.undo_stack.last_mut().unwrap();
|
||||
transaction.selections_after = selections;
|
||||
transaction.last_edit_at = now;
|
||||
Some(transaction)
|
||||
if self.undo_stack.last().unwrap().ranges.is_empty() {
|
||||
self.undo_stack.pop();
|
||||
None
|
||||
} else {
|
||||
let transaction = self.undo_stack.last_mut().unwrap();
|
||||
transaction.selections_after = selections;
|
||||
transaction.last_edit_at = now;
|
||||
Some(transaction)
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -3933,6 +3938,11 @@ mod tests {
|
||||
assert_eq!(buffer.text(), "ab2cde6");
|
||||
assert_eq!(buffer.selection_ranges(set_id).unwrap(), vec![3..3]);
|
||||
|
||||
buffer.start_transaction_at(None, now).unwrap();
|
||||
buffer.end_transaction_at(None, now, cx).unwrap();
|
||||
buffer.undo(cx);
|
||||
assert_eq!(buffer.text(), "12cde6");
|
||||
|
||||
buffer
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user