Skip to content

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.

Make an edit 0 back · 0 forward
Read
Clean
Score
Write
Ctrl+Z undo · Ctrl+Shift+Z or Ctrl+Y redo
bit Blow

Try 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 a BlowHistory, 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, AddEdges or DeleteElementsAsync are called.
  • OnHistoryChanged carries a BlowHistoryState - CanUndo, CanRedo, UndoDepth, RedoDepth, and UndoLabel and RedoLabel, the codes of the steps either side - which is all the toolbar reads.
  • UndoAsync() and RedoAsync() 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 with rename. A capture identical to the last step is ignored, so it is safe to call wherever an edit might have happened.
  • ClipboardShortcutsEnabled binds the clipboard keys; AlignSelectionAsync(BlowAlignEdge.Left) lines up the selected nodes' left edges and does nothing for fewer than two.
An unhandled error has occurred. Reload 🗙