Skip to content
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

Using undo-redo with cytoscape-edgehandles #22

Open
roddc opened this issue Aug 18, 2020 · 1 comment
Open

Using undo-redo with cytoscape-edgehandles #22

roddc opened this issue Aug 18, 2020 · 1 comment

Comments

@roddc
Copy link

roddc commented Aug 18, 2020

I am using edgehandles to draw edges, when I added an edge and then undo, it will delete the last added or target node , I need to call ur.do('add', addedEdge) in the edgehandles's complete() to fix this problem, is this the right way to do it

@mkhoussid
Copy link

mkhoussid commented Dec 29, 2020

You first have to remove the edge that was created in the ehcomplete callback, and then add it with undoRedo

In React,

cyRef.current.on('ehcomplete', (event, sourceNode, targetNode, addedEles) => { // https://github.com/cytoscape/cytoscape.js-edgehandles#events
        cyRef.current.remove(addedEles[0]); // remove from cy directly

        const actions = []; // 'batch' array (I recommend doing all undo-redo action as batches)
        actions.push({
            name: 'add',
            param: {
                group: 'edges',
                data: { id: addedEles[0].id(), source: sourceNode.id(), target: targetNode.id() },
            },
        });

        urRef.current.do('batch', actions); // add back to cy via ur: https://github.com/iVis-at-Bilkent/cytoscape.js-undo-redo#default-actions-undoableredoable
    });
}, [nodes, isSelectingEdges]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants