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
1 changed files with 14 additions and 4 deletions
|
@ -318,10 +318,15 @@ impl History {
|
||||||
assert_ne!(self.transaction_depth, 0);
|
assert_ne!(self.transaction_depth, 0);
|
||||||
self.transaction_depth -= 1;
|
self.transaction_depth -= 1;
|
||||||
if self.transaction_depth == 0 {
|
if self.transaction_depth == 0 {
|
||||||
let transaction = self.undo_stack.last_mut().unwrap();
|
if self.undo_stack.last().unwrap().ranges.is_empty() {
|
||||||
transaction.selections_after = selections;
|
self.undo_stack.pop();
|
||||||
transaction.last_edit_at = now;
|
None
|
||||||
Some(transaction)
|
} else {
|
||||||
|
let transaction = self.undo_stack.last_mut().unwrap();
|
||||||
|
transaction.selections_after = selections;
|
||||||
|
transaction.last_edit_at = now;
|
||||||
|
Some(transaction)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -3933,6 +3938,11 @@ mod tests {
|
||||||
assert_eq!(buffer.text(), "ab2cde6");
|
assert_eq!(buffer.text(), "ab2cde6");
|
||||||
assert_eq!(buffer.selection_ranges(set_id).unwrap(), vec![3..3]);
|
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
|
buffer
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue