undo method

bool undo(
  1. FluentDocument document
)

Implementation

bool undo(FluentDocument document) {
  if (!canUndo) return false;

  final delta = _undoStack.removeLast();
  _redoStack.add(delta);

  _isRestoringState = true;
  try {
    delta.revert(document);
  } catch (e, st) {
    print('[UNDO_ERROR] revert failed: $e\n$st');
    // Remove the corrupted delta so it doesn't crash again.
    _redoStack.removeLast();
    return false;
  } finally {
    _isRestoringState = false;
  }
  // Notify only the widgets whose nodes were touched by this delta.
  final affectedIds = _collectAffectedIds(delta, document);
  document.notifyDocumentChanged(affectedIds: affectedIds);
  _resetGrouping();
  return true;
}