diff --git a/lib/common/widgets/flutter/text_field/editable_text.dart b/lib/common/widgets/flutter/text_field/editable_text.dart index 260b74e25..9b35cb3ff 100644 --- a/lib/common/widgets/flutter/text_field/editable_text.dart +++ b/lib/common/widgets/flutter/text_field/editable_text.dart @@ -2609,6 +2609,10 @@ class EditableTextState extends State selection.baseOffset, selection.extentOffset, ); + final TextEditingValue collapsedTextEditingValue = textEditingValue + .copyWith(selection: .collapsed(offset: lastSelectionIndex)); + final newValue = collapsedTextEditingValue.replaced(selection, text); + // bggRGjQaUbCoE _pasteText widget.controller.syncRichText( selection.isCollapsed @@ -2616,22 +2620,18 @@ class EditableTextState extends State oldText: textEditingValue.text, textInserted: text, insertionOffset: selection.baseOffset, - selection: TextSelection.collapsed(offset: lastSelectionIndex), - composing: TextRange.empty, + selection: newValue.selection, + composing: newValue.composing, ) : TextEditingDeltaReplacement( oldText: textEditingValue.text, replacementText: text, replacedRange: selection, - selection: TextSelection.collapsed(offset: lastSelectionIndex), - composing: TextRange.empty, + selection: newValue.selection, + composing: newValue.composing, ), ); - final newValue = TextEditingValue( - text: widget.controller.plainText, - selection: widget.controller.newSelection, - composing: TextRange.empty, - ); + userUpdateTextEditingValue(newValue, cause); if (cause == SelectionChangedCause.toolbar) { // Schedule a call to bringIntoView() after renderEditable updates. @@ -5530,33 +5530,29 @@ class EditableTextState extends State void _replaceText(ReplaceTextIntent intent) { final TextEditingValue oldValue = _value; + final TextEditingValue newValue = intent.currentTextEditingValue.replaced( + intent.replacementRange, + intent.replacementText, + ); + // bggRGjQaUbCoE _replaceText widget.controller.syncRichText( intent.replacementText.isEmpty ? TextEditingDeltaDeletion( oldText: oldValue.text, deletedRange: intent.replacementRange, - selection: TextSelection.collapsed( - offset: intent.replacementRange.start, - ), - composing: TextRange.empty, + selection: newValue.selection, + composing: newValue.composing, ) : TextEditingDeltaReplacement( oldText: oldValue.text, replacementText: intent.replacementText, replacedRange: intent.replacementRange, - selection: TextSelection.collapsed( - offset: intent.replacementRange.start, - ), - composing: TextRange.empty, + selection: newValue.selection, + composing: newValue.composing, ), ); - final newValue = TextEditingValue( - text: widget.controller.plainText, - selection: widget.controller.newSelection, - composing: TextRange.empty, - ); userUpdateTextEditingValue(newValue, intent.cause); // If there's no change in text and selection (e.g. when selecting and