Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sougou IME issue on Windows #1000

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/src/editor/editor_component/service/ime/text_diff.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Diff getDiff(String oldText, String newText, int cursorPosition) {
final delta = newText.length - end;
final limit = math.max(0, cursorPosition - delta);

while (end > limit && oldText[end - 1] == newText[end + delta - 1]) {
while (end > limit &&
oldText[end - 1] == newText[end + delta - 1] &&
!newText.startsWith(oldText)) {
end--;
}

Expand Down
8 changes: 8 additions & 0 deletions test/editor/editor_component/ime/text_diff_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ void main() {
expect(diff.toString(), 'Diff[0, "", "W"]');
});

test('getDiff for Chinese', () {
const oldText = '一个';
const newText = '一个两个';

final diff = getDiff(oldText, newText, 0);
expect(diff.toString(), 'Diff[2, "", "两个"]');
});

test('getTextEditingDeltas insertion', () {
const oldValue = TextEditingValue(text: 'elcome');
const newValue = TextEditingValue(text: 'Welcome');
Expand Down
Loading