Initial implementation of cursors (perf branch version) #307
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is the same as #306, but based on the performance branch rather than main. It provides a first attempt at an API for cursors.
A cursor is an object of the form
{objectId: 'string', elemId: 'string'}
and it can be stored anywhere: inside an Automerge document or somewhere external. To get the cursor for a particular index of a text object, use:The cursor identifies a particular character in the text; the position of that character may change as text is inserted or deleted before it. To get the current index of a previously created cursor, use:
The third argument controls what to do if the character referenced by the cursor has been deleted. If
false
and the character has been deleted,getCursorIndex
returns -1. If the argument istrue
and the character has been deleted,getCursorIndex
returns the index of the closest preceding non-deleted character, or -1 if there is no such preceding character.I am not super happy with this approach, but putting up the PR nevertheless so that folks can play with it.