public void TextEditorWithUTF16_MiddleCursorOnBackspace_RemovesBothSurrogatesInSuccession()
    {
        var textBox = new TextEditor()
        {
            text        = "Mike🗘🗘🗘DeRoy",
            cursorIndex = 8,
            selectIndex = 8,
        };

        textBox.Backspace();

        Assert.AreEqual("Mike🗘🗘DeRoy", textBox.text, kFailedToRemoveCharacterMessage);
        Assert.AreEqual(6, textBox.cursorIndex, kFailedToChangeCursor);
        Assert.AreEqual(6, textBox.selectIndex, kFailedToChangeSelect);

        textBox.Backspace();

        Assert.AreEqual("Mike🗘DeRoy", textBox.text, kFailedToRemoveCharacterMessage);
        Assert.AreEqual(4, textBox.cursorIndex, kFailedToChangeCursor);
        Assert.AreEqual(4, textBox.selectIndex, kFailedToChangeSelect);

        textBox.Backspace();
        Assert.AreEqual("Mik🗘DeRoy", textBox.text, kFailedToRemoveCharacterMessage);
        Assert.AreEqual(3, textBox.cursorIndex, kFailedToChangeCursor);
        Assert.AreEqual(3, textBox.selectIndex, kFailedToChangeSelect);
    }
Esempio n. 2
0
        void HandleRequests()
        {
            var current = Event.current;

            if (requestMoveToCursorToEnd && current.type == EventType.Repaint)
            {
                textEditor.MoveTextEnd();
                requestMoveToCursorToEnd = false;
                Repaint();
            }
            else if (focusedWindow == this && requestFocusOnTextArea)
            {
                GUI.FocusControl(ConsoleTextAreaControlName);
                requestFocusOnTextArea = false;
                Repaint();
            }

            var cursorPos = textEditor.graphicalCursorPos;

            if (current.type == EventType.Repaint && cursorPos.y > lastCursorPos.y && requestRevertNewLine)
            {
                textEditor.Backspace();
                textEditor.MoveTextEnd();
                Repaint();
                requestRevertNewLine = false;
            }

            lastCursorPos = cursorPos;
        }
Esempio n. 3
0
        public void Merge_current_line_with_previous_if_backspacing_at_start()
        {
            var sut = new TextEditor("abc\ndef", 5);

            var position = sut.Backspace(1, 0);

            Assert.AreEqual((0, 3), position);
            Assert.AreEqual("abcdef", sut.Text);
        }
Esempio n. 4
0
        public void Backspace_in_line()
        {
            var sut = new TextEditor("abc\ndef", 5);

            var position = sut.Backspace(1, 1);

            Assert.AreEqual((1, 0), position);
            Assert.AreEqual("abc\nef", sut.Text);
        }
    public void TextEditorWithUTF16_LeftCursorOnBackspace_DoesNotRemoveCharacter()
    {
        var textBox = new TextEditor()
        {
            text        = "MikeDeRoy",
            cursorIndex = 0,
            selectIndex = 0,
        };

        textBox.Backspace();

        Assert.AreEqual("MikeDeRoy", textBox.text, kFailedToRemoveCharacterMessage);
        Assert.AreEqual(0, textBox.cursorIndex, kFailedToChangeCursor);
        Assert.AreEqual(0, textBox.selectIndex, kFailedToChangeSelect);
    }
    public void TextEditorWithUTF16_RightCursorOnBackspaceAndRightSurrogate_RemovesBothSurrogates()
    {
        var textBox = new TextEditor()
        {
            text        = "MikeDeRoy🗘",
            cursorIndex = 11,
            selectIndex = 11,
        };

        textBox.Backspace();

        Assert.AreEqual("MikeDeRoy", textBox.text, kFailedToRemoveCharacterMessage);
        Assert.AreEqual(9, textBox.cursorIndex, kFailedToChangeCursor);
        Assert.AreEqual(9, textBox.selectIndex, kFailedToChangeSelect);
    }
    public void Backspace_RemovesCodePointLeftOfCursor(string text, int[] codePointIndices)
    {
        for (var i = codePointIndices.Length - 1; i >= 0; i--)
        {
            var codePointIndex = codePointIndices[i];
            m_TextEditor.text        = text;
            m_TextEditor.cursorIndex = m_TextEditor.selectIndex = codePointIndex;
            var oldCursorIndex = m_TextEditor.cursorIndex;
            var oldSelectIndex = m_TextEditor.selectIndex;

            m_TextEditor.Backspace();

            var previousCodePointIndex = i > 0 ? codePointIndices[i - 1] : codePointIndex;
            var codePointLength        = codePointIndex - previousCodePointIndex;
            Assert.AreEqual(oldCursorIndex - codePointLength, m_TextEditor.cursorIndex, string.Format("cursorIndex {0} did not move to before removed code point", oldCursorIndex));
            Assert.AreEqual(oldSelectIndex - codePointLength, m_TextEditor.selectIndex, string.Format("selectIndex {0} did not move to before removed code point", oldSelectIndex));
            Assert.AreEqual(text.Remove(previousCodePointIndex, codePointLength), m_TextEditor.text);
        }
    }
