Skip to content

Commit e225fbb

Browse files
loro: Correctly pop undo-redo cursor from LIFO vec
This fixes an bug where the insert position & selection bound cursor was incorrectly popped off the vec from Loro's undo/redo manager. Co-authored-by: niklaswimmer <niklas@viric.eu>
1 parent 7e17039 commit e225fbb

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

reflection-doc/src/document.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ mod imp {
538538
obj,
539539
#[upgrade_or_default]
540540
move |stack_type, _, _| {
541-
// The `loro::UndoManager` holds internal locks, so we can't update the `Document.can_undo/can_redo` property inline
541+
// The `loro::UndoManager` holds internal locks, so we can't update the
542+
// `Document.can_undo/can_redo` property inline
542543
obj.main_context().spawn(clone!(
543544
#[weak]
544545
obj,
@@ -589,10 +590,12 @@ mod imp {
589590
#[weak]
590591
obj,
591592
move |_, _, mut meta| {
592-
*obj.imp().final_insert_cursor.write().unwrap() =
593+
// Popping from the Vec is LIFO, so we pop the selection bounds first and then
594+
// the insert cursor (reverse of how they've been added)
595+
*obj.imp().final_selection_bound.write().unwrap() =
593596
meta.cursors.pop().map(|cursor| cursor.cursor);
594597

595-
*obj.imp().final_selection_bound.write().unwrap() =
598+
*obj.imp().final_insert_cursor.write().unwrap() =
596599
meta.cursors.pop().map(|cursor| cursor.cursor);
597600
}
598601
))));

0 commit comments

Comments
 (0)