textInsertGraphemes function
TextCommandResult
textInsertGraphemes({
- required TextDocument document,
- required TextOffsetStateSnapshot state,
- required List<
String> graphemes, - bool replaceSelection = true,
Implementation
TextCommandResult textInsertGraphemes({
required TextDocument document,
required TextOffsetStateSnapshot state,
required List<String> graphemes,
bool replaceSelection = true,
}) {
if (graphemes.isEmpty) {
return _unchangedDocumentCommandResult(document, state);
}
final working = document.copy();
final selection = normalizedSelectionRange(
state.selectionBaseOffset,
state.selectionExtentOffset,
);
final hasSelection = selection != null && selection.start != selection.end;
final result = replaceSelection && hasSelection
? edit_ops.replaceDocumentRange(
working,
start: selection.start,
end: selection.end,
replacement: graphemes,
)
: edit_ops.insertIntoDocument(working, state.cursorOffset, graphemes);
return _documentCommandResult(
working,
cursorOffset: result.cursorOffset,
documentChange: result.change,
changed: result.changed,
);
}