PreventDefault() public method

public PreventDefault ( ) : void
return void
 static public int PreventDefault(IntPtr l)
 {
     try {
         FairyGUI.EventContext self = (FairyGUI.EventContext)checkSelf(l);
         self.PreventDefault();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int PreventDefault(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         FairyGUI.EventContext obj = (FairyGUI.EventContext)ToLua.CheckObject <FairyGUI.EventContext>(L, 1);
         obj.PreventDefault();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 3
0
        void __keydown(EventContext context)
        {
            if (!_editing || context.isDefaultPrevented)
            {
                return;
            }

            InputEvent evt = context.inputEvent;

            switch (evt.keyCode)
            {
            case KeyCode.Backspace:
            {
                context.PreventDefault();
                if (_selectionStart == _caretPosition && _caretPosition > 0)
                {
                    _selectionStart = _caretPosition - 1;
                }
                ReplaceSelection(null);
                break;
            }

            case KeyCode.Delete:
            {
                context.PreventDefault();
                if (_selectionStart == _caretPosition && _caretPosition < textField.charPositions.Count - 1)
                {
                    _selectionStart = _caretPosition + 1;
                }
                ReplaceSelection(null);
                break;
            }

            case KeyCode.LeftArrow:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }
                if (_caretPosition > 0)
                {
                    TextField.CharPosition cp = GetCharPosition(_caretPosition - 1);
                    AdjustCaret(cp, !evt.shift);
                }
                break;
            }

            case KeyCode.RightArrow:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }
                if (_caretPosition < textField.charPositions.Count - 1)
                {
                    TextField.CharPosition cp = GetCharPosition(_caretPosition + 1);
                    AdjustCaret(cp, !evt.shift);
                }
                break;
            }

            case KeyCode.UpArrow:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

                TextField.CharPosition cp = GetCharPosition(_caretPosition);
                if (cp.lineIndex == 0)
                {
                    return;
                }

                TextField.LineInfo line = textField.lines[cp.lineIndex - 1];
                cp = GetCharPosition(new Vector2(_caret.x, line.y + textField.y));
                AdjustCaret(cp, !evt.shift);
                break;
            }

            case KeyCode.DownArrow:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

                TextField.CharPosition cp = GetCharPosition(_caretPosition);
                if (cp.lineIndex == textField.lines.Count - 1)
                {
                    cp.charIndex = textField.charPositions.Count - 1;
                }
                else
                {
                    TextField.LineInfo line = textField.lines[cp.lineIndex + 1];
                    cp = GetCharPosition(new Vector2(_caret.x, line.y + textField.y));
                }
                AdjustCaret(cp, !evt.shift);
                break;
            }

            case KeyCode.PageUp:
            {
                context.PreventDefault();
                ClearSelection();

                break;
            }

            case KeyCode.PageDown:
            {
                context.PreventDefault();
                ClearSelection();

                break;
            }

            case KeyCode.Home:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

                TextField.CharPosition cp   = GetCharPosition(_caretPosition);
                TextField.LineInfo     line = textField.lines[cp.lineIndex];
                cp = GetCharPosition(new Vector2(int.MinValue, line.y + textField.y));
                AdjustCaret(cp, !evt.shift);
                break;
            }

            case KeyCode.End:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

                TextField.CharPosition cp   = GetCharPosition(_caretPosition);
                TextField.LineInfo     line = textField.lines[cp.lineIndex];
                cp = GetCharPosition(new Vector2(int.MaxValue, line.y + textField.y));
                AdjustCaret(cp, !evt.shift);

                break;
            }

            //Select All
            case KeyCode.A:
            {
                if (evt.ctrl)
                {
                    context.PreventDefault();
                    _selectionStart = 0;
                    AdjustCaret(GetCharPosition(int.MaxValue));
                }
                break;
            }

            //Copy
            case KeyCode.C:
            {
                if (evt.ctrl && !_displayAsPassword)
                {
                    context.PreventDefault();
                    string s = GetSelection();
                    if (!string.IsNullOrEmpty(s))
                    {
                        DoCopy(s);
                    }
                }
                break;
            }

            //Paste
            case KeyCode.V:
            {
                if (evt.ctrl)
                {
                    context.PreventDefault();
                    DoPaste();
                }
                break;
            }

            //Cut
            case KeyCode.X:
            {
                if (evt.ctrl && !_displayAsPassword)
                {
                    context.PreventDefault();
                    string s = GetSelection();
                    if (!string.IsNullOrEmpty(s))
                    {
                        DoCopy(s);
                        ReplaceSelection(null);
                    }
                }
                break;
            }

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
            {
                if (textField.singleLine)
                {
                    onSubmit.Call();
                    return;
                }
                break;
            }
            }

            char c = evt.character;

            if (c != 0)
            {
                if (evt.ctrl)
                {
                    return;
                }

                if (c == '\r' || (int)c == 3)
                {
                    c = '\n';
                }

                if (c == 127 || textField.singleLine && c == '\n')
                {
                    return;
                }

                if (char.IsHighSurrogate(c))
                {
                    _highSurrogateChar = c;
                    return;
                }

                if (char.IsLowSurrogate(c))
                {
                    ReplaceSelection(char.ConvertFromUtf32(((int)c & 0x03FF) + ((((int)_highSurrogateChar & 0x03FF) + 0x40) << 10)));
                }
                else
                {
                    ReplaceSelection(c.ToString());
                }
            }
            else
            {
                if (Input.compositionString.Length > 0)
                {
                    UpdateText();
                }
            }
        }
