Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-06-10 19:30:50 +08:00
parent 6cf41d1377
commit 76cd529733

View File

@@ -2609,6 +2609,10 @@ class EditableTextState extends State<EditableText>
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<EditableText>
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<EditableText>
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