Skip to content

Transactions and undo

Move two connected cards as one operation using the public drawing session.

Loading interactive example…Open in new tab ↗
Opening the live canvas…

Try it

  1. Click Preview 40, then Preview 80. Both offsets are measured from the original positions; the second preview does not accumulate the first.
  2. Commit, then Undo and Redo. Both cards restore together, and their connector follows the resolved ports.
  3. Undo again, preview a move and Cancel. The original positions and existing redo branch remain available.
  4. Move pair 40 demonstrates a single synchronous transaction without previews.

The session owns the edit lease and cancels it on disposal, including example reset. The example retains only the lease token, not a second document snapshot. An expired lease rejects further previews and commits. Buttons report denied commands through the shared example error surface.

Source

dart
DiagramTransaction movePair(double distance) => DiagramTransaction(
  label: 'Move pair',
  steps: [
    for (final id in ['card-0', 'card-1'])
      MoveShapeStep(elementId: id, delta: DiagramPoint(distance, 0)),
  ],
);

See Undo, redo and transactions for admission, history ownership, selection restoration and revision behavior.