diff --git a/reconcile-js/src/index.ts b/reconcile-js/src/index.ts index 75d64cf..9f0bbcc 100644 --- a/reconcile-js/src/index.ts +++ b/reconcile-js/src/index.ts @@ -174,7 +174,7 @@ function toTextWithCursors( function toCursorPosition(cursor: wasmCursorPosition): CursorPosition { return { id: cursor.id(), - position: cursor.characterPosition(), + position: cursor.characterIndex(), }; } diff --git a/src/operation_transformation/edited_text.rs b/src/operation_transformation/edited_text.rs index 5edfe03..cd0bd24 100644 --- a/src/operation_transformation/edited_text.rs +++ b/src/operation_transformation/edited_text.rs @@ -257,15 +257,15 @@ where match operation { Operation::Equal { .. } => { - history.push(SpanWithHistory::new(History::Unchanged, builder.take())); + history.push(SpanWithHistory::new(builder.take(), History::Unchanged)); } Operation::Insert { side, .. } => match side { Side::Left => { - history.push(SpanWithHistory::new(History::AddedFromLeft, builder.take())); + history.push(SpanWithHistory::new(builder.take(), History::AddedFromLeft)); } Side::Right => history.push(SpanWithHistory::new( - History::AddedFromRight, builder.take(), + History::AddedFromRight, )), }, Operation::Delete { @@ -277,10 +277,10 @@ where let deleted = self.text[*order..*order + *deleted_character_count].to_string(); match side { Side::Left => { - history.push(SpanWithHistory::new(History::RemovedFromLeft, deleted)); + history.push(SpanWithHistory::new(deleted, History::RemovedFromLeft)); } Side::Right => { - history.push(SpanWithHistory::new(History::RemovedFromRight, deleted)); + history.push(SpanWithHistory::new(deleted, History::RemovedFromRight)); } } } diff --git a/src/types/cursor_position.rs b/src/types/cursor_position.rs index f7abba7..9c97d44 100644 --- a/src/types/cursor_position.rs +++ b/src/types/cursor_position.rs @@ -30,7 +30,7 @@ impl CursorPosition { #[must_use] pub fn id(&self) -> usize { self.id } - #[cfg_attr(feature = "wasm", wasm_bindgen(js_name = characterPosition))] + #[cfg_attr(feature = "wasm", wasm_bindgen(js_name = characterIndex))] #[must_use] pub fn char_index(&self) -> usize { self.char_index } } diff --git a/src/types/span_with_history.rs b/src/types/span_with_history.rs index 90826c6..4f61317 100644 --- a/src/types/span_with_history.rs +++ b/src/types/span_with_history.rs @@ -5,19 +5,20 @@ use wasm_bindgen::prelude::*; use crate::types::history::History; -/// Wrapper type for `(History, String)` +/// Wrapper type for `(String, History)` where History describes the origin of +/// `text`. #[cfg_attr(feature = "wasm", wasm_bindgen)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, Clone, PartialEq)] pub struct SpanWithHistory { - history: History, text: String, + history: History, } #[cfg_attr(feature = "wasm", wasm_bindgen)] impl SpanWithHistory { #[must_use] - pub fn new(history: History, text: String) -> Self { SpanWithHistory { history, text } } + pub fn new(text: String, history: History) -> Self { SpanWithHistory { text, history } } #[must_use] pub fn history(&self) -> History { self.history } diff --git a/src/wasm.rs b/src/wasm.rs index 1234af2..0eda809 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -1,14 +1,4 @@ -//! This crate provides utilities for easily communicating between backend & -//! frontend and ensuring the same logic for encoding and decoding binary data, -//! and 3-way-merging documents in Rust and JavaScript. -//! -//! The crate is designed to be used as a Rust library and as a -//! TypeScript/JavaScript package through WebAssembly (WASM). -//! -//! # Modules -//! -//! - `errors`: Contains error types used in this crate. - +//! Expose the `reconcile` crate's functionality to WebAssembly. use core::str; use cfg_if::cfg_if; @@ -116,6 +106,7 @@ fn set_panic_hook() { console_error_panic_hook::set_once(); } +/// WASM wrapper type for the return value of `reconcile_with_history` #[wasm_bindgen] #[derive(Debug, Clone, PartialEq, Default)] pub struct TextWithCursorsAndHistory {