fix: sougou IME issue on Windows (#1000)

This commit is contained in:
Morn 2024-12-24 15:47:45 +08:00 • committed by GitHub
commit 4edd0e00e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -29,7 +29,9 @@ Diff getDiff(String oldText, String newText, int cursorPosition) {
final delta = newText.length - end; final delta = newText.length - end;
final limit = math.max(0, cursorPosition - delta); 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--; end--;
} }

View file

@ -19,6 +19,14 @@ void main() {
expect(diff.toString(), 'Diff[0, "", "W"]'); 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', () { test('getTextEditingDeltas insertion', () {
const oldValue = TextEditingValue(text: 'elcome'); const oldValue = TextEditingValue(text: 'elcome');
const newValue = TextEditingValue(text: 'Welcome'); const newValue = TextEditingValue(text: 'Welcome');