public TextEditorInfo(string fullText, string selectedText, int selectIndex, int cursorIndex, int addedChars, bool textLengthChanged, SmartTextEditor textEditor) { _fullText = fullText; _selectedText = selectedText; _selectIndex = selectIndex; _cursorIndex = cursorIndex; _addedChars = addedChars; _lengthChanged = textLengthChanged; TextEditor = textEditor; }
private static int HandleTextFieldEventForDesktop(Rect position, int id, GUIContent content, bool multiline, int maxLength, GUIStyle style, SmartTextEditor editor) { Event current = Event.current; bool flag = false; var charsAdded = 0; _cursorIndex = editor.cursorIndex; switch (current.type) { case EventType.MouseDown: if (position.Contains(current.mousePosition)) { GUIUtility.hotControl = id; GUIUtility.keyboardControl = id; _hasFocusProperty.SetValue(editor, true); editor.MoveCursorToPosition(Event.current.mousePosition); if (Event.current.clickCount == 2 && GUI.skin.settings.doubleClickSelectsWord) { editor.SelectCurrentWord(); editor.DblClickSnap(TextEditor.DblClickSnapping.WORDS); editor.MouseDragSelectsWholeWords(on: true); } if (Event.current.clickCount == 3 && GUI.skin.settings.tripleClickSelectsLine) { editor.SelectCurrentParagraph(); editor.MouseDragSelectsWholeWords(on: true); editor.DblClickSnap(TextEditor.DblClickSnapping.PARAGRAPHS); } current.Use(); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { if (current.shift) { editor.MoveCursorToPosition(Event.current.mousePosition); } else { editor.SelectToPosition(Event.current.mousePosition); } current.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id) { editor.MouseDragSelectsWholeWords(on: false); GUIUtility.hotControl = 0; current.Use(); } break; case EventType.KeyDown: { var originalTextLength = content.text.Length; if (GUIUtility.keyboardControl != id) { return(charsAdded); } if (editor.HandleKeyEvent(current)) { current.Use(); flag = true; content.text = editor.text; if (editor.text.Length != originalTextLength) { if (editor.text.Length < originalTextLength) { var deleted = originalTextLength - editor.text.Length; charsAdded = -deleted; } else { charsAdded = editor.text.Length - originalTextLength; } } break; } if (current.keyCode == KeyCode.Tab || current.character == '\t') { return(0); } char character = current.character; if (character == '\n' && !multiline && !current.alt) { return(charsAdded); } Font font = style.font; if (!font) { font = GUI.skin.font; } if (font.HasCharacter(character) || character == '\n') { editor.Insert(character); flag = true; charsAdded++; } else if (character == '\0') //if is null char { if (_compositionString.Length > 0) { editor.ReplaceSelection(""); flag = true; } if (!current.control && !current.command) { current.Use(); } } if (editor.text.Length != originalTextLength) { if (editor.text.Length < originalTextLength) { var deleted = originalTextLength - editor.text.Length; charsAdded = -deleted; } } break; } case EventType.Repaint: if (GUIUtility.keyboardControl != id) { style.Draw(position, content, id, on: false); } else { editor.DrawCursor(content.text); } break; } if (GUIUtility.keyboardControl == id) { _textFieldInput.SetValue(null, true); } if (flag) { //changed = true; content.text = editor.text; if (maxLength >= 0 && content.text.Length > maxLength) { content.text = content.text.Substring(0, maxLength); } current.Use(); } _cursorIndex = editor.cursorIndex; return(charsAdded); }