diff --git a/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart b/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart index ffff85aa..6b47d6a3 100644 --- a/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart +++ b/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart @@ -2,6 +2,8 @@ import 'dart:math'; import 'dart:ui' as ui; import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; +import 'package:flutter/rendering.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; @@ -95,7 +97,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState // with the last known remote value. // It is important to prevent excessive remote updates as it can cause // race conditions. - final actualValue = value.copyWith( + var actualValue = value.copyWith( composing: _lastKnownRemoteTextEditingValue?.composing, ); @@ -107,6 +109,16 @@ mixin RawEditorStateTextInputClientMixin on EditorState performSpellCheck(value.text); } + // This is to prevent sending an editing state with invalid composing range + // to engine. + // TODO: Maybe it's better to also include composing range in controller? + // Actions like [_DeleteTextAction] are using controller's editing value + // to update remote value. + // See https://github.com/fleather-editor/fleather/issues/259#issuecomment-2032404450 + if (!actualValue.isComposingRangeValid) { + actualValue = actualValue.copyWith(composing: TextRange.empty); + } + _lastKnownRemoteTextEditingValue = actualValue; _textInputConnection!.setEditingState(actualValue); }