Correctly redo all undone edits after undoing in multi-buffer
When undoing edits performed in the multi-buffer, we also undo subsequent edits that may have occurred outside of the multi-buffer. This commit makes us redo those edits as well. Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
c5b0b5f902
commit
93eb005f74
2 changed files with 26 additions and 10 deletions
|
@ -557,10 +557,14 @@ impl MultiBuffer {
|
||||||
|
|
||||||
while let Some(transaction) = self.history.pop_undo() {
|
while let Some(transaction) = self.history.pop_undo() {
|
||||||
let mut undone = false;
|
let mut undone = false;
|
||||||
for (buffer_id, buffer_transaction_id) in &transaction.buffer_transactions {
|
for (buffer_id, buffer_transaction_id) in &mut transaction.buffer_transactions {
|
||||||
if let Some(BufferState { buffer, .. }) = self.buffers.borrow().get(&buffer_id) {
|
if let Some(BufferState { buffer, .. }) = self.buffers.borrow().get(&buffer_id) {
|
||||||
undone |= buffer.update(cx, |buf, cx| {
|
undone |= buffer.update(cx, |buffer, cx| {
|
||||||
buf.undo_to_transaction(*buffer_transaction_id, 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, cx)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -580,10 +584,14 @@ impl MultiBuffer {
|
||||||
|
|
||||||
while let Some(transaction) = self.history.pop_redo() {
|
while let Some(transaction) = self.history.pop_redo() {
|
||||||
let mut redone = false;
|
let mut redone = false;
|
||||||
for (buffer_id, buffer_transaction_id) in &transaction.buffer_transactions {
|
for (buffer_id, buffer_transaction_id) in &mut transaction.buffer_transactions {
|
||||||
if let Some(BufferState { buffer, .. }) = self.buffers.borrow().get(&buffer_id) {
|
if let Some(BufferState { buffer, .. }) = self.buffers.borrow().get(&buffer_id) {
|
||||||
redone |= buffer.update(cx, |buf, cx| {
|
redone |= buffer.update(cx, |buffer, cx| {
|
||||||
buf.redo_to_transaction(*buffer_transaction_id, cx)
|
let redo_to = *buffer_transaction_id;
|
||||||
|
if let Some(entry) = buffer.peek_redo_stack() {
|
||||||
|
*buffer_transaction_id = entry.transaction_id();
|
||||||
|
}
|
||||||
|
buffer.redo_to_transaction(redo_to, cx)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2274,21 +2282,21 @@ impl History {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pop_undo(&mut self) -> Option<&Transaction> {
|
fn pop_undo(&mut self) -> Option<&mut Transaction> {
|
||||||
assert_eq!(self.transaction_depth, 0);
|
assert_eq!(self.transaction_depth, 0);
|
||||||
if let Some(transaction) = self.undo_stack.pop() {
|
if let Some(transaction) = self.undo_stack.pop() {
|
||||||
self.redo_stack.push(transaction);
|
self.redo_stack.push(transaction);
|
||||||
self.redo_stack.last()
|
self.redo_stack.last_mut()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pop_redo(&mut self) -> Option<&Transaction> {
|
fn pop_redo(&mut self) -> Option<&mut Transaction> {
|
||||||
assert_eq!(self.transaction_depth, 0);
|
assert_eq!(self.transaction_depth, 0);
|
||||||
if let Some(transaction) = self.redo_stack.pop() {
|
if let Some(transaction) = self.redo_stack.pop() {
|
||||||
self.undo_stack.push(transaction);
|
self.undo_stack.push(transaction);
|
||||||
self.undo_stack.last()
|
self.undo_stack.last_mut()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,10 @@ pub struct Transaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HistoryEntry {
|
impl HistoryEntry {
|
||||||
|
pub fn transaction_id(&self) -> TransactionId {
|
||||||
|
self.transaction.id
|
||||||
|
}
|
||||||
|
|
||||||
fn push_edit(&mut self, edit: &EditOperation) {
|
fn push_edit(&mut self, edit: &EditOperation) {
|
||||||
self.transaction.edit_ids.push(edit.timestamp.local());
|
self.transaction.edit_ids.push(edit.timestamp.local());
|
||||||
self.transaction.end.observe(edit.timestamp.local());
|
self.transaction.end.observe(edit.timestamp.local());
|
||||||
|
@ -1150,6 +1154,10 @@ impl Buffer {
|
||||||
self.history.undo_stack.last()
|
self.history.undo_stack.last()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn peek_redo_stack(&self) -> Option<&HistoryEntry> {
|
||||||
|
self.history.redo_stack.last()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn start_transaction(&mut self) -> Option<TransactionId> {
|
pub fn start_transaction(&mut self) -> Option<TransactionId> {
|
||||||
self.start_transaction_at(Instant::now())
|
self.start_transaction_at(Instant::now())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue