Undo temporary edits before performing rename or canceling it

Also, wire up remote renames.
This commit is contained in:
Antonio Scandurra 2022-02-18 11:41:47 +01:00
parent 514d69e83d
commit f9723ae16b
9 changed files with 331 additions and 60 deletions

View file

@ -285,19 +285,31 @@ impl History {
}
}
fn remove_from_undo(&mut self, transaction_id: TransactionId) -> &[HistoryEntry] {
fn remove_from_undo(
&mut self,
transaction_id: TransactionId,
push_redo: bool,
) -> Vec<Transaction> {
assert_eq!(self.transaction_depth, 0);
let redo_stack_start_len = self.redo_stack.len();
let mut transactions = Vec::new();
if let Some(entry_ix) = self
.undo_stack
.iter()
.rposition(|entry| entry.transaction.id == transaction_id)
{
self.redo_stack
.extend(self.undo_stack.drain(entry_ix..).rev());
transactions.extend(
self.undo_stack[entry_ix..]
.iter()
.rev()
.map(|entry| entry.transaction.clone()),
);
let transactions = self.undo_stack.drain(entry_ix..).rev();
if push_redo {
self.redo_stack.extend(transactions);
}
}
&self.redo_stack[redo_stack_start_len..]
transactions
}
fn forget(&mut self, transaction_id: TransactionId) {
@ -327,19 +339,31 @@ impl History {
}
}
fn remove_from_redo(&mut self, transaction_id: TransactionId) -> &[HistoryEntry] {
fn remove_from_redo(
&mut self,
transaction_id: TransactionId,
push_undo: bool,
) -> Vec<Transaction> {
assert_eq!(self.transaction_depth, 0);
let undo_stack_start_len = self.undo_stack.len();
let mut transactions = Vec::new();
if let Some(entry_ix) = self
.redo_stack
.iter()
.rposition(|entry| entry.transaction.id == transaction_id)
{
self.undo_stack
.extend(self.redo_stack.drain(entry_ix..).rev());
transactions.extend(
self.redo_stack[entry_ix..]
.iter()
.rev()
.map(|entry| entry.transaction.clone()),
);
if push_undo {
self.undo_stack
.extend(self.redo_stack.drain(entry_ix..).rev());
}
}
&self.undo_stack[undo_stack_start_len..]
transactions
}
}
@ -1215,14 +1239,12 @@ impl Buffer {
}
}
pub fn undo_to_transaction(&mut self, transaction_id: TransactionId) -> Vec<Operation> {
let transactions = self
.history
.remove_from_undo(transaction_id)
.iter()
.map(|entry| entry.transaction.clone())
.collect::<Vec<_>>();
pub fn undo_to_transaction(
&mut self,
transaction_id: TransactionId,
push_redo: bool,
) -> Vec<Operation> {
let transactions = self.history.remove_from_undo(transaction_id, push_redo);
transactions
.into_iter()
.map(|transaction| self.undo_or_redo(transaction).unwrap())
@ -1244,14 +1266,12 @@ impl Buffer {
}
}
pub fn redo_to_transaction(&mut self, transaction_id: TransactionId) -> Vec<Operation> {
let transactions = self
.history
.remove_from_redo(transaction_id)
.iter()
.map(|entry| entry.transaction.clone())
.collect::<Vec<_>>();
pub fn redo_to_transaction(
&mut self,
transaction_id: TransactionId,
push_undo: bool,
) -> Vec<Operation> {
let transactions = self.history.remove_from_redo(transaction_id, push_undo);
transactions
.into_iter()
.map(|transaction| self.undo_or_redo(transaction).unwrap())