-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Presence #9
Comments
I like it and think its important, but for the JSON OT type I haven't given it much thought yet. In a sense, we need the ability to create a cursor / marker (which might just be a path into some place in the document), and for that cursor to be moved around by other operations. So I'm no longer convinced that we need the idea of a selection range. (Just use 2 cursors). And I'm not convinced that it makes sense for the OT code to care about your operations vs the operations of others. (Those differences should probably be handled in surrounding code). |
I really appreciate your input here. Thank you for giving this some thought. I love your idea of the marker being an array. My original ideas were much more complicated. Using the array idea, a marker might look something like this: [
'some', 'path', // Path of the presence.
'ot-rich-text', // Subtype of the presence (a registered subtype).
{ // Opaque presence object (subtype-specific structure).
u: '123', // An example of an ot-rich-text presence object.
c: 8,
s: [ [ 1, 1 ], [ 5, 7 ]]
}
] |
FWIW, re: the OT code caring about your operations vs the operations of others, this informations ends up getting passed through to Though it's implemented that way, I'm also not convinced that it's necessary. The need for OT code caring about your operations vs the operations of others could possibly be avoided if, after you submit an op, you also emit a change in your own presence. In this case, how you transform your own presence by an op you emit yourself would be a moot point (because the transformed presence would be overwritten anyway). Although, there may be cases I haven't considered here. |
That's right, if you always submitted presence after an op, you would not need |
By the way, there's been a new presence implementation added in ShareDB. Here's an example of an OT type extended to support presence, compatible with ShareDB: ottypes/rich-text@ce14c8f#diff-4e2abe5a12642efc78b26087a61a8e9f The task at hand is to come up with a FWIW I got presence working with json0 and ShareDB without transformations using the following: import { type } from 'ot-json0';
type.transformPresence = function (presence, op, isOwnOp) {
if (!presence) {
return null;
}
return presence;
};
export { type }; Here's a snippet that interfaces with CodeMirror to generate the presence object: const handleCursorActivity = () => {
const from = codeMirror.getCursor(true);
const to = codeMirror.getCursor(false);
const doc = codeMirror.getDoc();
const fromIndex = doc.indexFromPos(from);
const toIndex = doc.indexFromPos(to);
const presenceObject = {
path,
index: fromIndex,
length: toIndex - fromIndex,
userId: me.id,
};
localPresence.submit(presenceObject);
};
codeMirror.on('cursorActivity', handleCursorActivity); |
Cool. Yeah so - right now we have a working
Its awkward to specify a selection range with json1, because I'm not sure what we should do we do if the start or end of the range moves somewhere else in the document. In general though, its been a long time since I've thought about presence. What do we need to make it work well for sharedb? What should the logic look like? I think that transformPosition method already does the heavy lifting. What else do we need to add / change to make it useful? |
I think what's needed is to:
|
Yep sounds good. I'm not sure what index and length refer to in this case - though that makes sense in the context of embedded types. Wanna spearhead / lead this @curran? |
I kind of do. Recycling some ideas from earlier for a more nuanced proposed shape for
I suppose tackling presence in Opened a new issue to tackle |
@curran @josephg Very excited to see movement on this! Let me know If I can help in anyway. We're currently using quill + sharedb with ot/rich-text, but there's a bunch of different problems that we think using ot/json1 as our root type would solve. Side note: if either of you have any recommendations or examples on how to get started on creating a document structure using ot/json1 where rich-text subtypes are editable by quill, that'd be great! |
@samiur Excellent! Indeed, a working example of ot/json1 where rich-text subtypes are editable by quill would be amazing. Actually, that might be a better first step than adding presence to This might be a good example for you to copy & modify to swap out json0 with json1: https://github.com/share/sharedb/tree/master/examples/rich-text-presence Another thought - |
I haven't forgot about this and I do intend to work on it one day! |
I got it working over in this fork https://github.com/vizhub-core/json1-presence |
I may be going out on a limb here, but what's your take on presence?
I've embarked on adding presence to json0.
Related proposal for OT spec changes: ottypes/docs#27
The text was updated successfully, but these errors were encountered: