public TextEditingValue(string text = "", TextSelection selection = null, TextRange composing = null) { this.text = text; this.composing = composing ?? TextRange.empty; if (selection != null && selection.start >= 0 && selection.end >= 0) { // handle surrogate pair emoji, which takes 2 utf16 chars // if selection cuts in the middle of the emoji, move it to the end int start = selection.start, end = selection.end; if (start < text.Length && char.IsLowSurrogate(text[start])) { start++; } if (end < text.Length && char.IsLowSurrogate(text[end])) { end++; } this.selection = selection.copyWith(start, end); } else { this.selection = TextSelection.collapsed(-1); } }
//unity-specific public TextEditingValue moveExtent(int move) { int offset = selection.extentOffset + move; offset = Mathf.Max(0, offset); offset = Mathf.Min(offset, text.Length); return(copyWith(selection: selection.copyWith(extentOffset: offset))); }