syncEditorStateFromLineSnapshot function

void syncEditorStateFromLineSnapshot(
  1. EditorState editorState,
  2. TextLineStateSnapshot snapshot, {
  3. required int lineCount,
  4. required int lineLength(
    1. int line
    ),
})

Implementation

void syncEditorStateFromLineSnapshot(
  EditorState editorState,
  TextLineStateSnapshot snapshot, {
  required int lineCount,
  required int Function(int line) lineLength,
}) {
  final clamped = snapshot.clamp(lineCount: lineCount, lineLength: lineLength);
  editorState.setCursor(
    line: clamped.cursor.line,
    column: clamped.cursor.column,
  );

  if (clamped.selectionBase == null || clamped.selectionExtent == null) {
    editorState.clearSelection();
    return;
  }

  editorState.setSelection(
    base: clamped.selectionBase!,
    extent: clamped.selectionExtent!,
    cursor: clamped.cursor,
  );
}