Esempio n. 8
0
    // Token: 0x06004E9F RID: 20127 RVA: 0x00145428 File Offset: 0x00143628
    private static bool PerformOperation(TextEditor te, global::UIUnityEvents.TextEditOp operation)
    {
        switch (operation)
        {
        case global::UIUnityEvents.TextEditOp.MoveLeft:
            te.MoveLeft();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveRight:
            te.MoveRight();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveUp:
            te.MoveUp();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveDown:
            te.MoveDown();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveLineStart:
            te.MoveLineStart();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveLineEnd:
            te.MoveLineEnd();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveTextStart:
            te.MoveTextStart();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveTextEnd:
            te.MoveTextEnd();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveGraphicalLineStart:
            te.MoveGraphicalLineStart();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveGraphicalLineEnd:
            te.MoveGraphicalLineEnd();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveWordLeft:
            te.MoveWordLeft();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveWordRight:
            te.MoveWordRight();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveParagraphForward:
            te.MoveParagraphForward();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveParagraphBackward:
            te.MoveParagraphBackward();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveToStartOfNextWord:
            te.MoveToStartOfNextWord();
            return(false);

        case global::UIUnityEvents.TextEditOp.MoveToEndOfPreviousWord:
            te.MoveToEndOfPreviousWord();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectLeft:
            te.SelectLeft();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectRight:
            te.SelectRight();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectUp:
            te.SelectUp();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectDown:
            te.SelectDown();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectTextStart:
            te.SelectTextStart();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectTextEnd:
            te.SelectTextEnd();
            return(false);

        case global::UIUnityEvents.TextEditOp.ExpandSelectGraphicalLineStart:
            te.ExpandSelectGraphicalLineStart();
            return(false);

        case global::UIUnityEvents.TextEditOp.ExpandSelectGraphicalLineEnd:
            te.ExpandSelectGraphicalLineEnd();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectGraphicalLineStart:
            te.SelectGraphicalLineStart();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectGraphicalLineEnd:
            te.SelectGraphicalLineEnd();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectWordLeft:
            te.SelectWordLeft();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectWordRight:
            te.SelectWordRight();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectToEndOfPreviousWord:
            te.SelectToEndOfPreviousWord();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectToStartOfNextWord:
            te.SelectToStartOfNextWord();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectParagraphBackward:
            te.SelectParagraphBackward();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectParagraphForward:
            te.SelectParagraphForward();
            return(false);

        case global::UIUnityEvents.TextEditOp.Delete:
            return(te.Delete());

        case global::UIUnityEvents.TextEditOp.Backspace:
            return(te.Backspace());

        case global::UIUnityEvents.TextEditOp.DeleteWordBack:
            return(te.DeleteWordBack());

        case global::UIUnityEvents.TextEditOp.DeleteWordForward:
            return(te.DeleteWordForward());

        case global::UIUnityEvents.TextEditOp.Cut:
            return(te.Cut());

        case global::UIUnityEvents.TextEditOp.Copy:
            te.Copy();
            return(false);

        case global::UIUnityEvents.TextEditOp.Paste:
            return(te.Paste());

        case global::UIUnityEvents.TextEditOp.SelectAll:
            te.SelectAll();
            return(false);

        case global::UIUnityEvents.TextEditOp.SelectNone:
            te.SelectNone();
            return(false);
        }
        Debug.Log("Unimplemented: " + operation);
        return(false);
    }