Exemplo n.º 4
0
        private void __dragStart(EventContext context)
        {
            context.PreventDefault();

            this.StartDrag((int)context.data);
        }
Exemplo n.º 5
0
		void __keydown(EventContext context)
		{
			if (_caret == null || context.isDefaultPrevented)
				return;

			InputEvent evt = context.inputEvent;

			switch (evt.keyCode)
			{
				case KeyCode.Backspace:
					{
						context.PreventDefault();
						if (_selectionStart != null)
						{
							DeleteSelection();
							OnChanged();
						}
						else if (_caretPosition > 0)
						{
							int tmp = _caretPosition; //this.text 会修改_caretPosition
							_caretPosition--;
							this.text = _text.Substring(0, tmp - 1) + _text.Substring(tmp);
							OnChanged();
						}

						break;
					}

				case KeyCode.Delete:
					{
						context.PreventDefault();
						if (_selectionStart != null)
						{
							DeleteSelection();
							OnChanged();
						}
						else if (_caretPosition < _text.Length)
						{
							this.text = _text.Substring(0, _caretPosition) + _text.Substring(_caretPosition + 1);
							OnChanged();
						}

						break;
					}

				case KeyCode.LeftArrow:
					{
						context.PreventDefault();
						if (evt.shift)
						{
							if (_selectionStart == null)
								_selectionStart = GetCharPosition(_caretPosition);
						}
						else
							ClearSelection();
						if (_caretPosition > 0)
						{
							CharPosition cp = GetCharPosition(_caretPosition - 1);

							AdjustCaret(cp);
						}
						break;
					}

				case KeyCode.RightArrow:
					{
						context.PreventDefault();
						if (evt.shift)
						{
							if (_selectionStart == null)
								_selectionStart = GetCharPosition(_caretPosition);
						}
						else
							ClearSelection();
						if (_caretPosition < _text.Length)
						{
							CharPosition cp = GetCharPosition(_caretPosition + 1);
							AdjustCaret(cp);
						}
						break;
					}

				case KeyCode.UpArrow:
					{
						context.PreventDefault();
						if (evt.shift)
						{
							if (_selectionStart == null)
								_selectionStart = GetCharPosition(_caretPosition);
						}
						else
							ClearSelection();

						CharPosition cp = GetCharPosition(_caretPosition);
						if (cp.lineIndex == 0)
							return;

						LineInfo line = _lines[cp.lineIndex - 1];
						cp = GetCharPosition(new Vector3(_caret.cachedTransform.localPosition.x + _GetPositionOffset().x, line.y, 0));
						AdjustCaret(cp);
						break;
					}


				case KeyCode.DownArrow:
					{
						context.PreventDefault();
						if (evt.shift)
						{
							if (_selectionStart == null)
								_selectionStart = GetCharPosition(_caretPosition);
						}
						else
							ClearSelection();

						CharPosition cp = GetCharPosition(_caretPosition);
						if (cp.lineIndex == _lines.Count - 1)
							return;

						LineInfo line = _lines[cp.lineIndex + 1];
						cp = GetCharPosition(new Vector3(_caret.cachedTransform.localPosition.x + _GetPositionOffset().x, line.y, 0));
						AdjustCaret(cp);
						break;
					}

				case KeyCode.PageUp:
					{
						context.PreventDefault();
						ClearSelection();

						break;
					}

				case KeyCode.PageDown:
					{
						context.PreventDefault();
						ClearSelection();

						break;
					}

				case KeyCode.Home:
					{
						context.PreventDefault();
						ClearSelection();

						CharPosition cp = GetCharPosition(_caretPosition);
						LineInfo line = _lines[cp.lineIndex];
						cp = GetCharPosition(new Vector3(int.MinValue, line.y, 0));
						AdjustCaret(cp);
						break;
					}

				case KeyCode.End:
					{
						context.PreventDefault();
						ClearSelection();

						CharPosition cp = GetCharPosition(_caretPosition);
						LineInfo line = _lines[cp.lineIndex];
						cp = GetCharPosition(new Vector3(int.MaxValue, line.y, 0));
						AdjustCaret(cp);

						break;
					}

				//Select All
				case KeyCode.A:
					{
						if (evt.ctrl)
						{
							context.PreventDefault();
							_selectionStart = GetCharPosition(0);
							AdjustCaret(GetCharPosition(_text.Length));
						}
						break;
					}

				// Copy
				case KeyCode.C:
					{
						if (evt.ctrl && !_displayAsPassword)
						{
							context.PreventDefault();
							string s = GetSelection();
							if (!string.IsNullOrEmpty(s))
								Stage.inst.onCopy.Call(s);
						}
						break;
					}

				// Paste
				case KeyCode.V:
					{
						if (evt.ctrl)
						{
							context.PreventDefault();
							Stage.inst.onPaste.Call(this);
						}
						break;
					}

				// Cut
				case KeyCode.X:
					{
						if (evt.ctrl && !_displayAsPassword)
						{
							context.PreventDefault();
							string s = GetSelection();
							if (!string.IsNullOrEmpty(s))
							{
								Stage.inst.onCopy.Call(s);
								DeleteSelection();
								OnChanged();
							}
						}
						break;
					}

				case KeyCode.Return:
				case KeyCode.KeypadEnter:
					{
						if (!evt.ctrl && !evt.shift)
						{
							context.PreventDefault();

							if (!_singleLine)
							{
								InsertText("\n");
								OnChanged();
							}
						}
						break;
					}
			}
		}
