diff --git a/AUTHORS b/AUTHORS index 1211ffab5ac3a..c018e61980aff 100644 --- a/AUTHORS +++ b/AUTHORS @@ -23,4 +23,5 @@ Koutaro Mori TheOneWithTheBraid Twin Sun, LLC Qixing Cao -LinXunFeng \ No newline at end of file +LinXunFeng +Amir Panahandeh \ No newline at end of file diff --git a/lib/web_ui/lib/src/engine/text_editing/composition_aware_mixin.dart b/lib/web_ui/lib/src/engine/text_editing/composition_aware_mixin.dart index c33a72bfde378..71294e25d7930 100644 --- a/lib/web_ui/lib/src/engine/text_editing/composition_aware_mixin.dart +++ b/lib/web_ui/lib/src/engine/text_editing/composition_aware_mixin.dart @@ -71,11 +71,11 @@ mixin CompositionAwareMixin { } EditingState determineCompositionState(EditingState editingState) { - if (editingState.baseOffset == null || composingText == null || editingState.text == null) { + if (editingState.extentOffset == null || composingText == null || editingState.text == null) { return editingState; } - final int composingBase = editingState.baseOffset! - composingText!.length; + final int composingBase = editingState.extentOffset! - composingText!.length; if (composingBase < 0) { return editingState; diff --git a/lib/web_ui/test/engine/composition_test.dart b/lib/web_ui/test/engine/composition_test.dart index 5d4b9fb6a89d6..31e97266dd4ef 100644 --- a/lib/web_ui/test/engine/composition_test.dart +++ b/lib/web_ui/test/engine/composition_test.dart @@ -106,7 +106,7 @@ Future testMain() async { }); group('determine composition state', () { - test('should return new composition state if valid new composition', () { + test('should return new composition state - compositing middle of text', () { const int baseOffset = 100; const String composingText = 'composeMe'; @@ -128,6 +128,30 @@ Future testMain() async { composingBaseOffset: expectedComposingBase, composingExtentOffset: expectedComposingBase + composingText.length)); }); + + test('should return new composition state - compositing from beginning of text', () { + const String composingText = '今日は'; + + final EditingState editingState = EditingState( + text: '今日は', + baseOffset: 0, + extentOffset: 3, + ); + + final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin = + _MockWithCompositionAwareMixin(); + mockWithCompositionAwareMixin.composingText = composingText; + + const int expectedComposingBase = 0; + + expect( + mockWithCompositionAwareMixin + .determineCompositionState(editingState), + editingState.copyWith( + composingBaseOffset: expectedComposingBase, + composingExtentOffset: + expectedComposingBase + composingText.length)); + }); }); });