Undo & Redo
Keep the undo stack yourself with BlowHistory: capture the graph after each edit, labelled with what it was, and restore the snapshot Undo or Redo hands back. For an app that already has an undo stack, or wants to decide what one step is; the canvas can also keep one for you (see Built-in Undo & Redo).
Press Tab to move between the nodes and edges of the diagram.
Press Enter or Space to select it, Shift with Enter to add it to the selection, the arrow keys to move the selected nodes, Delete to remove them and Escape to clear the selection. Press C to start a connection from it.
Press Enter or Space to select it, Delete to remove it and Escape to clear the selection. Press C to move its end to another node.
bit BlowTry it
- Drag a node, drag from a handle to connect two, or select something and press Delete: each is one step, and the Undo button names it - move, connect, delete. Moving five selected nodes together is one step too.
- Undo and Redo walk the steps; the view stays where you put it. Make an edit after undoing and the redo steps are gone, as in every editor.
- Add node and Scramble are steps as well. Press Scramble more than ten times: the step count stops at ten, because the oldest step is dropped.
- Simulate a remote edit moves Middle to the right as another user's change would. Undo as far as you like: the other steps come back, but Middle stays where the remote edit put it.
- Clear history forgets every step and starts again from the graph as it is.
How it works
new BlowHistory(capacity: 10)keeps up to ten steps back; past that the oldest is dropped.Capacity,UndoDepth,RedoDepth,CanUndoandCanRedodrive the toolbar.Capture(nodes, edges, viewport, label)records the live graph as a step, copying only the nodes and edges that changed since the last one. It returns false and records nothing when nothing changed - selecting is not an edit - so capturing liberally is harmless and Undo always does something.- The page captures in
OnGraphChanged, raised once per completed edit with aBlowGraphChangewhoseLabel(move,connect,delete,add, ...) becomes the step's label;UndoLabelandRedoLabelname the steps either side. A change of kindReplacedis the page's own restore, and is not captured. HandlingOnNodeDragStop,OnConnectandOnDeletewould do as well. - Add node goes through
AddNodes, so it arrives inOnGraphChangedlike a user's edit. Scramble moves the nodes directly, which the canvas cannot see, so the page captures it itself, labelledscramble. Undo()andRedo()step through the history and return theBlowSnapshotto apply, or null.RestoreAsync(snapshot, restoreViewport: false)puts the graph back in place, as copies, and leaves the viewport alone.Rebase(nodes, edges, viewport)writes a change nobody should undo into every step, back and forward; a step whose whole effect it overwrote is dropped.Clear()forgets everything, so the page captures the starting point again - asOnInitdoes, or the first undo would have nothing to return to.