Exemplo n.º 6
0
        private void __dragStart(EventContext context)
        {
            context.PreventDefault();

            this.StartDrag((int)context.data);
        }
Exemplo n.º 7
0
        private void __dragStart(EventContext context)
        {
            context.PreventDefault();

            this.StartDrag(null);
        }
Exemplo n.º 8
0
        void __keydown(EventContext context)
        {
            if (!_editing || context.isDefaultPrevented)
            {
                return;
            }

            InputEvent evt = context.inputEvent;

            switch (evt.keyCode)
            {
            case Keys.Back:
            {
                if (textField.text.Length > 0)
                {
                    IMEAdapter.compositionString = textField.text.Remove(textField.text.Length - 1, 1);
                }

                context.PreventDefault();
                if (_selectionStart == _caretPosition && _caretPosition > 0)
                {
                    _selectionStart = _caretPosition - 1;
                }

                ReplaceSelection(null);
                break;
            }

            case Keys.Delete:
            {
                context.PreventDefault();
                if (_selectionStart == _caretPosition && _caretPosition < textField.charPositions.Count - 1)
                {
                    _selectionStart = _caretPosition + 1;
                }
                ReplaceSelection(null);
                break;
            }

            case Keys.Left:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }
                if (_caretPosition > 0)
                {
                    TextField.CharPosition cp = GetCharPosition(_caretPosition - 1);
                    AdjustCaret(cp, !evt.shift);
                }
                break;
            }

            case Keys.Right:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }
                if (_caretPosition < textField.charPositions.Count - 1)
                {
                    TextField.CharPosition cp = GetCharPosition(_caretPosition + 1);
                    AdjustCaret(cp, !evt.shift);
                }
                break;
            }

            case Keys.Up:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

                TextField.CharPosition cp = GetCharPosition(_caretPosition);
                if (cp.lineIndex == 0)
                {
                    return;
                }

                TextField.LineInfo line = textField.lines[cp.lineIndex - 1];
                cp = GetCharPosition(new Vector2(_caret.x, line.y + textField.y));
                AdjustCaret(cp, !evt.shift);
                break;
            }

            case Keys.Down:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

                TextField.CharPosition cp = GetCharPosition(_caretPosition);
                if (cp.lineIndex == textField.lines.Count - 1)
                {
                    cp.charIndex = textField.charPositions.Count - 1;
                }
                else
                {
                    TextField.LineInfo line = textField.lines[cp.lineIndex + 1];
                    cp = GetCharPosition(new Vector2(_caret.x, line.y + textField.y));
                }
                AdjustCaret(cp, !evt.shift);
                break;
            }

            case Keys.PageUp:
            {
                context.PreventDefault();
                ClearSelection();

                break;
            }

            case Keys.PageDown:
            {
                context.PreventDefault();
                ClearSelection();

                break;
            }

            case Keys.Home:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

                TextField.CharPosition cp   = GetCharPosition(_caretPosition);
                TextField.LineInfo     line = textField.lines[cp.lineIndex];
                cp = GetCharPosition(new Vector2(int.MinValue, line.y + textField.y));
                AdjustCaret(cp, !evt.shift);
                break;
            }

            case Keys.End:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

                TextField.CharPosition cp   = GetCharPosition(_caretPosition);
                TextField.LineInfo     line = textField.lines[cp.lineIndex];
                cp = GetCharPosition(new Vector2(int.MaxValue, line.y + textField.y));
                AdjustCaret(cp, !evt.shift);

                break;
            }

            //Select All
            case Keys.A:
            {
                if (evt.ctrl)
                {
                    context.PreventDefault();
                    _selectionStart = 0;
                    AdjustCaret(GetCharPosition(int.MaxValue));
                }
                break;
            }

            //Copy
            case Keys.C:
            {
                if (evt.ctrl && !_displayAsPassword)
                {
                    context.PreventDefault();
                    string s = GetSelection();
                    if (!string.IsNullOrEmpty(s))
                    {
                        DoCopy(s);
                    }
                }
                break;
            }

            //Paste
            case Keys.V:
            {
                if (evt.ctrl)
                {
                    context.PreventDefault();
                    DoPaste();
                }
                break;
            }

            //Cut
            case Keys.X:
            {
                if (evt.ctrl && !_displayAsPassword)
                {
                    context.PreventDefault();
                    string s = GetSelection();
                    if (!string.IsNullOrEmpty(s))
                    {
                        DoCopy(s);
                        ReplaceSelection(null);
                    }
                }
                break;
            }

            case Keys.Enter:
            {
                if (textField.singleLine)
                {
                    DispatchEvent("onSubmit", null);
                    return;
                }
                break;
            }
            }

            if (evt.ctrl)
            {
                return;
            }

            string str = evt.KeyName;

            if (!string.IsNullOrEmpty(str) && IMEAdapter.compositionMode == IMEAdapter.CompositionMode.Off)
            {
                if (textField.singleLine && str == "\n")
                {
                    return;
                }

                ReplaceSelection(str);
            }
            else
            {
                if (IMEAdapter.compositionString.Length > 0)
                {
                    UpdateText();
                }
            }
        }
