fix: remote id, update text and reserve selection (#10867)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2025-02-21 10:41:57 +08:00 committed by GitHub
parent 343f12b380
commit 0b9a6a280e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 5 deletions

View file

@ -3705,3 +3705,18 @@ Widget workaroundWindowBorder(BuildContext context, Widget child) {
],
);
}
void updateTextAndPreserveSelection(TextEditingController controller, String text) {
final preSelectionStart = controller.selection.start;
final preSelectionEnd = controller.selection.end;
// Only care about select all for now.
final isSelected = preSelectionEnd > preSelectionStart;
// Set text will make the selection invalid.
controller.text = text;
if (isSelected) {
controller.selection = TextSelection(
baseOffset: 0, extentOffset: controller.value.text.length);
}
}