lineSnapshotFromEditorState function

TextLineStateSnapshot lineSnapshotFromEditorState(
  1. EditorState editorState, {
  2. required int lineCount,
  3. required int lineLength(
    1. int line
    ),
  4. bool preserveCollapsedSelection = false,
})

Implementation

TextLineStateSnapshot lineSnapshotFromEditorState(
  EditorState editorState, {
  required int lineCount,
  required int Function(int line) lineLength,
  bool preserveCollapsedSelection = false,
}) {
  final cursor = _clampPositionToLines(
    editorState.cursor,
    lineCount: lineCount,
    lineLength: lineLength,
  );
  final selection = editorState.selection;
  if (selection == null ||
      (selection.isCollapsed && !preserveCollapsedSelection)) {
    return TextLineStateSnapshot.collapsed(cursor: cursor);
  }

  return TextLineStateSnapshot.selection(
    base: _clampPositionToLines(
      selection.base,
      lineCount: lineCount,
      lineLength: lineLength,
    ),
    extent: _clampPositionToLines(
      selection.extent,
      lineCount: lineCount,
      lineLength: lineLength,
    ),
    cursor: cursor,
    preserveCollapsedSelection: preserveCollapsedSelection,
  );
}