Built-in Undo & Redo
Set HistoryEnabled and the canvas keeps the undo stack itself: it records a labelled step wherever a user would see one - a drag finished, an edge connected, something deleted, pasted, aligned or nudged - and binds Ctrl/Cmd+Z and Ctrl/Cmd+Shift+Z. Edits your own code makes behind its back are recorded with CaptureHistory.
Ctrl+Z undo · Ctrl+Shift+Z or Ctrl+Y 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 a node and nudge it with the arrow keys: each is a step, and the Undo button names it - move, connect.
- Click the canvas and press Ctrl/Cmd+Z to undo, Ctrl/Cmd+Shift+Z or Ctrl/Cmd+Y to redo - or use the buttons. Pan or zoom first: undo restores the graph but leaves the view where you put it.
- Ctrl/Cmd+C then V, X or D copy, paste, cut and duplicate the selection; each is a step too.
- Add node, Align left (select two or more nodes first) and Delete selected call the canvas, which records them as add, align and delete.
- Rename selected changes the selected nodes' labels in the page's own code; it is a step called rename because the page records it.
- Click a node or pan: selecting and panning are not edits, so the step count does not move. Undo, then make an edit: the redo steps are gone, as in every editor.
How it works
HistoryEnabled(off by default, so a flow does not take Ctrl+Z from the page around it) makes the canvas keep aBlowHistory, starting from the graph on screen.HistoryCapacity(100 by default, 50 here) bounds how many steps back it goes; changing it starts a fresh history.- A step is recorded when a drag that moved something ends, a resize ends, an edge is connected or reconnected, something is deleted, pasted, cut or duplicated, the arrow keys nudge nodes, a selection is aligned or distributed, and when
AddNodes,AddEdgesorDeleteElementsAsyncare called. OnHistoryChangedcarries aBlowHistoryState-CanUndo,CanRedo,UndoDepth,RedoDepth, andUndoLabelandRedoLabel, the codes of the steps either side - which is all the toolbar reads.UndoAsync()andRedoAsync()do what the keys do and return false when there was nothing to do. Undo puts the graph back but not the viewport.- For an edit the canvas cannot see - a label, a node's data, a list changed by your own code - call
CaptureHistory(label)afterwards, as Rename does withrename. A capture identical to the last step is ignored, so it is safe to call wherever an edit might have happened. ClipboardShortcutsEnabledbinds the clipboard keys;AlignSelectionAsync(BlowAlignEdge.Left)lines up the selected nodes' left edges and does nothing for fewer than two.