use crate::{
marks::{Mark, MarkSet},
text_value::ConcreteTextValue,
ObjId, Prop, Value,
};
use core::fmt::Debug;
use std::fmt;
use crate::sequence_tree::SequenceTree;
#[derive(Debug, Clone, PartialEq)]
pub struct Patch {
pub obj: ObjId,
pub path: Vec<(ObjId, Prop)>,
pub action: PatchAction,
}
impl Patch {
pub(crate) fn has(&self, obj: &ObjId, recursive: bool) -> bool {
&self.obj == obj || (recursive && self.path.iter().any(|(o, _)| o == obj))
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum PatchAction {
PutMap {
key: String,
value: (Value<'static>, ObjId),
conflict: bool,
},
PutSeq {
index: usize,
value: (Value<'static>, ObjId),
conflict: bool,
},
Insert {
index: usize,
values: SequenceTree<(Value<'static>, ObjId, bool)>,
},
SpliceText {
index: usize,
value: ConcreteTextValue,
marks: Option<MarkSet>,
},
Increment {
prop: Prop,
value: i64,
},
Conflict {
prop: Prop,
},
DeleteMap { key: String },
DeleteSeq { index: usize, length: usize },
Mark { marks: Vec<Mark> },
}
impl fmt::Display for PatchAction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}