Skip to content

Commit

Permalink
normalize the documentation around cursor and reflect that in Position
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed Feb 2, 2025
1 parent 3e19ece commit 123fddd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Sources/Automerge/Cursor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ extension Cursor: CustomStringConvertible {
/// - ``Document/cursor(obj:position:)``
/// - ``Document/cursor(obj:position:heads:)``
public enum Position {
/// A stable location character or array position that follows that location regardless of Document changes.
case cursor(Cursor)
/// An absolute index position within an array or text object.
case index(UInt64)
}

Expand Down
10 changes: 6 additions & 4 deletions Sources/Automerge/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ public final class Document: @unchecked Sendable {
/// `Cursor` provides a reliable way to track the position of a character's location over time regardless of document changes.
/// The cursor remains anchored to the following character, and if placed at the end of the document,
/// the location it represents stays persistently at the end of the text or array.
///
/// The following snippet provides examples of cursor locations and the character it tracks:
/// ```swift
/// "ABC" // scenario
Expand Down Expand Up @@ -622,10 +623,11 @@ public final class Document: @unchecked Sendable {
/// Traditional index-based positions become outdated when you or collaborators modify the document.
/// This method provides a stable reference to a character that stays correctly anchored regardless of changes.
///
/// `Cursor` provides a reliable way to track positions over time without being affected by document changes.
/// `Cursor` provides a reliable way to track the position of a character's location over time regardless of document changes.
/// The cursor remains anchored to the following character, and if placed at the end of the document,
/// it will persistently stay attached to the end.
/// the location it represents stays persistently at the end of the text or array.
///
/// The following snippet provides examples of cursor locations and the character it tracks:
/// ```swift
/// "ABC" // scenario
/// "A|BC" // set cursor at `1`, cursor is attached to `B`
Expand All @@ -639,8 +641,8 @@ public final class Document: @unchecked Sendable {
/// - Parameters:
/// - obj: The object identifier of the list or text object.
/// - position: The index position in the list, or index for a text object based on ``TextEncoding``.
/// When using a position equal to or greater than the object's length at the specified point in time,
/// the cursor will track the end of the document as it changes.
/// When you use a position equal to or greater than the current length of the object,
/// the cursor tracks the end of the document, regardless of changes.
/// - heads: The set of ``ChangeHash`` that represents a point of time in the history the document.
/// - Returns: A cursor that references the position and point in time you specified.
///
Expand Down

0 comments on commit 123fddd

Please sign in to comment.