miroiu / nodify

Highly performant and modular controls for node-based editors designed for data-binding and MVVM.
https://miroiu.github.io/nodify
MIT License
1.27k stars 205 forks source link

[Feature] Copy/Paste and Undo/Redo editor actions #101

Closed heisenberg-cooks closed 3 months ago

heisenberg-cooks commented 4 months ago

Describe the solution you'd like Having a built in method for copy/paste and undo/redo added to the editor would be very convenient for ease of canvas operations and minimization of clicking around.

Describe alternatives you've considered I currently have a copy method, but it's very limited to just copying nodes only. It simply copies all the properties of an existing node and assigns it a new id on paste, but this gets more complicated with custom controls being embedded in as node inputs. Connections are a little bit more difficult to maintain since you might not be copying the node they are connecting to.

Undo/redo sounds like a similar request since it requires keeping the collection in memory.

With that being said, i'm not sure the scope of the copy/paste and undo/redo when multiple tabs/editors are being used? Perhaps it's only relative to the current editor in focus?

miroiu commented 4 months ago

Hi! The provided controls do not hold too much state because everything is intended to be controlled by the view model. Of course, I could have an undo action for basic things like moving a node or zooming the canvas, etc. But that would surely interfere with your custom-made undo-redo solution, over-complicating things. Then we need to think about what stays in memory and for how long, then make sure that the view does not get out of sync with the view model. In the case of copy-paste, how would you validate that copy-paste is allowed? The graph may be read-only or some of the nodes should be unique. These rules are application-specific. Even if I tried implementing something in the library, it wouldn't be generic enough to cover all cases.

However, I had an attempt at creating a separate library at some point in time which would implement most of the common functionality you see in a node editor in a generic way so you can use it as a base. Here's the PR if you are interested: #36 . And here are the relevant files for undo/redo: https://github.com/miroiu/nodify/tree/feature/new-blueprint/Nodifier/UndoRedo

miroiu commented 3 months ago

Closing this as not planned. Please feel free to reopen the issue if you need more information.