浏览代码

Merge pull request #327 from IIzzaya/master

[Fix] TextField maxLength wrong IME input behavior
/main
GitHub 5 年前
当前提交
55fd597a
共有 4 个文件被更改,包括 26 次插入10 次删除
  1. 15
      Runtime/service/keyboard.cs
  2. 7
      Runtime/service/text_formatter.cs
  3. 6
      Runtime/service/text_input.cs
  4. 8
      Runtime/widgets/editable_text.cs

15
Runtime/service/keyboard.cs


return true;
}
bool isIMEInput = false;
public void OnGUI() {
if (TouchScreenKeyboard.isSupported) {
return;

if (_validateCharacter(ch)) {
this._value = this._value.insert(new string(ch, 1));
}
} else if (!string.IsNullOrEmpty(Input.compositionString)) {
}
else if (!string.IsNullOrEmpty(Input.compositionString)) {
this.isIMEInput = true;
this._value = this._value.compose(Input.compositionString);
}

if (this._value != oldValue) {
Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); });
if (this.isIMEInput) {
var isIMEInput = this.isIMEInput;
Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value, isIMEInput); });
this.isIMEInput = false;
}
else {
Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); });
}
}
}

7
Runtime/service/text_formatter.cs


public override TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
if (this.maxLength != null && this.maxLength > 0 && newValue.text.Length > this.maxLength) {
if (Input.compositionString.Length > 0) {
return newValue;
}
TextSelection newSelection = newValue.selection.copyWith(
baseOffset: Mathf.Min(newValue.selection.start, this.maxLength.Value),
extentOffset: Mathf.Min(newValue.selection.end, this.maxLength.Value)

composing: TextRange.empty
);
}
}
}
static class Util {
internal static TextEditingValue _selectionAwareTextManipulation(TextEditingValue value,

6
Runtime/service/text_input.cs


}
public interface TextInputClient {
void updateEditingValue(TextEditingValue value);
void updateEditingValue(TextEditingValue value, bool isIMEInput);
void performAction(TextInputAction action);

}
}
internal static void _updateEditingState(int client, TextEditingValue value) {
internal static void _updateEditingState(int client, TextEditingValue value, bool isIMEInput = false) {
if (_currentConnection == null) {
return;
}

}
_currentConnection._client.updateEditingValue(value);
_currentConnection._client.updateEditingValue(value, isIMEInput);
}
internal static void _performAction(int client, TextInputAction action) {

8
Runtime/widgets/editable_text.cs


TextEditingValue _lastKnownRemoteTextEditingValue;
public void updateEditingValue(TextEditingValue value) {
public void updateEditingValue(TextEditingValue value, bool isIMEInput) {
if (value.text != this._value.text) {
this._hideSelectionOverlayIfNeeded();
this._showCaretOnScreen();

}
this._lastKnownRemoteTextEditingValue = value;
this._formatAndSetValue(value);
this._formatAndSetValue(value, isIMEInput);
this._stopCursorTimer(resetCharTicks: false);
this._startCursorTimer();

return Promise<bool>.Resolved(false);
}
void _formatAndSetValue(TextEditingValue value) {
var textChanged = this._value?.text != value?.text;
void _formatAndSetValue(TextEditingValue value, bool isIMEInput = false) {
var textChanged = this._value?.text != value?.text || isIMEInput;
if (textChanged && this.widget.inputFormatters != null && this.widget.inputFormatters.isNotEmpty()) {
foreach (var formatter in this.widget.inputFormatters) {
value = formatter.formatEditUpdate(this._value, value);

正在加载...
取消
保存