Repository: AppFlowy-IO/appflowy-editor

Issue:
[Bug] Windows input method issues
### Bug Description

When using Sogou Input Method to input certain Chinese characters, the order of characters may be disrupted, as shown in the video

### How to Reproduce

1. Sogou Input Method
2. 让这
3. 三人
4. 每人
5. 赚

turn out:让这三人赚人每

### Expected Behavior

Normal input

### Operating System

desktop

### AppFlowy Version(s)

main

### Screenshots


https://github.com/user-attachments/assets/f4a1a24e-43bc-4ea5-af80-10a1961d7a06



### Additional Context

_No response_


Discussion: Assign to me

Fix patch:
diff --git a/lib/src/editor/editor_component/service/ime/text_diff.dart b/lib/src/editor/editor_component/service/ime/text_diff.dart
index 5bafb1bc3..32ab80cb6 100644
--- a/lib/src/editor/editor_component/service/ime/text_diff.dart
+++ b/lib/src/editor/editor_component/service/ime/text_diff.dart
@@ -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--;
   }
 


Test patch:
diff --git a/test/editor/editor_component/ime/text_diff_test.dart b/test/editor/editor_component/ime/text_diff_test.dart
index 58d96787e..3b5152446 100644
--- a/test/editor/editor_component/ime/text_diff_test.dart
+++ b/test/editor/editor_component/ime/text_diff_test.dart
@@ -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');