Yjs binding configuration

Constructors

Properties

Methods

Constructors

Properties

ytext: YText

Yjs text to synchronize

Methods

  • Helper function to transform an absolute index position to a Yjs-based relative position (https://docs.yjs.dev/api/relative-positions).

    A relative position can be transformed back to an absolute position even after the document has changed. The position is automatically adapted. This does not require any position transformations. Relative positions are computed based on the internal Yjs document model. Peers that share content through Yjs are guaranteed that their positions will always synced up when using relative positions.

    import { ySyncFacet } from 'y-codemirror'

    ..
    const ysync = view.state.facet(ySyncFacet)
    // transform an absolute index position to a ypos
    const ypos = ysync.getYPos(3)
    // transform the ypos back to an absolute position
    ysync.fromYPos(ypos) // => 3

    It cannot be guaranteed that absolute index positions can be synced up between peers. This might lead to undesired behavior when implementing features that require that all peers see the same marked range (e.g. a comment plugin).

    Parameters

    • pos: number
    • assoc: number = 0

    Returns RelativePosition