Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 169cb2f

Browse files
committed
Update CompositionAwareMixin to correctly compute composingBase
1 parent 2fe8489 commit 169cb2f

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

AUTHORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ Koutaro Mori <koutaro.mo@gmail.com>
2323
TheOneWithTheBraid <the-one@with-the-braid.cf>
2424
Twin Sun, LLC <google-contrib@twinsunsolutions.com>
2525
Qixing Cao <qixing.cao.83@gmail.com>
26-
LinXunFeng <linxunfeng@yeah.net>
26+
LinXunFeng <linxunfeng@yeah.net>
27+
Amir Panahandeh <amirpanahandeh@gmail.com>

lib/web_ui/lib/src/engine/text_editing/composition_aware_mixin.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ mixin CompositionAwareMixin {
7575
return editingState;
7676
}
7777

78-
final int composingBase = editingState.baseOffset! - composingText!.length;
78+
final int composingBase = editingState.extentOffset! - composingText!.length;
7979

8080
if (composingBase < 0) {
8181
return editingState;

lib/web_ui/test/engine/composition_test.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Future<void> testMain() async {
106106
});
107107

108108
group('determine composition state', () {
109-
test('should return new composition state if valid new composition', () {
109+
test('should return new composition state - compositing middle of text', () {
110110
const int baseOffset = 100;
111111
const String composingText = 'composeMe';
112112

@@ -128,6 +128,30 @@ Future<void> testMain() async {
128128
composingBaseOffset: expectedComposingBase,
129129
composingExtentOffset: expectedComposingBase + composingText.length));
130130
});
131+
132+
test('should return new composition state - compositing from beginning of text', () {
133+
const String composingText = '今日は';
134+
135+
final EditingState editingState = EditingState(
136+
text: '今日は',
137+
baseOffset: 0,
138+
extentOffset: 3,
139+
);
140+
141+
final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin =
142+
_MockWithCompositionAwareMixin();
143+
mockWithCompositionAwareMixin.composingText = composingText;
144+
145+
const int expectedComposingBase = 0;
146+
147+
expect(
148+
mockWithCompositionAwareMixin
149+
.determineCompositionState(editingState),
150+
editingState.copyWith(
151+
composingBaseOffset: expectedComposingBase,
152+
composingExtentOffset:
153+
expectedComposingBase + composingText.length));
154+
});
131155
});
132156
});
133157

0 commit comments

Comments
 (0)