/// <summary> /// /// </summary> /// <param name="value"></param> public void ReplaceSelection(string value) { if (!editable) { throw new Exception("InputTextField is not editable."); } if (!_editing) { Stage.inst.focus = this; } textField.Rebuild(); int t0, t1; if (_selectionStart != _caretPosition) { if (_selectionStart < _caretPosition) { t0 = _selectionStart; t1 = _caretPosition; _caretPosition = _selectionStart; } else { t0 = _caretPosition; t1 = _selectionStart; _selectionStart = _caretPosition; } } else { if (string.IsNullOrEmpty(value)) { return; } t0 = t1 = _caretPosition; } StringBuilder buffer = new StringBuilder(); buffer.Append(_text, 0, t0); if (!string.IsNullOrEmpty(value)) { value = ToolSet.FormatCRLF(value); value = ValidateInput(value); buffer.Append(value); _caretPosition += value.Length; } buffer.Append(_text, t1 + _composing, _text.Length - t1 - _composing); if (maxLength > 0 && buffer.Length > maxLength) { buffer.Length = maxLength; } this.text = buffer.ToString(); onChanged.Call(); }