public void setEditingState(TextEditingValue state) { this._value = state; if (this._keyboard != null && this._keyboard.active) { this._keyboard.text = state.text; if (this._value.selection != null && this._value.selection.isValid) { int start = this._value.selection.start; int end = this._value.selection.end; this._pendingSelection = new RangeInt(start, end - start); RangeInt selection = new RangeInt(state.selection.start, end - start); if (this._keyboard.canGetSelection) { this._pendingSelection = null; this._keyboard.selection = selection; } else { this._pendingSelection = selection; } } } }
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; var oldValue = this._value; if (currentEvent != null && currentEvent.type == EventType.KeyDown) { if (currentEvent.keyCode == KeyCode.Backspace) { if (this._value.selection.isValid) { this._value = this._value.deleteSelection(true); } } else if (currentEvent.character != '\0') { this._value = this._value.clearCompose(); char ch = currentEvent.character; if (ch == '\r' || ch == 3) { ch = '\n'; } if (ch == '\n') { Window.instance.run(() => { TextInput._performAction(this._client, TextInputAction.newline); }); } if (_validateCharacter(ch)) { this._value = this._value.insert(new string(ch, 1)); } } else if (!string.IsNullOrEmpty(Input.compositionString)) { this._value = this._value.compose(Input.compositionString); } currentEvent.Use(); } if (this._value != oldValue) { Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); }); } }
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; }
internal static TextEditingValue truncate(TextEditingValue value, int maxLength) { TextSelection newSelection = value.selection.copyWith( baseOffset: Mathf.Min(value.selection.start, maxLength), extentOffset: Mathf.Min(value.selection.end, maxLength)); string truncated = value.text.Substring(0, maxLength); return(new TextEditingValue( text: truncated, selection: newSelection, composing: TextRange.empty )); }
internal void _updateEditingState(int client, TextEditingValue value) { if (this._currentConnection == null) { return; } if (client != this._currentConnection._id) { return; } this._currentConnection._client.updateEditingValue(value); }
internal static void _updateEditingState(int client, TextEditingValue value, bool isIMEInput = false) { if (_currentConnection == null) { return; } if (client != _currentConnection._id) { return; } _currentConnection._client.updateEditingValue(value, isIMEInput); }
public void Update() { if (!TouchScreenKeyboard.isSupported) { return; } if (this._client == 0 || this._keyboard == null) { return; } if (this._keyboard.canSetSelection && this._pendingSelection != null) { this._keyboard.selection = this._pendingSelection.Value; this._pendingSelection = null; } if (this._keyboard.status == TouchScreenKeyboard.Status.Done) { if (!this._screenKeyboardDone) { this._screenKeyboardDone = true; Window.instance.run(() => { this._textInput._performAction(this._client, TextInputAction.done); }); } } else if (this._keyboard.status == TouchScreenKeyboard.Status.Visible) { var keyboardSelection = this._keyboard.selection; var newValue = new TextEditingValue( this._keyboard.text, this._keyboard.canGetSelection ? new TextSelection(keyboardSelection.start, keyboardSelection.end) : this._value.selection ); var changed = this._value != newValue; this._value = newValue; if (changed) { Window.instance.run(() => { this._textInput._updateEditingState(this._client, this._value); }); } } }
public override TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) { return(Util._selectionAwareTextManipulation( value: newValue, substringManipulation: substring => { string groups = ""; foreach (Match match in whitelistedPattern.Matches(input: substring)) { groups += match.Groups[0].Value; } return groups; } )); }
internal static TextEditingValue _selectionAwareTextManipulation(TextEditingValue value, Func <string, string> substringManipulation) { int selectionStartIndex = value.selection.start; int selectionEndIndex = value.selection.end; string manipulatedText; TextSelection manipulatedSelection = null; if (selectionStartIndex < 0 || selectionEndIndex < 0) { manipulatedText = substringManipulation(value.text); } else { var beforeSelection = substringManipulation( value.text.Substring(0, selectionStartIndex) ); var inSelection = substringManipulation( value.text.Substring(selectionStartIndex, selectionEndIndex - selectionStartIndex) ); var afterSelection = substringManipulation( value.text.Substring(selectionEndIndex) ); manipulatedText = beforeSelection + inSelection + afterSelection; if (value.selection.baseOffset > value.selection.extentOffset) { manipulatedSelection = value.selection.copyWith( baseOffset: beforeSelection.Length + inSelection.Length, extentOffset: beforeSelection.Length ); } else { manipulatedSelection = value.selection.copyWith( baseOffset: beforeSelection.Length, extentOffset: beforeSelection.Length + inSelection.Length ); } } return(new TextEditingValue( text: manipulatedText, selection: manipulatedSelection ?? TextSelection.collapsed(offset: -1), composing: manipulatedText == value.text ? value.composing : TextRange.empty )); }
public void Update() { if (_client == 0 || _keyboard == null) { return; } if (_keyboard.canSetSelection && _pendingSelection != null) { _keyboard.selection = _pendingSelection.Value; _pendingSelection = null; } if (_keyboard.status == TouchScreenKeyboard.Status.Done) { if (!_screenKeyboardDone) { _screenKeyboardDone = true; Timer.create(TimeSpan.Zero, () => { TextInput._performAction(_client, TextInputAction.done); }); } } else if (_keyboard.status == TouchScreenKeyboard.Status.Visible) { var keyboardSelection = _keyboard.selection; var newValue = new TextEditingValue( _keyboard.text, _keyboard.canGetSelection ? new TextSelection(keyboardSelection.start, keyboardSelection.end) : TextSelection.collapsed(0) ); var changed = _value != newValue; _value = newValue; if (changed) { Timer.create(TimeSpan.Zero, () => { TextInput._updateEditingState(_client, _value); }); } } }
public override TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) { if (this.maxLength != null && this.maxLength > 0 && newValue.text.Length > this.maxLength) { TextSelection newSelection = newValue.selection.copyWith( baseOffset: Math.Min(newValue.selection.start, this.maxLength.Value), extentOffset: Math.Min(newValue.selection.end, this.maxLength.Value) ); string truncated = newValue.text.Substring(0, this.maxLength.Value); return(new TextEditingValue( text: truncated, selection: newSelection, composing: TextRange.empty )); } return(newValue); }
public override TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) { if (maxLength != null && maxLength > 0 && newValue.text.Length > maxLength) { if (Input.compositionString.Length > 0) { return(newValue); } if (oldValue.text.Length == maxLength.Value) { return(oldValue); } return(truncate(newValue, maxLength.Value)); } return(newValue); }
public override TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) { return(Util._selectionAwareTextManipulation(newValue, (substring) => blacklistedPattern.Replace(substring, replacementString))); }
public void setEditingState(TextEditingValue value) { D.assert(this.attached); TextInput.keyboardDelegate.setEditingState(value); }
public override void setEditingState(TextEditingValue value) { UIWidgetsTextInputSetTextInputEditingState(value.toJson().ToString()); }
public void setEditingState(TextEditingValue value) { this._value = value; }
public abstract void setEditingState(TextEditingValue value);
public void setEditingState(TextEditingValue value) { D.assert(this.attached); this._textInput.keyboardManager.setEditingState(value); }
public void OnGUI() { if (TouchScreenKeyboard.isSupported) { return; } if (_client == 0) { return; } while (!PointerEventConverter.KeyEvent.isEmpty()) { var currentEvent = PointerEventConverter.KeyEvent.Dequeue(); var oldValue = _value; if (currentEvent != null && currentEvent.type == EventType.KeyDown) { var response = TextInput._handleGlobalInputKey(_client, new RawKeyDownEvent(new RawKeyEventData(currentEvent))); if (response.swallow) { if (response.inputAction != null) { Timer.create(TimeSpan.Zero, () => { TextInput._performAction(_client, response.inputAction.Value); }); } if (_validateCharacter(response.input)) { _value = _value.insert(new string(response.input, 1)); } } else if (currentEvent.keyCode == KeyCode.Backspace) { if (_value.selection.isValid) { _value = _value.deleteSelection(true); } } else if (currentEvent.character != 0) { _value = _value.clearCompose(); char ch = currentEvent.character; if (ch == '\r' || ch == 3) { ch = '\n'; } if (ch == '\n') { Timer.create(TimeSpan.Zero, () => { TextInput._performAction(_client, _textInputConfiguration?.inputAction ?? TextInputAction.newline); }); } if (_validateCharacter(ch)) { _value = _value.insert(new string(ch, 1)); } } else if (!string.IsNullOrEmpty(currentEvent.keyCode.ToString())) { isIMEInput = true; _value = _value.compose(currentEvent.keyCode.ToString()); } currentEvent.Use(); } if (_value != oldValue) { if (this.isIMEInput) { var isIMEInput = this.isIMEInput; Timer.create(TimeSpan.Zero, () => { TextInput._updateEditingState(_client, _value, isIMEInput); }); this.isIMEInput = false; } else { Timer.create(TimeSpan.Zero, () => { TextInput._updateEditingState(_client, _value, isIMEInput); }); } } } }
public void OnGUI() { if (TouchScreenKeyboard.isSupported) { return; } if (this._client == 0) { return; } var currentEvent = Event.current; var oldValue = this._value; if (currentEvent != null && currentEvent.type == EventType.KeyDown) { var response = TextInput._handleGlobalInputKey(this._client, new RawKeyDownEvent(new RawKeyEventData(currentEvent))); if (response.swallow) { if (response.inputAction != null) { Window.instance.run(() => { TextInput._performAction(this._client, response.inputAction.Value); }); } if (_validateCharacter(response.input)) { this._value = this._value.insert(new string(response.input, 1)); } } else if (currentEvent.keyCode == KeyCode.Backspace) { if (this._value.selection.isValid) { this._value = this._value.deleteSelection(true); } } else if (currentEvent.character != '\0') { this._value = this._value.clearCompose(); char ch = currentEvent.character; if (ch == '\r' || ch == 3) { ch = '\n'; } if (ch == '\n') { Window.instance.run(() => { TextInput._performAction(this._client, TextInputAction.newline); }); } if (_validateCharacter(ch)) { this._value = this._value.insert(new string(ch, 1)); } } else if (!string.IsNullOrEmpty(Input.compositionString)) { this.isIMEInput = true; this._value = this._value.compose(Input.compositionString); } currentEvent.Use(); } if (this._value != oldValue) { 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); }); } } }
public override TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) { return(formatFunction(oldValue, newValue)); }
public abstract TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue);