Docs

cursor

Source: crates/lvcs-doc/src/cursor/mod.rs.

/// One character of an Automerge `Text`: the counter and actor of the
/// operation that inserted it, which every peer shares (decision 76).
/// Serialized as `{ counter, actor }` with the actor id as a byte string.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(from = "ElementWire", into = "ElementWire")]
pub struct ElementId {
    counter: u64,
    actor: ActorId,
}

/// An inclusive range anchor (design §8, decisions 41, 76, and 83): `start`
/// is the range's first character, with `MoveCursor::After`, and `end` its
/// last, with `MoveCursor::Before`, both visible at the heads `at` it was
/// made at. No anchor is empty. An insert exactly at either boundary lands
/// outside the range, because each anchor is a character, not a gap.
/// Resolved where no character between the two anchors in list order is
/// visible, `start` moves past `end` and the anchor resolves as
/// [`AnchorSpan::Collapsed`] on every peer alike, at the gap where the
/// range was.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RangeAnchor {
    /// The heads the anchor was made at, sorted and deduplicated.
    #[serde(with = "crate::cbor::heads")]
    at: Vec<ChangeHash>,
    start: ElementId,
    end: ElementId,
}

/// A [`RangeAnchor`] resolved at some heads.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum AnchorSpan {
    /// The range is the code points `start..end` there (`start < end`):
    /// `start` is the first character's position or, once it is deleted,
    /// that of the next character visible in list order at those heads
    /// (decision 83); `end - 1` the same for the last character and the
    /// previous visible one.
    Range { start: usize, end: usize },
    /// No character between the anchors in list order is visible there:
    /// every character the range held is deleted, and so is anything
    /// inserted inside it, so the resolved `start` is past the resolved
    /// `end` (decision 41). `at` is the gap where the range was, in code
    /// points at those heads: how many characters visible there come
    /// before the range's first character in list order (decision 92).
    Collapsed { at: usize },
}