Lint & fix typos
This commit is contained in:
parent
865d1f5073
commit
12c367db21
5 changed files with 50 additions and 40 deletions
|
|
@ -218,7 +218,7 @@ function init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function toWasmTextWithCursors(text: string | TextWithCursors): wasmTextWithCursors {
|
function toWasmTextWithCursors(text: string | TextWithCursors): wasmTextWithCursors {
|
||||||
const isInputString = typeof text == 'string';
|
const isInputString = typeof text === 'string';
|
||||||
const leftText = isInputString ? text : text.text;
|
const leftText = isInputString ? text : text.text;
|
||||||
const leftCursors = isInputString ? [] : (text.cursors ?? []);
|
const leftCursors = isInputString ? [] : (text.cursors ?? []);
|
||||||
|
|
||||||
|
|
|
||||||
36
src/lib.rs
36
src/lib.rs
|
|
@ -1,12 +1,14 @@
|
||||||
//! # Reconcile: 3-way text merging with automatic conflict resolution
|
//! # Reconcile: 3-way text merging with automatic conflict resolution
|
||||||
//!
|
//!
|
||||||
//! A library for merging conflicting text edits without manual intervention.
|
//! A library for merging conflicting text edits without manual intervention.
|
||||||
//! Unlike traditional 3-way merge tools that produce conflict markers, this library
|
//! Unlike traditional 3-way merge tools that produce conflict markers, this
|
||||||
//! automatically resolves conflicts by applying both sets of changes where possible.
|
//! library automatically resolves conflicts by applying both sets of changes
|
||||||
|
//! where possible.
|
||||||
//!
|
//!
|
||||||
//! Based on a combination of Myers' diff algorithm and Operational Transformation
|
//! Based on a combination of Myers' diff algorithm and Operational
|
||||||
//! principles, it's designed for scenarios where you have a common parent text
|
//! Transformation principles, it's designed for scenarios where you have a
|
||||||
//! and two modified versions that need to be intelligently combined.
|
//! common parent text and two modified versions that need to be intelligently
|
||||||
|
//! combined.
|
||||||
//!
|
//!
|
||||||
//! **[Try the interactive demo](https://schmelczer.dev/reconcile)** to see it in action.
|
//! **[Try the interactive demo](https://schmelczer.dev/reconcile)** to see it in action.
|
||||||
//!
|
//!
|
||||||
|
|
@ -33,9 +35,12 @@
|
||||||
//!
|
//!
|
||||||
//! ### Built-in tokenisers
|
//! ### Built-in tokenisers
|
||||||
//!
|
//!
|
||||||
//! - **`BuiltinTokenizer::Word`** (recommended): Splits on word boundaries, preserving word integrity
|
//! - **`BuiltinTokenizer::Word`** (recommended): Splits on word boundaries,
|
||||||
//! - **`BuiltinTokenizer::Character`**: Character-level merging for fine-grained control
|
//! preserving word integrity
|
||||||
//! - **`BuiltinTokenizer::Line`**: Line-based merging, similar to traditional diff tools
|
//! - **`BuiltinTokenizer::Character`**: Character-level merging for
|
||||||
|
//! fine-grained control
|
||||||
|
//! - **`BuiltinTokenizer::Line`**: Line-based merging, similar to traditional
|
||||||
|
//! diff tools
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! use reconcile_text::{reconcile, BuiltinTokenizer};
|
//! use reconcile_text::{reconcile, BuiltinTokenizer};
|
||||||
|
|
@ -81,7 +86,8 @@
|
||||||
//! assert_eq!(result.apply().text(), "Hello beautiful world. This is a great test.");
|
//! assert_eq!(result.apply().text(), "Hello beautiful world. This is a great test.");
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! > **Note**: Setting token joinability to `false` causes insertions to interleave
|
//! > **Note**: Setting token joinability to `false` causes insertions to
|
||||||
|
//! > interleave
|
||||||
//! > (LRLRLR) rather than group together (LLLRRR), which often produces more
|
//! > (LRLRLR) rather than group together (LLLRRR), which often produces more
|
||||||
//! > natural-looking merged text.
|
//! > natural-looking merged text.
|
||||||
//!
|
//!
|
||||||
|
|
@ -124,12 +130,16 @@
|
||||||
//!
|
//!
|
||||||
//! ## Algorithm overview
|
//! ## Algorithm overview
|
||||||
//!
|
//!
|
||||||
//! 1. **Diff computation**: Myers' algorithm calculates differences between parent↔left and parent↔right
|
//! 1. **Diff computation**: Myers' algorithm calculates differences between
|
||||||
//! 2. **Tokenisation**: Text is split into meaningful units (words, characters, etc.)
|
//! parent↔left and parent↔right
|
||||||
//! 3. **Diff optimisation**: Operations are reordered and consolidated for coherent changes
|
//! 2. **Tokenisation**: Text is split into meaningful units (words, characters,
|
||||||
|
//! etc.)
|
||||||
|
//! 3. **Diff optimisation**: Operations are reordered and consolidated for
|
||||||
|
//! coherent changes
|
||||||
//! 4. **Operational Transformation**: Edits are combined using OT principles
|
//! 4. **Operational Transformation**: Edits are combined using OT principles
|
||||||
//!
|
//!
|
||||||
//! For detailed algorithm explanation, see the [README](README.md#how-it-works).
|
//! For detailed algorithm explanation, see the
|
||||||
|
//! [README](README.md#how-it-works).
|
||||||
|
|
||||||
mod operation_transformation;
|
mod operation_transformation;
|
||||||
mod raw_operation;
|
mod raw_operation;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use crate::{tokenizer::token::Token, utils::myers_diff::myers_diff};
|
||||||
/// Text editing operation containing the to-be-changed `Tokens`-s.
|
/// Text editing operation containing the to-be-changed `Tokens`-s.
|
||||||
///
|
///
|
||||||
/// `RawOperations` can be joined together when the underlying tokens
|
/// `RawOperations` can be joined together when the underlying tokens
|
||||||
/// allow for joining subseqeunt operations.
|
/// allow for joining subsequent operations.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum RawOperation<T>
|
pub enum RawOperation<T>
|
||||||
where
|
where
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ use serde::{Deserialize, Serialize};
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
// CursorPosition represents the position of an identifiable cursor in a text
|
/// `CursorPosition` represents the position of an identifiable cursor in a text
|
||||||
// document based on its (UTF-8) character index.
|
/// document based on its (UTF-8) character index.
|
||||||
#[allow(clippy::unsafe_derive_deserialize)]
|
#[allow(clippy::unsafe_derive_deserialize)]
|
||||||
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ where
|
||||||
// odd and when there is a reciprocal k line coming from the other
|
// odd and when there is a reciprocal k line coming from the other
|
||||||
// direction.
|
// direction.
|
||||||
if odd && (k - delta).abs() <= (d - 1) {
|
if odd && (k - delta).abs() <= (d - 1) {
|
||||||
// TODO optimize this so we don't have to compare against n
|
// TODO optimise this so we don't have to compare against n
|
||||||
if vf[k] + vb[-(k - delta)] >= n {
|
if vf[k] + vb[-(k - delta)] >= n {
|
||||||
// Return the snake
|
// Return the snake
|
||||||
return Some((x0 + old_range.start, y0 + new_range.start));
|
return Some((x0 + old_range.start, y0 + new_range.start));
|
||||||
|
|
@ -222,7 +222,7 @@ where
|
||||||
vb[k] = x;
|
vb[k] = x;
|
||||||
|
|
||||||
if !odd && (k - delta).abs() <= d {
|
if !odd && (k - delta).abs() <= d {
|
||||||
// TODO optimize this so we don't have to compare against n
|
// TODO optimise this so we don't have to compare against n
|
||||||
if vb[k] + vf[-(k - delta)] >= n {
|
if vb[k] + vf[-(k - delta)] >= n {
|
||||||
// Return the snake
|
// Return the snake
|
||||||
return Some((n - x + old_range.start, m - y + new_range.start));
|
return Some((n - x + old_range.start, m - y + new_range.start));
|
||||||
|
|
@ -230,7 +230,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Maybe there's an opportunity to optimize and bail early?
|
// TODO: Maybe there's an opportunity to optimise and bail early?
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue