Пример #1
0
 public override void HandleKeyUp(UIKeyEventArgs e)
 {
     this.SetCaretVisible(true);
     if (_textSurfaceEventListener != null)
     {
         TextSurfaceEventListener.NotifyKeyDown(_textSurfaceEventListener, e);;
     }
 }
Пример #2
0
        public override void HandleKeyPress(UIKeyEventArgs e)
        {
            this.SetCaretVisible(true);
            //------------------------
            if (e.IsControlCharacter)
            {
                HandleKeyDown(e);
                return;
            }



            e.CancelBubbling = true;

            InvalidateGraphicOfCurrentSelectionArea();

            bool preventDefault = false;

            if (_textSurfaceEventListener != null &&
                !(preventDefault = TextSurfaceEventListener.NotifyPreviewKeyPress(_textSurfaceEventListener, e)))
            {
                _editSession.UpdateSelectionRange();
            }
            if (preventDefault)
            {
                return;
            }

            if (_isEditable)
            {
                int insertAt = _editSession.CurrentLineCharIndex;

                _editSession.AddCharToCurrentLine(e.KeyChar);

                if (_textSurfaceEventListener != null)
                {
                    //TODO: review this again ***
                    if (_editSession.SelectionRange != null)
                    {
                        TextSurfaceEventListener.NotifyCharacterReplaced(_textSurfaceEventListener, e.KeyChar);
                    }
                    else
                    {
                        TextSurfaceEventListener.NotifyCharacterAdded(_textSurfaceEventListener, insertAt, e.KeyChar);
                    }
                }
            }


            EnsureCaretVisible();

            if (_textSurfaceEventListener != null)
            {
                TextSurfaceEventListener.NotifyKeyDown(_textSurfaceEventListener, e);;
            }
        }
Пример #3
0
        public override void HandleKeyDown(UIKeyEventArgs e)
        {
            this.SetCaretVisible(true);
            if (!e.HasKeyData)
            {
                return;
            }

            switch (e.KeyCode)
            {
            case UIKeys.Home:
            {
                this.DoHome(e.Shift);
            }
            break;

            case UIKeys.End:
            {
                this.DoEnd(e.Shift);
            }
            break;

            case UIKeys.Back:
            {
                if (_isEditable)
                {
                    if (_editSession.SelectionRange != null)
                    {
                        InvalidateGraphicOfCurrentSelectionArea();
                    }
                    else
                    {
                        InvalidateGraphicOfCurrentLineArea();
                    }
                    if (_textSurfaceEventListener == null)
                    {
                        _editSession.DoBackspace();
                    }
                    else
                    {
                        if (!TextSurfaceEventListener.NotifyPreviewBackSpace(_textSurfaceEventListener, e) &&
                            _editSession.DoBackspace())
                        {
                            TextSurfaceEventListener.NotifyCharactersRemoved(_textSurfaceEventListener,
                                                                             new TextDomEventArgs(_editSession._updateJustCurrentLine));
                        }
                    }
                    EnsureCaretVisible();
                }
            }
            break;

            case UIKeys.Delete:
            {
                if (_isEditable)
                {
                    if (_editSession.SelectionRange != null)
                    {
                        InvalidateGraphicOfCurrentSelectionArea();
                    }
                    else
                    {
                        InvalidateGraphicOfCurrentLineArea();
                    }
                    if (_textSurfaceEventListener == null)
                    {
                        _editSession.DoDelete();
                    }
                    else
                    {
                        VisualSelectionRangeSnapShot delpart = _editSession.DoDelete();
                        TextSurfaceEventListener.NotifyCharactersRemoved(_textSurfaceEventListener,
                                                                         new TextDomEventArgs(_editSession._updateJustCurrentLine, delpart));
                    }

                    EnsureCaretVisible();
                }
            }
            break;

            default:
            {
                if (_textSurfaceEventListener != null)
                {
                    UIKeys keycode = e.KeyCode;
                    if (keycode >= UIKeys.F1 && keycode <= UIKeys.F12)
                    {
                        InvalidateGraphicOfCurrentSelectionArea();
                        TextSurfaceEventListener.NotifyFunctionKeyDown(_textSurfaceEventListener, keycode);
                        EnsureCaretVisible();
                    }
                }
            }
            break;
            }

            if (e.HasKeyData && e.Ctrl)
            {
                switch (e.KeyCode)
                {
                case UIKeys.A:
                {
                    //select all
                    //....
                    this.CurrentLineNumber = 0;
                    //start select to end
                    DoHome(false);       //1st simulate
                    DoHome(true);        //2nd
                    this.CurrentLineNumber = this.LineCount - 1;
                    DoEnd(true);         //
                }
                break;

                case UIKeys.C:
                {
                    using (StringBuilderPool <TempTextLineCopyContext> .GetFreeStringBuilder(out StringBuilder stBuilder))
                    {
                        _editSession.CopySelectedTextToPlainText(stBuilder);
                        if (stBuilder != null)
                        {
                            if (stBuilder.Length == 0)
                            {
                                Clipboard.Clear();
                            }
                            else
                            {
                                Clipboard.SetText(stBuilder.ToString());
                            }
                        }
                    }
                }
                break;

                case UIKeys.V:
                {
                    if (_isEditable && Clipboard.ContainsUnicodeText())
                    {
                        //1. we need to parse multi-line to single line
                        //this may need text-break services

                        _editSession.AddTextToCurrentLine(PlainTextDocumentHelper.CreatePlainTextDocument(Clipboard.GetUnicodeText()));

                        EnsureCaretVisible();
                    }
                }
                break;

                case UIKeys.X:
                {
                    if (_isEditable && _editSession.SelectionRange != null)
                    {
                        InvalidateGraphicOfCurrentSelectionArea();

                        using (StringBuilderPool <TempTextLineCopyContext> .GetFreeStringBuilder(out StringBuilder stBuilder))
                        {
                            _editSession.CopySelectedTextToPlainText(stBuilder);
                            if (stBuilder != null)
                            {
                                Clipboard.SetText(stBuilder.ToString());
                            }
                            _editSession.DoDelete();
                            EnsureCaretVisible();
                        }
                    }
                }
                break;

                case UIKeys.Z:
                {
                    if (_isEditable)
                    {
                        _editSession.UndoLastAction();
                        EnsureCaretVisible();
                    }
                }
                break;

                case UIKeys.Y:
                {
                    if (_isEditable)
                    {
                        _editSession.ReverseLastUndoAction();
                        EnsureCaretVisible();
                    }
                }
                break;
                }
            }

            if (_textSurfaceEventListener != null)
            {
                TextSurfaceEventListener.NotifyKeyDown(_textSurfaceEventListener, e);
            }
        }