Improve compact diff API #24
3 changed files with 7 additions and 22 deletions
Rename file
commit
c0aacc06d9
|
|
@ -1,6 +1,5 @@
|
||||||
mod edited_text;
|
mod edited_text;
|
||||||
mod operation;
|
mod operation;
|
||||||
mod transport;
|
|
||||||
mod utils;
|
mod utils;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
pub mod change_set;
|
||||||
pub mod cursor_position;
|
pub mod cursor_position;
|
||||||
pub mod history;
|
pub mod history;
|
||||||
pub mod side;
|
pub mod side;
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,15 @@ use serde::{
|
||||||
de::{self, Deserializer, Visitor},
|
de::{self, Deserializer, Visitor},
|
||||||
ser::Serializer,
|
ser::Serializer,
|
||||||
};
|
};
|
||||||
|
#[cfg(feature = "wasm")]
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
use crate::{CursorPosition, Tokenizer, operation_transformation::Operation};
|
use crate::{Tokenizer, operation_transformation::Operation};
|
||||||
|
|
||||||
|
/// A serializable representation of the changes made to a text document
|
||||||
|
/// without the original text.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
pub enum SimpleOperation {
|
enum SimpleOperation {
|
||||||
Equal { length: usize },
|
Equal { length: usize },
|
||||||
Insert { text: String },
|
Insert { text: String },
|
||||||
Delete { length: usize },
|
Delete { length: usize },
|
||||||
|
|
@ -183,22 +187,3 @@ impl<'de> Deserialize<'de> for SimpleOperation {
|
||||||
deserializer.deserialize_any(OperationVisitor)
|
deserializer.deserialize_any(OperationVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A serializable representation of the changes made to a text document
|
|
||||||
/// without the original text.
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
#[derive(Debug, Clone, PartialEq, Default)]
|
|
||||||
pub struct ChangeSet {
|
|
||||||
pub operations: Vec<SimpleOperation>,
|
|
||||||
pub cursors: Vec<CursorPosition>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ChangeSet {
|
|
||||||
#[must_use]
|
|
||||||
pub fn new(operations: Vec<SimpleOperation>, cursors: Vec<CursorPosition>) -> Self {
|
|
||||||
Self {
|
|
||||||
operations,
|
|
||||||
cursors,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue