Skip to content

Commit

Permalink
fix: input chinese issue (#608)
Browse files Browse the repository at this point in the history
* fix:input chinese issue

* fix:input chinese issue

* fix:input_chinese_issue

* fix:610
  • Loading branch information
q200892907 authored Dec 7, 2023
1 parent f4834b5 commit 67e60ec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,16 @@ Future<void> onNonTextUpdate(
},
);
}
} else if (PlatformExtension.isMacOS) {
if (selection != null) {
editorState.updateSelectionWithReason(
Selection.collapsed(
Position(
path: selection.start.path,
offset: nonTextUpdate.selection.start,
),
),
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
TextEditingValue? get currentTextEditingValue => _currentTextEditingValue;

TextEditingValue? _currentTextEditingValue;

set currentTextEditingValue(TextEditingValue? newValue) {
_currentTextEditingValue = newValue;
}
Expand Down Expand Up @@ -90,6 +91,7 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
if (currentTextEditingValue == value) {
return;
}

final deltas = getTextEditingDeltas(currentTextEditingValue, value);
// On mobile, the IME will send a lot of updateEditingValue events, so we
// need to debounce it to combine them together.
Expand Down Expand Up @@ -176,7 +178,9 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
}
}

if ((PlatformExtension.isWindows || PlatformExtension.isLinux) &&
if ((PlatformExtension.isWindows ||
PlatformExtension.isLinux ||
PlatformExtension.isMacOS) &&
delta is TextEditingDeltaNonTextUpdate) {
composingTextRange = delta.composing;
}
Expand Down Expand Up @@ -256,7 +260,9 @@ extension on TextEditingDeltaNonTextUpdate {

extension on TextSelection {
TextSelection operator <<(int shiftAmount) => shift(-shiftAmount);

TextSelection operator >>(int shiftAmount) => shift(shiftAmount);

TextSelection shift(int shiftAmount) => TextSelection(
baseOffset: max(0, baseOffset + shiftAmount),
extentOffset: max(0, extentOffset + shiftAmount),
Expand All @@ -265,7 +271,9 @@ extension on TextSelection {

extension on TextRange {
TextRange operator <<(int shiftAmount) => shift(-shiftAmount);

TextRange operator >>(int shiftAmount) => shift(shiftAmount);

TextRange shift(int shiftAmount) => !isValid
? this
: TextRange(
Expand All @@ -276,6 +284,7 @@ extension on TextRange {

extension on String {
String operator <<(int shiftAmount) => shift(shiftAmount);

String shift(int shiftAmount) {
if (shiftAmount > length) {
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>
/// handle hardware keyboard
KeyEventResult _onKey(FocusNode node, RawKeyEvent event) {
if (event is! RawKeyDownEvent || !enableShortcuts) {
if (textInputService.composingTextRange != TextRange.empty) {
return KeyEventResult.skipRemainingHandlers;
}
return KeyEventResult.ignored;
}

Expand Down

0 comments on commit 67e60ec

Please sign in to comment.