mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-05 12:14:43 +00:00
chore: revert
This commit is contained in:
parent
477c4f6216
commit
ca51a78bac
3 changed files with 40 additions and 25 deletions
|
@ -55,21 +55,32 @@ impl UndoManager {
|
|||
|
||||
/// Set the listener for push events.
|
||||
/// The listener will be called when a new undo/redo item is pushed into the stack.
|
||||
pub fn set_on_push(&self, on_push: Arc<dyn OnPush>) {
|
||||
self.0
|
||||
.write()
|
||||
.unwrap()
|
||||
.set_on_push(Box::new(move |u, c, e| {
|
||||
loro::UndoItemMeta::from(on_push.on_push(u, c, e.map(|x| x.into())))
|
||||
}));
|
||||
pub fn set_on_push(&self, on_push: Option<Arc<dyn OnPush>>) {
|
||||
if let Some(on_push) = on_push {
|
||||
self.0
|
||||
.write()
|
||||
.unwrap()
|
||||
.set_on_push(Some(Box::new(move |u, c, e| {
|
||||
loro::UndoItemMeta::from(on_push.on_push(u, c, e.map(|x| x.into())))
|
||||
})));
|
||||
} else {
|
||||
self.0.write().unwrap().set_on_push(None);
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the listener for pop events.
|
||||
/// The listener will be called when an undo/redo item is popped from the stack.
|
||||
pub fn set_on_pop(&self, on_pop: Arc<dyn OnPop>) {
|
||||
self.0.write().unwrap().set_on_pop(Box::new(move |u, c, m| {
|
||||
on_pop.on_pop(u, c, UndoItemMeta::from(m))
|
||||
}))
|
||||
pub fn set_on_pop(&self, on_pop: Option<Arc<dyn OnPop>>) {
|
||||
if let Some(on_pop) = on_pop {
|
||||
self.0
|
||||
.write()
|
||||
.unwrap()
|
||||
.set_on_pop(Some(Box::new(move |u, c, m| {
|
||||
on_pop.on_pop(u, c, UndoItemMeta::from(m))
|
||||
})));
|
||||
} else {
|
||||
self.0.write().unwrap().set_on_pop(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2699,16 +2699,20 @@ impl UndoManager {
|
|||
|
||||
/// Set the listener for push events.
|
||||
/// The listener will be called when a new undo/redo item is pushed into the stack.
|
||||
pub fn set_on_push(&mut self, on_push: OnPush) {
|
||||
self.0.set_on_push(Some(Box::new(move |u, c, e| {
|
||||
on_push(u, c, e.map(|x| x.into()))
|
||||
})))
|
||||
pub fn set_on_push(&mut self, on_push: Option<OnPush>) {
|
||||
if let Some(on_push) = on_push {
|
||||
self.0.set_on_push(Some(Box::new(move |u, c, e| {
|
||||
on_push(u, c, e.map(|x| x.into()))
|
||||
})));
|
||||
} else {
|
||||
self.0.set_on_push(None);
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the listener for pop events.
|
||||
/// The listener will be called when an undo/redo item is popped from the stack.
|
||||
pub fn set_on_pop(&mut self, on_pop: OnPop) {
|
||||
self.0.set_on_pop(Some(on_pop));
|
||||
pub fn set_on_pop(&mut self, on_pop: Option<OnPop>) {
|
||||
self.0.set_on_pop(on_pop);
|
||||
}
|
||||
|
||||
/// Clear the undo stack and the redo stack
|
||||
|
|
|
@ -1536,17 +1536,17 @@ fn undo_manager_events() -> anyhow::Result<()> {
|
|||
let pop_count_clone = pop_count.clone();
|
||||
let popped_value = Arc::new(Mutex::new(LoroValue::Null));
|
||||
let popped_value_clone = popped_value.clone();
|
||||
undo.set_on_push(Box::new(move |_source, span, _| {
|
||||
undo.set_on_push(Some(Box::new(move |_source, span, _| {
|
||||
push_count_clone.fetch_add(1, atomic::Ordering::SeqCst);
|
||||
UndoItemMeta {
|
||||
value: LoroValue::I64(span.start as i64),
|
||||
cursors: Default::default(),
|
||||
}
|
||||
}));
|
||||
undo.set_on_pop(Box::new(move |_source, _span, v| {
|
||||
})));
|
||||
undo.set_on_pop(Some(Box::new(move |_source, _span, v| {
|
||||
pop_count_clone.fetch_add(1, atomic::Ordering::SeqCst);
|
||||
*popped_value_clone.try_lock().unwrap() = v.value;
|
||||
}));
|
||||
})));
|
||||
text.insert(0, "Hello")?;
|
||||
assert_eq!(push_count.load(atomic::Ordering::SeqCst), 0);
|
||||
doc.commit();
|
||||
|
@ -1583,19 +1583,19 @@ fn undo_transform_cursor_position() -> anyhow::Result<()> {
|
|||
let mut undo = UndoManager::new(&doc);
|
||||
let cursors: Arc<Mutex<Vec<Cursor>>> = Arc::new(Mutex::new(Vec::new()));
|
||||
let cursors_clone = cursors.clone();
|
||||
undo.set_on_push(Box::new(move |_, _, _| {
|
||||
undo.set_on_push(Some(Box::new(move |_, _, _| {
|
||||
let mut ans = UndoItemMeta::new();
|
||||
let cursors = cursors_clone.try_lock().unwrap();
|
||||
for c in cursors.iter() {
|
||||
ans.add_cursor(c)
|
||||
}
|
||||
ans
|
||||
}));
|
||||
})));
|
||||
let popped_cursors = Arc::new(Mutex::new(Vec::new()));
|
||||
let popped_cursors_clone = popped_cursors.clone();
|
||||
undo.set_on_pop(Box::new(move |_, _, meta| {
|
||||
undo.set_on_pop(Some(Box::new(move |_, _, meta| {
|
||||
*popped_cursors_clone.try_lock().unwrap() = meta.cursors;
|
||||
}));
|
||||
})));
|
||||
text.insert(0, "Hello world!")?;
|
||||
doc.commit();
|
||||
cursors
|
||||
|
|
Loading…
Reference in a new issue