setTextPreservingSelection method
Sets text while preserving the current selection
This method updates the text content while maintaining the current text selection state, which is important for "select all" operations.
newText - The new text content
Implementation
void setTextPreservingSelection(String newText) {
final currentSelection = selection;
final clampedSelection = TextSelection(
baseOffset: currentSelection.baseOffset.clamp(0, newText.length),
extentOffset: currentSelection.extentOffset.clamp(0, newText.length),
);
value = TextEditingValue(
text: newText,
selection: clampedSelection,
);
}