Exemplo n.º 9
0
        void __keydown(EventContext context)
        {
            if (!_editing || context.isDefaultPrevented)
            {
                return;
            }

            InputEvent evt = context.inputEvent;

            switch (evt.keyCode)
            {
            case KeyCode.Backspace:
            {
                context.PreventDefault();
                if (_selectionStart != null)
                {
                    ReplaceSelection(null);
                }
                else if (_caretPosition > 0)
                {
                    int tmp = _caretPosition;
                    _caretPosition--;
                    ReplaceText(textField.text.Substring(0, tmp - 1) + textField.text.Substring(tmp));
                }

                break;
            }

            case KeyCode.Delete:
            {
                context.PreventDefault();
                if (_selectionStart != null)
                {
                    ReplaceSelection(null);
                }
                else if (_caretPosition < textField.text.Length)
                {
                    ReplaceText(textField.text.Substring(0, _caretPosition) + textField.text.Substring(_caretPosition + 1));
                }

                break;
            }

            case KeyCode.LeftArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }
                if (_caretPosition > 0)
                {
                    CharPosition cp = GetCharPosition(_caretPosition - 1);
                    AdjustCaret(cp);
                }
                break;
            }

            case KeyCode.RightArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }
                if (_caretPosition < textField.text.Length)
                {
                    CharPosition cp = GetCharPosition(_caretPosition + 1);
                    AdjustCaret(cp);
                }
                break;
            }

            case KeyCode.UpArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }

                CharPosition cp = GetCharPosition(_caretPosition);
                if (cp.lineIndex == 0)
                {
                    return;
                }

                TextField.LineInfo line = textField.lines[cp.lineIndex - 1];
                cp = GetCharPosition(new Vector2(_caret.x, line.y + textField.y));
                AdjustCaret(cp);
                break;
            }

            case KeyCode.DownArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }

                CharPosition cp = GetCharPosition(_caretPosition);
                if (cp.lineIndex == textField.lines.Count - 1)
                {
                    cp.charIndex = textField.charPositions.Count - 1;
                }
                else
                {
                    TextField.LineInfo line = textField.lines[cp.lineIndex + 1];
                    cp = GetCharPosition(new Vector2(_caret.x, line.y + textField.y));
                }
                AdjustCaret(cp);
                break;
            }

            case KeyCode.PageUp:
            {
                context.PreventDefault();
                ClearSelection();

                break;
            }

            case KeyCode.PageDown:
            {
                context.PreventDefault();
                ClearSelection();

                break;
            }

            case KeyCode.Home:
            {
                context.PreventDefault();
                ClearSelection();

                CharPosition       cp   = GetCharPosition(_caretPosition);
                TextField.LineInfo line = textField.lines[cp.lineIndex];
                cp = GetCharPosition(new Vector2(int.MinValue, line.y + textField.y));
                AdjustCaret(cp);
                break;
            }

            case KeyCode.End:
            {
                context.PreventDefault();
                ClearSelection();

                CharPosition       cp   = GetCharPosition(_caretPosition);
                TextField.LineInfo line = textField.lines[cp.lineIndex];
                cp = GetCharPosition(new Vector2(int.MaxValue, line.y + textField.y));
                AdjustCaret(cp);

                break;
            }

            //Select All
            case KeyCode.A:
            {
                if (evt.ctrl)
                {
                    context.PreventDefault();
                    _selectionStart = GetCharPosition(0);
                    AdjustCaret(GetCharPosition(textField.text.Length));
                }
                break;
            }

            //Copy
            case KeyCode.C:
            {
                if (evt.ctrl && !_displayAsPassword)
                {
                    context.PreventDefault();
                    string s = GetSelection();
                    if (!string.IsNullOrEmpty(s))
                    {
                        DoCopy(s);
                    }
                }
                break;
            }

            //Paste
            case KeyCode.V:
            {
                if (evt.ctrl)
                {
                    context.PreventDefault();
                    DoPaste();
                }
                break;
            }

            //Cut
            case KeyCode.X:
            {
                if (evt.ctrl && !_displayAsPassword)
                {
                    context.PreventDefault();
                    string s = GetSelection();
                    if (!string.IsNullOrEmpty(s))
                    {
                        DoCopy(s);
                        ReplaceSelection(null);
                    }
                }
                break;
            }

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
            {
                if (!evt.ctrl && !evt.shift)
                {
                    context.PreventDefault();

                    if (!textField.singleLine)
                    {
                        ReplaceSelection("\n");
                    }
                }
                break;
            }
            }
        }
