From e225fbbf64e4047ae99d56eed9896a81e9302eee Mon Sep 17 00:00:00 2001 From: adz Date: Fri, 21 Aug 2026 12:22:33 +0200 Subject: [PATCH] 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 --- reflection-doc/src/document.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/reflection-doc/src/document.rs b/reflection-doc/src/document.rs index b2df83d5..9e418052 100644 --- a/reflection-doc/src/document.rs +++ b/reflection-doc/src/document.rs @@ -538,7 +538,8 @@ mod imp { obj, #[upgrade_or_default] move |stack_type, _, _| { - // The `loro::UndoManager` holds internal locks, so we can't update the `Document.can_undo/can_redo` property inline + // The `loro::UndoManager` holds internal locks, so we can't update the + // `Document.can_undo/can_redo` property inline obj.main_context().spawn(clone!( #[weak] obj, @@ -589,10 +590,12 @@ mod imp { #[weak] obj, move |_, _, mut meta| { - *obj.imp().final_insert_cursor.write().unwrap() = + // Popping from the Vec is LIFO, so we pop the selection bounds first and then + // the insert cursor (reverse of how they've been added) + *obj.imp().final_selection_bound.write().unwrap() = meta.cursors.pop().map(|cursor| cursor.cursor); - *obj.imp().final_selection_bound.write().unwrap() = + *obj.imp().final_insert_cursor.write().unwrap() = meta.cursors.pop().map(|cursor| cursor.cursor); } ))));