mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-02 02:59:51 +00:00
fix: delete the **bring back** tree node from the undo container remap (#423)
This commit is contained in:
parent
8fbfea4bda
commit
2f0a3ab92f
4 changed files with 243 additions and 1343 deletions
|
@ -347,6 +347,7 @@ where
|
|||
N: Fn(u8, &mut [T]) -> Vec<T>,
|
||||
T: Clone + Debug + Send + 'static,
|
||||
{
|
||||
println!("Minifying...");
|
||||
std::panic::set_hook(Box::new(|_info| {
|
||||
// ignore panic output
|
||||
// println!("{:?}", _info);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -31,9 +31,7 @@ use std::{
|
|||
ops::Deref,
|
||||
sync::{Arc, Mutex, Weak},
|
||||
};
|
||||
|
||||
use tracing::{debug, error, info, instrument, trace};
|
||||
|
||||
mod tree;
|
||||
pub use tree::TreeHandler;
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ use tracing::{debug_span, info_span, instrument};
|
|||
use crate::{
|
||||
change::get_sys_timestamp,
|
||||
cursor::{AbsolutePosition, Cursor},
|
||||
delta::TreeExternalDiff,
|
||||
event::{Diff, EventTriggerKind},
|
||||
version::Frontiers,
|
||||
ContainerDiff, DocDiff, LoroDoc,
|
||||
|
@ -122,7 +123,7 @@ fn transform_cursor(
|
|||
#[derive(Debug)]
|
||||
pub struct UndoManager {
|
||||
peer: PeerID,
|
||||
container_remap: FxHashMap<ContainerID, ContainerID>,
|
||||
container_remap: Arc<Mutex<FxHashMap<ContainerID, ContainerID>>>,
|
||||
inner: Arc<Mutex<UndoManagerInner>>,
|
||||
}
|
||||
|
||||
|
@ -425,6 +426,8 @@ impl UndoManager {
|
|||
doc, peer,
|
||||
))));
|
||||
let inner_clone = inner.clone();
|
||||
let remap_containers = Arc::new(Mutex::new(FxHashMap::default()));
|
||||
let remap_containers_clone = remap_containers.clone();
|
||||
doc.subscribe_root(Arc::new(move |event| match event.event_meta.by {
|
||||
EventTriggerKind::Local => {
|
||||
// TODO: PERF undo can be significantly faster if we can get
|
||||
|
@ -454,6 +457,23 @@ impl UndoManager {
|
|||
}
|
||||
EventTriggerKind::Import => {
|
||||
let mut inner = inner_clone.try_lock().unwrap();
|
||||
|
||||
for e in event.events {
|
||||
if let Diff::Tree(tree) = &e.diff {
|
||||
for item in &tree.diff {
|
||||
let target = item.target;
|
||||
if let TreeExternalDiff::Create { .. } = &item.action {
|
||||
// If the concurrent event is a create event, it may bring the deleted tree node back,
|
||||
// so we need to remove it from the remap of the container.
|
||||
remap_containers_clone
|
||||
.lock()
|
||||
.unwrap()
|
||||
.remove(&target.associated_meta_container());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner.undo_stack.compose_remote_event(event.events);
|
||||
inner.redo_stack.compose_remote_event(event.events);
|
||||
}
|
||||
|
@ -467,7 +487,7 @@ impl UndoManager {
|
|||
|
||||
UndoManager {
|
||||
peer,
|
||||
container_remap: Default::default(),
|
||||
container_remap: remap_containers,
|
||||
inner,
|
||||
}
|
||||
}
|
||||
|
@ -607,7 +627,7 @@ impl UndoManager {
|
|||
peer: self.peer,
|
||||
counter: span.span,
|
||||
},
|
||||
&mut self.container_remap,
|
||||
&mut self.container_remap.lock().unwrap(),
|
||||
Some(&remote_change_clone),
|
||||
&mut |diff| {
|
||||
info_span!("transform remote diff").in_scope(|| {
|
||||
|
@ -628,7 +648,7 @@ impl UndoManager {
|
|||
cursor,
|
||||
&remote_diff.try_lock().unwrap(),
|
||||
doc,
|
||||
&self.container_remap,
|
||||
&self.container_remap.lock().unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue