editTransaction<T> method

T editTransaction<T>(
  1. T body(
    1. TextAreaModel model
    )
)

Runs every edit invoked by body as one undoable transaction.

Transactions may nest. Only the outer boundary commits history, allowing completion, formatting, snippets, and host commands to compose existing textarea operations without creating partial undo steps.

Implementation

T editTransaction<T>(T Function(TextAreaModel model) body) {
  final before = _captureEditState();
  final historyCheckpoint = _history.checkpoint();
  return _runEditFrame(() {
    _beginHistoryAction(_TextAreaHistoryAction.transform, breakChain: true);
    _recordUndoSnapshot();
    try {
      return body(this);
    } catch (_) {
      _history.restoreCheckpoint(historyCheckpoint);
      _restoreEditState(before);
      rethrow;
    }
  });
}