void _handleMethodCall(string method, List <JSONNode> args) { if (TextInput._currentConnection == null) { return; } int client = args[0].AsInt; if (client != TextInput._currentConnection._id) { return; } using (TextInput._currentConnection._window.getScope()) { switch (method) { case "TextInputClient.updateEditingState": TextInput._updateEditingState(client, TextEditingValue.fromJson(args[1].AsObject)); break; case "TextInputClient.performAction": TextInput._performAction(client, TextInputUtils._toTextInputAction(args[1].Value)); break; default: throw new UIWidgetsError($"unknown method ${method}"); } } }
public void OnGUI() { if (TouchScreenKeyboard.isSupported) { return; } if (this._client == 0) { return; } var currentEvent = Event.current; if (currentEvent != null && currentEvent.type == EventType.KeyDown) { var action = TextInputUtils.getInputAction(currentEvent); if (action != null) { Window.instance.run(() => { TextInput._performAction(this._client, action.Value); }); } if (action == null || action == TextInputAction.newline) { if (currentEvent.keyCode == KeyCode.None) { char ch = currentEvent.character; if (ch == '\r' || ch == 3) { ch = '\n'; } this._value = this._value.clearCompose(); if (_validateCharacter(ch)) { this._value = this._value.insert(new string(ch, 1)); } Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); }); } } currentEvent.Use(); } if (!string.IsNullOrEmpty(Input.compositionString) && this._lastCompositionString != Input.compositionString) { this._value = this._value.compose(Input.compositionString); Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); }); } this._lastCompositionString = Input.compositionString; }
public static TextEditingValue fromJson(JSONObject json) { TextAffinity?affinity = TextInputUtils._toTextAffinity(json["selectionAffinity"].Value); return(new TextEditingValue( text: json["text"].Value, selection: new TextSelection( baseOffset: json.GetValueOrDefault("selectionBase", defaultIndexNode).AsInt, extentOffset: json.GetValueOrDefault("selectionExtent", defaultIndexNode).AsInt, affinity: affinity != null ? affinity.Value : TextAffinity.downstream, isDirectional: json["selectionIsDirectional"].AsBool ), composing: new TextRange( start: json.GetValueOrDefault("composingBase", defaultIndexNode).AsInt, end: json.GetValueOrDefault("composingExtent", defaultIndexNode).AsInt ) )); }