Positioning cursors using awareness (`StickyIndex` support)
While the awareness is exposed by pycrdt, it does not expose the StickyIndex often needed to place collaborators cursors at a relative position.
It looks like it would be sufficient to expose python binding to sticky_index on Text and Array, do I see it right?
https://github.com/y-crdt/y-crdt/blob/0968e1dd3889df369d3adff60e771632bd754af7/yrs/src/moving.rs#L892-L906
cc @brichet who contributed to the awareness feature in pycrdt.
Just to share my research into how we could possibly use it downstream (in jupyterlab):
ycell = document.ycells[0]
text: Text = ycell["source"]
document.awareness.set_local_state_field(
"user",
{
"username": "krassowski",
"initials": "MK",
"display_name": "M. Krassowski",
"name": "Krassowski",
"color": "#ffb61e",
},
)
# set the cursor in the first cell
cursor = text.sticky_index(index=0, assoc=0)
document.awareness.set_local_state_field(
"cursors",
[
{
"anchor": cursor,
"head": cursor,
"primary": True,
"empty": True,
}
],
)
Some questions here are:
- should the
stick_indexobject be natively json-serializable when passed toset_local_state_fieldor haveto_py()method? - do we need to pass
doc.transact_mut()as iny-crdtor can it be accessed only at the bindings level (as implied by my pseudocode above)
I wonder what would be the use case for cursors position from the server side document awareness. Is it intended for LLM use?
Is it intended for LLM use?
Yes, spot on. Having a collaborator agent on the backend being able to work and continue working even if you refresh the browser, and their cursor position being visible when they type.