syncEditorStateFromOffsets function
void
syncEditorStateFromOffsets(
- TextDocument document,
- EditorState editorState, {
- required int cursorOffset,
- int? selectionBaseOffset,
- int? selectionExtentOffset,
Implementation
void syncEditorStateFromOffsets(
TextDocument document,
EditorState editorState, {
required int cursorOffset,
int? selectionBaseOffset,
int? selectionExtentOffset,
}) {
final cursor = document.positionForOffset(
cursorOffset.clamp(0, document.length),
);
editorState.setCursor(line: cursor.line, column: cursor.column);
if (selectionBaseOffset == null || selectionExtentOffset == null) {
editorState.clearSelection();
return;
}
editorState.setSelection(
base: document.positionForOffset(
selectionBaseOffset.clamp(0, document.length),
),
extent: document.positionForOffset(
selectionExtentOffset.clamp(0, document.length),
),
cursor: cursor,
);
}