Set String by Diff?

19 views
Skip to first unread message

Curran Kelleher

unread,
Feb 3, 2018, 2:10:37 AM2/3/18
to ShareJS
Greetings,

Does anyone know of a way to set a text field in ShareDB by its diff (difference) with the old text?

I've got a scenario where I want to set the value of a string in ShareDB, but also minimize the size of the ops (for history retention). I know the old string value, and the new string value, but the edit is not from a text editor so I don't know the minimal ops to generate for the change. The strings are datasets such as CSV or JSON strings, and the changes are updates to the datasets. The most common types of changes are appending new lines at the end, and removing lines from the beginning, but these are not the only kinds of changes encountered.

I'm looking for something that computes a String diff like Google Diff Match Patch or JSDiff, but which generates ShareDB ops instead of library-specific diff data structures. I suppose a direct conversion from the diff library output to JSON0 ops may be possible, but I'm not sure.

Has anyone seen something like this? After some searching, the closest thing I found was this discussion of Racer's setDiff, which is a similar concept, but does not handle string diffs. There's also a diff implementation in Nate's text-diff-binding, but I'm not sure if it's adequate or if it can be used outside the context of an onInput event.

Thanks!

Best regards,
Curran

John Hewson

unread,
Feb 3, 2018, 2:07:17 PM2/3/18
to sha...@googlegroups.com
Hi again Curran,

I think json0-ot-diff might be what you want. I’m aware of it but have not used it:


If you’re using rich-text, then quill-delta, on which it is based offers a diff method:


I’ve used it and it works well.

Cheers,

— John

--
You received this message because you are subscribed to the Google Groups "ShareJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharejs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Curran Kelleher

unread,
Feb 5, 2018, 9:02:02 AM2/5/18
to ShareJS
Hi John,

Thank you for the references.

Unfortunately neither of them are suited to my use case.
  • json0-ot-diff says clearly "The current implementation only supports list/object insertion/deletion (i.e. li, ld, oi, od).". It does not support string ops, which is the only thing I need.
  • The Quill.js Diff is pretty close, but it yields ops for the rich text type and I'm using the JSON0 type.
I'm considering trying to generate si and sd JSON0 ops from the output of JsDiff.diffChars. Not sure how it will play out. Will report back here if it works!

Regards,
Curran
Reply all
Reply to author
Forward
Message has been deleted
0 new messages