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
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 to0
'end'
ensures this cursor always resolves tostring.length
Start cursors can be created by passing any negative number in
position
.End cursors can be created by passing a number
>= string.length
inposition
.move
determines the position the cursor resolves to if the character atindex
is removed:'after'
causes the cursor to resolve towardsstring.length
'before'
causes the cursor to resolve towards0
move
is'after'
by default.