Esempio n. 9
0
    /// <summary>
    /// Handle the specified event.
    /// </summary>

    bool ProcessEvent(Event ev)
    {
        RuntimePlatform rp    = Application.platform;
        bool            isMac = (rp == RuntimePlatform.OSXEditor || rp == RuntimePlatform.OSXPlayer || rp == RuntimePlatform.OSXWebPlayer);
        bool            ctrl  = isMac ? (ev.modifiers == EventModifiers.Command) : (ev.modifiers == EventModifiers.Control);

        switch (ev.keyCode)
        {
        case KeyCode.Backspace:
        {
            ev.Use();
            mEditor.Backspace();
            UpdateLabel();
            ExecuteOnChange();
            return(true);
        }

        case KeyCode.Delete:
        {
            ev.Use();
            mEditor.Delete();
            UpdateLabel();
            ExecuteOnChange();
            return(true);
        }

        case KeyCode.LeftArrow:
        {
            ev.Use();
            mEditor.MoveLeft();
            UpdateLabel();
            return(true);
        }

        case KeyCode.RightArrow:
        {
            ev.Use();
            mEditor.MoveRight();
            UpdateLabel();
            return(true);
        }

        case KeyCode.Home:
        case KeyCode.UpArrow:
        {
            ev.Use();
            mEditor.MoveTextStart();
            UpdateLabel();
            return(true);
        }

        case KeyCode.End:
        case KeyCode.DownArrow:
        {
            ev.Use();
            mEditor.MoveTextEnd();
            UpdateLabel();
            return(true);
        }

        // Copy
        case KeyCode.C:
        {
            if (ctrl)
            {
                ev.Use();
                NGUITools.clipboard = value;
            }
            return(true);
        }

        // Paste
        case KeyCode.V:
        {
            if (ctrl)
            {
                ev.Use();
                Append(NGUITools.clipboard);
            }
            return(true);
        }

        // Cut
        case KeyCode.X:
        {
            if (ctrl)
            {
                ev.Use();
                NGUITools.clipboard = value;
                value = "";
            }
            return(true);
        }

        // Submit
        case KeyCode.Return:
        case KeyCode.KeypadEnter:
        {
            ev.Use();

            if (ctrl && label != null && label.overflowMethod != UILabel.Overflow.ClampContent)
            {
                char c = '\n';
                if (onValidate != null)
                {
                    c = onValidate(mEditor.content.text, mEditor.selectPos, c);
                }
                else if (validation != Validation.None)
                {
                    c = Validate(mEditor.content.text, mEditor.selectPos, c);
                }

                // Append the character
                if (c != 0)
                {
                    mEditor.Insert(c);
                    UpdateLabel();
                    ExecuteOnChange();
                }
            }
            else
            {
                UICamera.currentKey = ev.keyCode;
                Submit();
                UICamera.currentKey = KeyCode.None;
                isSelected          = false;
                UpdateLabel();
                ExecuteOnChange();
            }
            return(true);
        }
        }
        return(false);
    }
