mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-06 12:25:03 +00:00
fix: impl a few unimplemented! for movable tree (#335)
This commit is contained in:
parent
e5dfded0f3
commit
ca5f762646
1 changed files with 41 additions and 2 deletions
|
@ -2132,7 +2132,17 @@ impl ListHandler {
|
||||||
impl MovableListHandler {
|
impl MovableListHandler {
|
||||||
pub fn insert(&self, pos: usize, v: impl Into<LoroValue>) -> LoroResult<()> {
|
pub fn insert(&self, pos: usize, v: impl Into<LoroValue>) -> LoroResult<()> {
|
||||||
match &self.inner {
|
match &self.inner {
|
||||||
MaybeDetached::Detached(_) => unimplemented!(),
|
MaybeDetached::Detached(d) => {
|
||||||
|
let mut d = d.lock().unwrap();
|
||||||
|
if pos > d.value.len() {
|
||||||
|
return Err(LoroError::OutOfBound {
|
||||||
|
pos,
|
||||||
|
len: d.value.len(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
d.value.insert(pos, ValueOrHandler::Value(v.into()));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
MaybeDetached::Attached(a) => {
|
MaybeDetached::Attached(a) => {
|
||||||
a.with_txn(|txn| self.insert_with_txn(txn, pos, v.into()))
|
a.with_txn(|txn| self.insert_with_txn(txn, pos, v.into()))
|
||||||
}
|
}
|
||||||
|
@ -2183,7 +2193,24 @@ impl MovableListHandler {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mov(&self, from: usize, to: usize) -> LoroResult<()> {
|
pub fn mov(&self, from: usize, to: usize) -> LoroResult<()> {
|
||||||
match &self.inner {
|
match &self.inner {
|
||||||
MaybeDetached::Detached(_) => unimplemented!(),
|
MaybeDetached::Detached(d) => {
|
||||||
|
let mut d = d.lock().unwrap();
|
||||||
|
if from >= d.value.len() {
|
||||||
|
return Err(LoroError::OutOfBound {
|
||||||
|
pos: from,
|
||||||
|
len: d.value.len(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if to >= d.value.len() {
|
||||||
|
return Err(LoroError::OutOfBound {
|
||||||
|
pos: to,
|
||||||
|
len: d.value.len(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let v = d.value.remove(from);
|
||||||
|
d.value.insert(to, v);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
MaybeDetached::Attached(a) => a.with_txn(|txn| self.move_with_txn(txn, from, to)),
|
MaybeDetached::Attached(a) => a.with_txn(|txn| self.move_with_txn(txn, from, to)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2297,6 +2324,12 @@ impl MovableListHandler {
|
||||||
match &self.inner {
|
match &self.inner {
|
||||||
MaybeDetached::Detached(d) => {
|
MaybeDetached::Detached(d) => {
|
||||||
let mut d = d.lock().unwrap();
|
let mut d = d.lock().unwrap();
|
||||||
|
if pos > d.value.len() {
|
||||||
|
return Err(LoroError::OutOfBound {
|
||||||
|
pos,
|
||||||
|
len: d.value.len(),
|
||||||
|
});
|
||||||
|
}
|
||||||
d.value
|
d.value
|
||||||
.insert(pos, ValueOrHandler::Handler(child.to_handler()));
|
.insert(pos, ValueOrHandler::Handler(child.to_handler()));
|
||||||
Ok(child)
|
Ok(child)
|
||||||
|
@ -2347,6 +2380,12 @@ impl MovableListHandler {
|
||||||
match &self.inner {
|
match &self.inner {
|
||||||
MaybeDetached::Detached(d) => {
|
MaybeDetached::Detached(d) => {
|
||||||
let mut d = d.lock().unwrap();
|
let mut d = d.lock().unwrap();
|
||||||
|
if index >= d.value.len() {
|
||||||
|
return Err(LoroError::OutOfBound {
|
||||||
|
pos: index,
|
||||||
|
len: d.value.len(),
|
||||||
|
});
|
||||||
|
}
|
||||||
d.value[index] = ValueOrHandler::Value(value.into());
|
d.value[index] = ValueOrHandler::Value(value.into());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue