-
Notifications
You must be signed in to change notification settings - Fork 6k
Update CompositionAwareMixin to correctly compute composingBase in Web engine #44139
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks reasonable to me. Using |
||
|
|
||
| if (composingBase < 0) { | ||
| return editingState; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,7 +106,7 @@ Future<void> 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', () { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably outside of the scope of this PR, but I noticed this test has the selection of the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const int baseOffset = 100; | ||
| const String composingText = 'composeMe'; | ||
|
|
||
|
|
@@ -128,6 +128,30 @@ Future<void> testMain() async { | |
| composingBaseOffset: expectedComposingBase, | ||
| composingExtentOffset: expectedComposingBase + composingText.length)); | ||
| }); | ||
|
|
||
| test('should return new composition state - compositing from beginning of text', () { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks great! There are some untested code paths in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't think of any scenario that this can happen but it's still possible. Do you think I can address adding tests along with #44139 (comment) in another PR? @htoor3
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That works for me @Amir-P |
||
| 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)); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.