Esempio n. 10
0
    private static bool PerformOperation(TextEditor te, UIUnityEvents.TextEditOp operation)
    {
        switch (operation)
        {
        case UIUnityEvents.TextEditOp.MoveLeft:
        {
            te.MoveLeft();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveRight:
        {
            te.MoveRight();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveUp:
        {
            te.MoveUp();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveDown:
        {
            te.MoveDown();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveLineStart:
        {
            te.MoveLineStart();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveLineEnd:
        {
            te.MoveLineEnd();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveTextStart:
        {
            te.MoveTextStart();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveTextEnd:
        {
            te.MoveTextEnd();
            break;
        }

        case UIUnityEvents.TextEditOp.MovePageUp:
        case UIUnityEvents.TextEditOp.MovePageDown:
        case UIUnityEvents.TextEditOp.SelectPageUp:
        case UIUnityEvents.TextEditOp.SelectPageDown:
        {
            Debug.Log(string.Concat("Unimplemented: ", operation));
            break;
        }

        case UIUnityEvents.TextEditOp.MoveGraphicalLineStart:
        {
            te.MoveGraphicalLineStart();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveGraphicalLineEnd:
        {
            te.MoveGraphicalLineEnd();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveWordLeft:
        {
            te.MoveWordLeft();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveWordRight:
        {
            te.MoveWordRight();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveParagraphForward:
        {
            te.MoveParagraphForward();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveParagraphBackward:
        {
            te.MoveParagraphBackward();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveToStartOfNextWord:
        {
            te.MoveToStartOfNextWord();
            break;
        }

        case UIUnityEvents.TextEditOp.MoveToEndOfPreviousWord:
        {
            te.MoveToEndOfPreviousWord();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectLeft:
        {
            te.SelectLeft();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectRight:
        {
            te.SelectRight();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectUp:
        {
            te.SelectUp();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectDown:
        {
            te.SelectDown();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectTextStart:
        {
            te.SelectTextStart();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectTextEnd:
        {
            te.SelectTextEnd();
            break;
        }

        case UIUnityEvents.TextEditOp.ExpandSelectGraphicalLineStart:
        {
            te.ExpandSelectGraphicalLineStart();
            break;
        }

        case UIUnityEvents.TextEditOp.ExpandSelectGraphicalLineEnd:
        {
            te.ExpandSelectGraphicalLineEnd();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectGraphicalLineStart:
        {
            te.SelectGraphicalLineStart();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectGraphicalLineEnd:
        {
            te.SelectGraphicalLineEnd();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectWordLeft:
        {
            te.SelectWordLeft();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectWordRight:
        {
            te.SelectWordRight();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectToEndOfPreviousWord:
        {
            te.SelectToEndOfPreviousWord();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectToStartOfNextWord:
        {
            te.SelectToStartOfNextWord();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectParagraphBackward:
        {
            te.SelectParagraphBackward();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectParagraphForward:
        {
            te.SelectParagraphForward();
            break;
        }

        case UIUnityEvents.TextEditOp.Delete:
        {
            return(te.Delete());
        }

        case UIUnityEvents.TextEditOp.Backspace:
        {
            return(te.Backspace());
        }

        case UIUnityEvents.TextEditOp.DeleteWordBack:
        {
            return(te.DeleteWordBack());
        }

        case UIUnityEvents.TextEditOp.DeleteWordForward:
        {
            return(te.DeleteWordForward());
        }

        case UIUnityEvents.TextEditOp.Cut:
        {
            return(te.Cut());
        }

        case UIUnityEvents.TextEditOp.Copy:
        {
            te.Copy();
            break;
        }

        case UIUnityEvents.TextEditOp.Paste:
        {
            return(te.Paste());
        }

        case UIUnityEvents.TextEditOp.SelectAll:
        {
            te.SelectAll();
            break;
        }

        case UIUnityEvents.TextEditOp.SelectNone:
        {
            te.SelectNone();
            break;
        }

        default:
        {
            goto case UIUnityEvents.TextEditOp.SelectPageDown;
        }
        }
        return(false);
    }