Open satoren opened 1 month ago
played around with an approach using updates. could evolve to support other types, depth, persistence, and better efficiency using SVs.
https://github.com/cortfritz/undo_manager
Let me know if you think that direction makes sense vs. something else. I don't love coding inversions of %{insert: blah...}
Possibly inversions of updates in rust?
I'm open.
I could put the question better; do you think the use of Yex doc updates to store differences can be a good path to implant the yjs spec for undo manager?
I could leverage SVs to be more efficient. And instead of a string for clients, I would implement the spec for contexts.
I was planning to export the UndoManager of yrs(rust) with nif.
derp. so much better. I'm happy to take a stab at it if you would like.
cannot get your main branch to pass tests. If i futz with mix.exs and compile the rust directly with cargo build
i can compile. I'm guessing i'm not doing that right though.
in the meantime my WiP is here: https://github.com/cortfritz/y_ex/tree/feature/undo
just sketching for now.
The RUSTLER_PRECOMPILATION_YEX_BUILD
environment variable must be set to 1.
For those developers who are willing to participate I need to update README.
that works! thank you.
This is as far as i got.
https://github.com/cortfritz/y_ex/blob/feature/undo/native/yex/src/undo.rs
I'm able to create a new yrs::UndoManager and exercise some functions, but unable to get Undo to... undo. When I passed a Text into UndoManager::new as scope I could only get panics. Couldn't figure out how set up Undo to do it's job. I'm going to come back to this eventually but effort/progress is out of whack and i'm going to back off for now.
LOVE THIS PROJECT, thank you.
The panic is probably because the ENV is not registered with thread_local. This is used in the observer callback to send messages to the beam. Therefore, any function that will be modified must be wrapped in this. https://github.com/satoren/y_ex/blob/a23ce60c66bcfbe80b6a3accfd3aae92275cecbd/native/yex/src/awareness.rs#L96
followed your advice - this seems to go better:
https://github.com/cortfritz/y_ex/blob/feature/undo/native/yex/src/undo.rs
no errors, but I'm still not actually effecting an undo, with or without origin.
got it working!!!
I'm not able to get async working - but it looks like your implementation is synchronous?
getting Yex.UndoManager.new/2 to take Yex.Text, Yex.Map, Yex.Array, etc may have a better pattern. I couldn't get NifSharedType to work or NifYInput... I ended up with the less elegant:
I haven't tackled XML types yet.
But tests passing for undo on Text, Map, Array, and multiple origins for Text. Will grow tests on these to be more comprehensive and add XML types, then address other functionality.
Can refactor if I find a better pattern for the interface.
fixed the NIF interface and implementation so we are DRY and don't have parallel implementations.
implemented redo
next will support adding scopes.
implemented stop_capture, expand_scope, and exclude_origin
next adding the observable behavior and the ability to add/get meta info on stack items.
ok, i believe i have implemented (with caveats below) all of the features demonstrated in the yjs example you link above.
upon creating a pull request I see some egregious mistakes, bad structure, etc. have to love coderabbit!
i'm fixing these now.
https://docs.yjs.dev/api/undo-manager