浏览代码

[Fix] TextField maxLength wrong IME input behavior

/main
iizzaya 5 年前
当前提交
8e8058fb
共有 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 imeInput = this.isimeInput;
Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value, imeInput); });
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 imeInput);
void performAction(TextInputAction action);

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

}
_currentConnection._client.updateEditingValue(value);
_currentConnection._client.updateEditingValue(value, imeInput);
}
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 imeInput) {
if (value.text != this._value.text) {
this._hideSelectionOverlayIfNeeded();
this._showCaretOnScreen();

}
this._lastKnownRemoteTextEditingValue = value;
this._formatAndSetValue(value);
this._formatAndSetValue(value, imeInput);
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 imeInput = false) {
var textChanged = this._value?.text != value?.text || imeInput;
if (textChanged && this.widget.inputFormatters != null && this.widget.inputFormatters.isNotEmpty()) {
foreach (var formatter in this.widget.inputFormatters) {
value = formatter.formatEditUpdate(this._value, value);

正在加载...
取消
保存