Store the oldest transaction id for each excerpted buffer in multi-buffer transactions

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Nathan Sobo 2022-02-10 09:14:39 -07:00
parent 9936bb2efa
commit c5b0b5f902

View file

@ -3,7 +3,7 @@ mod anchor;
pub use anchor::{Anchor, AnchorRangeExt}; pub use anchor::{Anchor, AnchorRangeExt};
use anyhow::Result; use anyhow::Result;
use clock::ReplicaId; use clock::ReplicaId;
use collections::{Bound, HashMap, HashSet}; use collections::{Bound, HashMap};
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task}; use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
pub use language::Completion; pub use language::Completion;
use language::{ use language::{
@ -60,7 +60,7 @@ pub enum CharKind {
struct Transaction { struct Transaction {
id: TransactionId, id: TransactionId,
buffer_transactions: HashSet<(usize, text::TransactionId)>, buffer_transactions: HashMap<usize, text::TransactionId>,
first_edit_at: Instant, first_edit_at: Instant,
last_edit_at: Instant, last_edit_at: Instant,
suppress_grouping: bool, suppress_grouping: bool,
@ -425,12 +425,12 @@ impl MultiBuffer {
return buffer.update(cx, |buffer, cx| buffer.end_transaction_at(now, cx)); return buffer.update(cx, |buffer, cx| buffer.end_transaction_at(now, cx));
} }
let mut buffer_transactions = HashSet::default(); let mut buffer_transactions = HashMap::default();
for BufferState { buffer, .. } in self.buffers.borrow().values() { for BufferState { buffer, .. } in self.buffers.borrow().values() {
if let Some(transaction_id) = if let Some(transaction_id) =
buffer.update(cx, |buffer, cx| buffer.end_transaction_at(now, cx)) buffer.update(cx, |buffer, cx| buffer.end_transaction_at(now, cx))
{ {
buffer_transactions.insert((buffer.id(), transaction_id)); buffer_transactions.insert(buffer.id(), transaction_id);
} }
} }
@ -2227,7 +2227,7 @@ impl History {
fn end_transaction( fn end_transaction(
&mut self, &mut self,
now: Instant, now: Instant,
buffer_transactions: HashSet<(usize, TransactionId)>, buffer_transactions: HashMap<usize, TransactionId>,
) -> bool { ) -> bool {
assert_ne!(self.transaction_depth, 0); assert_ne!(self.transaction_depth, 0);
self.transaction_depth -= 1; self.transaction_depth -= 1;
@ -2238,7 +2238,12 @@ impl History {
} else { } else {
let transaction = self.undo_stack.last_mut().unwrap(); let transaction = self.undo_stack.last_mut().unwrap();
transaction.last_edit_at = now; transaction.last_edit_at = now;
transaction.buffer_transactions.extend(buffer_transactions); for (buffer_id, transaction_id) in buffer_transactions {
transaction
.buffer_transactions
.entry(buffer_id)
.or_insert(transaction_id);
}
true true
} }
} else { } else {
@ -2312,6 +2317,14 @@ impl History {
if let Some(transaction) = transactions_to_merge.last() { if let Some(transaction) = transactions_to_merge.last() {
last_transaction.last_edit_at = transaction.last_edit_at; last_transaction.last_edit_at = transaction.last_edit_at;
} }
for to_merge in transactions_to_merge {
for (buffer_id, transaction_id) in &to_merge.buffer_transactions {
last_transaction
.buffer_transactions
.entry(*buffer_id)
.or_insert(*transaction_id);
}
}
} }
self.undo_stack.truncate(new_len); self.undo_stack.truncate(new_len);