• Returns a cursor for the given position in a string.

    Remarks

    A cursor represents a relative position, "before character X", rather than an absolute position. As the document is edited, the cursor remains stable relative to its context, just as you'd expect from a cursor in a concurrent text editor.

    The string representation is shareable, and so you can use this both to edit the document yourself (using splice) or to share multiple collaborator's current cursor positions over the network.

    The cursor's position can be an index in the string, 'start' or 'end'.

    • 'start' ensures this cursor always resolves to 0
    • 'end' ensures this cursor always resolves to string.length

    Start cursors can be created by passing any negative number in position.

    End cursors can be created by passing a number >= string.length in position.

    move determines the position the cursor resolves to if the character at index is removed:

    • 'after' causes the cursor to resolve towards string.length
    • 'before' causes the cursor to resolve towards 0

    move is 'after' by default.

    Type Parameters

    • T

      The type of the value contained in the document

    Parameters

    • doc: Doc<T>

      The document

    • path: Prop[]

      The path to the string

    • position: CursorPosition

      The position of the cursor, either an index, 'start' or 'end'

    • Optional move: MoveCursor

      The direction the cursor should resolve to, defaults to 'after'

    Returns Cursor

Generated using TypeDoc