Skip to content

Initial implementation of cursors (perf branch version)#307

Closed
ept wants to merge 6 commits intoperformancefrom
cursors-perf
Closed

Initial implementation of cursors (perf branch version)#307
ept wants to merge 6 commits intoperformancefrom
cursors-perf

Conversation

@ept
Copy link
Member

@ept ept commented Jan 26, 2021

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:

const cursor = doc.text.getCursorAt(index)

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:

const index = Automerge.getCursorIndex(doc, cursor, true)

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 is true 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.

@ept ept added this to the 1.0 alpha release milestone Feb 3, 2021
@ept ept removed this from the 1.0 alpha release milestone Feb 3, 2021
@ept
Copy link
Member Author

ept commented May 7, 2021

I think we have come to the conclusion that the approach to cursors in #313 is preferable to this one, since it keeps open the option of having frontend and backend on separate threads. I will therefore close this PR.

@ept ept closed this May 7, 2021
@ept ept deleted the cursors-perf branch May 7, 2021 10:37
echarles pushed a commit to datalayer-externals/automerge-classic-arch that referenced this pull request Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants