Cursors.Cursor(type, tname, item)

A Cursor is a relative position that is based on the Yjs model. In contrast to an absolute position (position by index), the Cursor can be recomputed when remote changes are received. For example:

Insert(0, 'x')('a|bc') = 'xa|bc' Where | is the cursor position.

A relative cursor position can be obtained with the function

One of the properties must be defined.

new Cursor(type, tname, item)

Parameters:
Name Type Description
type ID | null
tname string | null
item ID | null
Example
// Current cursor position is at position 10
  const relativePosition = createCursorFromOffset(yText, 10)
  // modify yText
  yText.insert(0, 'abc')
  yText.delete(3, 10)
  // Compute the cursor position
  const absolutePosition = toAbsolutePosition(y, relativePosition)
  absolutePosition.type === yText // => true
  console.log('cursor location is ' + absolutePosition.offset) // => cursor location is 3

Members

item :ID|null

tname :string|null

type :ID|null