Exemplo n.º 10
0
        private void __dragStart(EventContext context)
        {
            context.PreventDefault();

            this.StartDrag(null);
        }
Exemplo n.º 11
0
        void __keydown(EventContext context)
        {
            if (!_editing || context.isDefaultPrevented)
                return;

            InputEvent evt = context.inputEvent;

            switch (evt.keyCode)
            {
                case KeyCode.Backspace:
                    {
                        context.PreventDefault();
                        if (_selectionStart != null)
                            ReplaceSelection(null);
                        else if (_caretPosition > 0)
                        {
                            int tmp = _caretPosition;
                            _caretPosition--;
                            ReplaceText(textField.text.Substring(0, tmp - 1) + textField.text.Substring(tmp));
                        }

                        break;
                    }

                case KeyCode.Delete:
                    {
                        context.PreventDefault();
                        if (_selectionStart != null)
                            ReplaceSelection(null);
                        else if (_caretPosition < textField.text.Length)
                            ReplaceText(textField.text.Substring(0, _caretPosition) + textField.text.Substring(_caretPosition + 1));

                        break;
                    }

                case KeyCode.LeftArrow:
                    {
                        context.PreventDefault();
                        if (evt.shift)
                        {
                            if (_selectionStart == null)
                                _selectionStart = GetCharPosition(_caretPosition);
                        }
                        else
                            ClearSelection();
                        if (_caretPosition > 0)
                        {
                            TextField.CharPosition cp = GetCharPosition(_caretPosition - 1);
                            AdjustCaret(cp);
                        }
                        break;
                    }

                case KeyCode.RightArrow:
                    {
                        context.PreventDefault();
                        if (evt.shift)
                        {
                            if (_selectionStart == null)
                                _selectionStart = GetCharPosition(_caretPosition);
                        }
                        else
                            ClearSelection();
                        if (_caretPosition < textField.text.Length)
                        {
                            TextField.CharPosition cp = GetCharPosition(_caretPosition + 1);
                            AdjustCaret(cp);
                        }
                        break;
                    }

                case KeyCode.UpArrow:
                    {
                        context.PreventDefault();
                        if (evt.shift)
                        {
                            if (_selectionStart == null)
                                _selectionStart = GetCharPosition(_caretPosition);
                        }
                        else
                            ClearSelection();

                        TextField.CharPosition cp = GetCharPosition(_caretPosition);
                        if (cp.lineIndex == 0)
                            return;

                        TextField.LineInfo line = textField.lines[cp.lineIndex - 1];
                        cp = GetCharPosition(new Vector2(_caret.x, line.y + textField.y));
                        AdjustCaret(cp);
                        break;
                    }

                case KeyCode.DownArrow:
                    {
                        context.PreventDefault();
                        if (evt.shift)
                        {
                            if (_selectionStart == null)
                                _selectionStart = GetCharPosition(_caretPosition);
                        }
                        else
                            ClearSelection();

                        TextField.CharPosition cp = GetCharPosition(_caretPosition);
                        if (cp.lineIndex == textField.lines.Count - 1)
                            cp.caretIndex = textField.charPositions.Count - 1;
                        else
                        {
                            TextField.LineInfo line = textField.lines[cp.lineIndex + 1];
                            cp = GetCharPosition(new Vector2(_caret.x, line.y + textField.y));
                        }
                        AdjustCaret(cp);
                        break;
                    }

                case KeyCode.PageUp:
                    {
                        context.PreventDefault();
                        ClearSelection();

                        break;
                    }

                case KeyCode.PageDown:
                    {
                        context.PreventDefault();
                        ClearSelection();

                        break;
                    }

                case KeyCode.Home:
                    {
                        context.PreventDefault();
                        ClearSelection();

                        TextField.CharPosition cp = GetCharPosition(_caretPosition);
                        TextField.LineInfo line = textField.lines[cp.lineIndex];
                        cp = GetCharPosition(new Vector2(int.MinValue, line.y + textField.y));
                        AdjustCaret(cp);
                        break;
                    }

                case KeyCode.End:
                    {
                        context.PreventDefault();
                        ClearSelection();

                        TextField.CharPosition cp = GetCharPosition(_caretPosition);
                        TextField.LineInfo line = textField.lines[cp.lineIndex];
                        cp = GetCharPosition(new Vector2(int.MaxValue, line.y + textField.y));
                        AdjustCaret(cp);

                        break;
                    }

                //Select All
                case KeyCode.A:
                    {
                        if (evt.ctrl)
                        {
                            context.PreventDefault();
                            _selectionStart = GetCharPosition(0);
                            AdjustCaret(GetCharPosition(textField.text.Length));
                        }
                        break;
                    }

                //Copy
                case KeyCode.C:
                    {
                        if (evt.ctrl && !_displayAsPassword)
                        {
                            context.PreventDefault();
                            string s = GetSelection();
                            if (!string.IsNullOrEmpty(s))
                                DoCopy(s);
                        }
                        break;
                    }

                //Paste
                case KeyCode.V:
                    {
                        if (evt.ctrl)
                        {
                            context.PreventDefault();
                            DoPaste();
                        }
                        break;
                    }

                //Cut
                case KeyCode.X:
                    {
                        if (evt.ctrl && !_displayAsPassword)
                        {
                            context.PreventDefault();
                            string s = GetSelection();
                            if (!string.IsNullOrEmpty(s))
                            {
                                DoCopy(s);
                                ReplaceSelection(null);
                            }
                        }
                        break;
                    }

                case KeyCode.Return:
                case KeyCode.KeypadEnter:
                    {
                        if (!evt.ctrl && !evt.shift)
                        {
                            context.PreventDefault();

                            if (!textField.singleLine)
                                ReplaceSelection("\n");
                        }
                        break;
                    }
            }
        }