Simplify undo_to_transaction
and redo_to_transaction
We don't need to mutate the history anymore now that we render pending renames with a block decoration.
This commit is contained in:
parent
b573a39cbc
commit
cf7cc83f85
4 changed files with 29 additions and 141 deletions
|
@ -27,7 +27,6 @@ use text::{
|
|||
AnchorRangeExt as _, Edit, Point, PointUtf16, TextSummary,
|
||||
};
|
||||
use theme::SyntaxTheme;
|
||||
use util::CowMut;
|
||||
|
||||
const NEWLINES: &'static [u8] = &[b'\n'; u8::MAX as usize];
|
||||
|
||||
|
@ -566,7 +565,7 @@ impl MultiBuffer {
|
|||
if let Some(entry) = buffer.peek_undo_stack() {
|
||||
*buffer_transaction_id = entry.transaction_id();
|
||||
}
|
||||
buffer.undo_to_transaction(undo_to, true, cx)
|
||||
buffer.undo_to_transaction(undo_to, cx)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -579,35 +578,6 @@ impl MultiBuffer {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn undo_to_transaction(
|
||||
&mut self,
|
||||
transaction_id: TransactionId,
|
||||
push_redo: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> bool {
|
||||
if let Some(buffer) = self.as_singleton() {
|
||||
return buffer.update(cx, |buffer, cx| {
|
||||
buffer.undo_to_transaction(transaction_id, push_redo, cx)
|
||||
});
|
||||
}
|
||||
|
||||
let mut undone = false;
|
||||
for transaction in &mut *self.history.remove_from_undo(transaction_id, push_redo) {
|
||||
for (buffer_id, buffer_transaction_id) in &mut transaction.buffer_transactions {
|
||||
if let Some(BufferState { buffer, .. }) = self.buffers.borrow().get(&buffer_id) {
|
||||
undone |= buffer.update(cx, |buffer, cx| {
|
||||
let undo_to = *buffer_transaction_id;
|
||||
if let Some(entry) = buffer.peek_undo_stack() {
|
||||
*buffer_transaction_id = entry.transaction_id();
|
||||
}
|
||||
buffer.undo_to_transaction(undo_to, true, cx)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
undone
|
||||
}
|
||||
|
||||
pub fn redo(&mut self, cx: &mut ModelContext<Self>) -> Option<TransactionId> {
|
||||
if let Some(buffer) = self.as_singleton() {
|
||||
return buffer.update(cx, |buffer, cx| buffer.redo(cx));
|
||||
|
@ -622,7 +592,7 @@ impl MultiBuffer {
|
|||
if let Some(entry) = buffer.peek_redo_stack() {
|
||||
*buffer_transaction_id = entry.transaction_id();
|
||||
}
|
||||
buffer.redo_to_transaction(redo_to, true, cx)
|
||||
buffer.redo_to_transaction(redo_to, cx)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2345,31 +2315,6 @@ impl History {
|
|||
}
|
||||
}
|
||||
|
||||
fn remove_from_undo(
|
||||
&mut self,
|
||||
transaction_id: TransactionId,
|
||||
push_redo: bool,
|
||||
) -> CowMut<[Transaction]> {
|
||||
assert_eq!(self.transaction_depth, 0);
|
||||
|
||||
if let Some(entry_ix) = self
|
||||
.undo_stack
|
||||
.iter()
|
||||
.rposition(|transaction| transaction.id == transaction_id)
|
||||
{
|
||||
let transactions = self.undo_stack.drain(entry_ix..).rev();
|
||||
if push_redo {
|
||||
let redo_stack_start_len = self.redo_stack.len();
|
||||
self.redo_stack.extend(transactions);
|
||||
CowMut::Borrowed(&mut self.redo_stack[redo_stack_start_len..])
|
||||
} else {
|
||||
CowMut::Owned(transactions.collect())
|
||||
}
|
||||
} else {
|
||||
CowMut::Owned(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
fn pop_redo(&mut self) -> Option<&mut Transaction> {
|
||||
assert_eq!(self.transaction_depth, 0);
|
||||
if let Some(transaction) = self.redo_stack.pop() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue