Exemple #1
0
        VisualSelectionRangeSnapShot RemoveSelectedText()
        {
#if DEBUG
            if (dbugEnableTextManRecorder)
            {
                _dbugActivityRecorder.WriteInfo("TxLMan::RemoveSelectedText");
                _dbugActivityRecorder.BeginContext();
            }
#endif

            if (selectionRange == null)
            {
#if DEBUG
                if (dbugEnableTextManRecorder)
                {
                    _dbugActivityRecorder.WriteInfo("NO_SEL_RANGE");
                    _dbugActivityRecorder.EndContext();
                }
#endif
                return(VisualSelectionRangeSnapShot.Empty);
            }
            else if (!selectionRange.IsValid)
            {
#if DEBUG
                if (dbugEnableTextManRecorder)
                {
                    _dbugActivityRecorder.WriteInfo("!RANGE_ON_SAME_POINT");
                }
#endif
                CancelSelect();
#if DEBUG
                if (dbugEnableTextManRecorder)
                {
                    _dbugActivityRecorder.EndContext();
                }
#endif
                return(VisualSelectionRangeSnapShot.Empty);
            }
            selectionRange.SwapIfUnOrder();
            VisualSelectionRangeSnapShot selSnapshot = selectionRange.GetSelectionRangeSnapshot();
            VisualPointInfo startPoint = selectionRange.StartPoint;
            CurrentLineNumber = startPoint.LineId;
            int preCutIndex = startPoint.LineCharIndex;
            textLineWriter.SetCurrentCharIndex(startPoint.LineCharIndex);
            if (selectionRange.IsOnTheSameLine)
            {
                List <EditableRun> tobeDeleteTextRuns = new List <EditableRun>();
                textLineWriter.CopySelectedTextRuns(selectionRange, tobeDeleteTextRuns);
                if (tobeDeleteTextRuns != null && tobeDeleteTextRuns.Count > 0)
                {
                    commandHistory.AddDocAction(
                        new DocActionDeleteRange(tobeDeleteTextRuns,
                                                 selSnapshot.startLineNum,
                                                 selSnapshot.startColumnNum,
                                                 selSnapshot.endLineNum,
                                                 selSnapshot.endColumnNum));
                    textLineWriter.RemoveSelectedTextRuns(selectionRange);
                    updateJustCurrentLine = true;
                }
            }
            else
            {
                int startPointLindId    = startPoint.LineId;
                int startPointCharIndex = startPoint.LineCharIndex;
                List <EditableRun> tobeDeleteTextRuns = new List <EditableRun>();
                textLineWriter.CopySelectedTextRuns(selectionRange, tobeDeleteTextRuns);
                if (tobeDeleteTextRuns != null && tobeDeleteTextRuns.Count > 0)
                {
                    commandHistory.AddDocAction(
                        new DocActionDeleteRange(tobeDeleteTextRuns,
                                                 selSnapshot.startLineNum,
                                                 selSnapshot.startColumnNum,
                                                 selSnapshot.endLineNum,
                                                 selSnapshot.endColumnNum));
                    textLineWriter.RemoveSelectedTextRuns(selectionRange);
                    updateJustCurrentLine = false;
                    textLineWriter.MoveToLine(startPointLindId);
                    textLineWriter.SetCurrentCharIndex(startPointCharIndex);
                }
            }
            CancelSelect();
            TextEditRenderBox.NotifyTextContentSizeChanged(visualTextSurface);
#if DEBUG
            if (dbugEnableTextManRecorder)
            {
                _dbugActivityRecorder.EndContext();
            }
#endif
            return(selSnapshot);
        }
        public void OnKeyDown(UIKeyEventArgs e)
        {
            this.SetCaretState(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 (internalTextLayerController.SelectionRange != null)
                {
                    InvalidateGraphicLocalArea(this, GetSelectionUpdateArea());
                }
                else
                {
                    InvalidateGraphicOfCurrentLineArea();
                }
                if (textSurfaceEventListener == null)
                {
                    internalTextLayerController.DoBackspace();
                }
                else
                {
                    if (!TextSurfaceEventListener.NotifyPreviewBackSpace(textSurfaceEventListener) &&
                        internalTextLayerController.DoBackspace())
                    {
                        TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener,
                                                                         new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine));
                    }
                }

                EnsureCaretVisible();
            } break;

            case UIKeys.Delete:
            {
                if (internalTextLayerController.SelectionRange != null)
                {
                    InvalidateGraphicLocalArea(this, GetSelectionUpdateArea());
                }
                else
                {
                    InvalidateGraphicOfCurrentLineArea();
                }
                if (textSurfaceEventListener == null)
                {
                    internalTextLayerController.DoDelete();
                }
                else
                {
                    VisualSelectionRangeSnapShot delpart = internalTextLayerController.DoDelete();
                    TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener,
                                                                     new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine));
                }

                EnsureCaretVisible();
            } break;

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

            if (e.HasKeyData && e.Ctrl)
            {
                switch (e.KeyCode)
                {
                case UIKeys.C:
                {
                    StringBuilder stBuilder = GetFreeStringBuilder();
                    internalTextLayerController.CopySelectedTextToPlainText(stBuilder);
                    if (stBuilder != null)
                    {
                        if (stBuilder.Length == 0)
                        {
                            Clipboard.Clear();
                        }
                        else
                        {
                            Clipboard.SetText(stBuilder.ToString());
                        }
                    }
                    ReleaseStringBuilder(stBuilder);
                } break;

                case UIKeys.V:
                {
                    if (Clipboard.ContainUnicodeText())
                    {
                        internalTextLayerController.AddTextRunsToCurrentLine(
                            new EditableRun[] {
                                new EditableTextRun(this.Root,
                                                    Clipboard.GetUnicodeText(), this.CurrentTextSpanStyle)
                            });
                        EnsureCaretVisible();
                    }
                } break;

                case UIKeys.X:
                {
                    if (internalTextLayerController.SelectionRange != null)
                    {
                        if (internalTextLayerController.SelectionRange != null)
                        {
                            InvalidateGraphicLocalArea(this, GetSelectionUpdateArea());
                        }
                        StringBuilder stBuilder = GetFreeStringBuilder();
                        internalTextLayerController.CopySelectedTextToPlainText(stBuilder);
                        if (stBuilder != null)
                        {
                            Clipboard.SetText(stBuilder.ToString());
                        }

                        internalTextLayerController.DoDelete();


                        EnsureCaretVisible();
                        ReleaseStringBuilder(stBuilder);
                    }
                } break;

                case UIKeys.Z:
                {
                    internalTextLayerController.UndoLastAction();
                    EnsureCaretVisible();
                } break;

                case UIKeys.Y:
                {
                    internalTextLayerController.ReverseLastUndoAction();
                    EnsureCaretVisible();
                } break;

                case UIKeys.B:
                {
                    //TextSpanStyle style = internalTextLayerController.GetFirstTextStyleInSelectedRange();
                    //TextSpanStyle textStyle = null;

                    ////test only ***
                    ////TODO: make this more configurable
                    //if (style != null)
                    //{
                    //    TextSpanStyle defaultBeh = ((TextSpanStyle)style);
                    //    if (defaultBeh.FontBold)
                    //    {
                    //        textStyle = StyleHelper.CreateNewStyle(Color.Black);
                    //    }
                    //    else
                    //    {
                    //        textStyle = StyleHelper.CreateNewStyle(Color.Blue);
                    //    }
                    //}
                    //else
                    //{
                    //    textStyle = StyleHelper.CreateNewStyle(Color.Blue);
                    //}

                    //internalTextLayerController.DoFormatSelection(textStyle);

                    //if (internalTextLayerController.updateJustCurrentLine)
                    //{

                    //    InvalidateGraphicOfCurrentLineArea();
                    //}
                    //else
                    //{
                    //    InvalidateGraphics();
                    //}
                } break;
                }
            }
            if (textSurfaceEventListener != null)
            {
                TextSurfaceEventListener.NotifyKeyDown(textSurfaceEventListener, e.KeyCode);
            }
        }
Exemple #3
0
        public void HandleKeyDown(UIKeyEventArgs e)
        {
            this.SetCaretState(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 (internalTextLayerController.SelectionRange != null)
                {
                    InvalidateGraphicLocalArea(this, GetSelectionUpdateArea());
                }
                else
                {
                    InvalidateGraphicOfCurrentLineArea();
                }
                if (textSurfaceEventListener == null)
                {
                    internalTextLayerController.DoBackspace();
                }
                else
                {
                    if (!TextSurfaceEventListener.NotifyPreviewBackSpace(textSurfaceEventListener) &&
                        internalTextLayerController.DoBackspace())
                    {
                        TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener,
                                                                         new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine));
                    }
                }

                EnsureCaretVisible();
            }
            break;

            case UIKeys.Delete:
            {
                if (internalTextLayerController.SelectionRange != null)
                {
                    InvalidateGraphicLocalArea(this, GetSelectionUpdateArea());
                }
                else
                {
                    InvalidateGraphicOfCurrentLineArea();
                }
                if (textSurfaceEventListener == null)
                {
                    internalTextLayerController.DoDelete();
                }
                else
                {
                    VisualSelectionRangeSnapShot delpart = internalTextLayerController.DoDelete();
                    TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener,
                                                                     new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine));
                }

                EnsureCaretVisible();
            }
            break;

            default:
            {
                if (textSurfaceEventListener != null)
                {
                    UIKeys keycode = e.KeyCode;
                    if (keycode >= UIKeys.F1 && keycode <= UIKeys.F12)
                    {
                        InvalidateGraphicLocalArea(this, GetSelectionUpdateArea());
                        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
                    DoEnd(true);        //simulate
                    this.CurrentLineNumber = this.LineCount - 1;
                    DoEnd(true);
                }
                break;

                case UIKeys.C:
                {
                    StringBuilder stBuilder = GetFreeStringBuilder();
                    internalTextLayerController.CopySelectedTextToPlainText(stBuilder);
                    if (stBuilder != null)
                    {
                        if (stBuilder.Length == 0)
                        {
                            Clipboard.Clear();
                        }
                        else
                        {
                            Clipboard.SetText(stBuilder.ToString());
                        }
                    }
                    ReleaseStringBuilder(stBuilder);
                }
                break;

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

                        internalTextLayerController.AddUnformattedStringToCurrentLine(
                            Clipboard.GetUnicodeText(), this.currentSpanStyle);

                        EnsureCaretVisible();
                    }
                }
                break;

                case UIKeys.X:
                {
                    if (internalTextLayerController.SelectionRange != null)
                    {
                        if (internalTextLayerController.SelectionRange != null)
                        {
                            InvalidateGraphicLocalArea(this, GetSelectionUpdateArea());
                        }
                        StringBuilder stBuilder = GetFreeStringBuilder();
                        internalTextLayerController.CopySelectedTextToPlainText(stBuilder);
                        if (stBuilder != null)
                        {
                            Clipboard.SetText(stBuilder.ToString());
                        }

                        internalTextLayerController.DoDelete();
                        EnsureCaretVisible();
                        ReleaseStringBuilder(stBuilder);
                    }
                }
                break;

                case UIKeys.Z:
                {
                    internalTextLayerController.UndoLastAction();
                    EnsureCaretVisible();
                }
                break;

                case UIKeys.Y:
                {
                    internalTextLayerController.ReverseLastUndoAction();
                    EnsureCaretVisible();
                }
                break;

                case UIKeys.B:
                {
                    //
                    //test add markers
                    //
                    //if (internalTextLayerController.SelectionRange != null)
                    //{
                    //    //
                    //    internalTextLayerController.SelectionRange.SwapIfUnOrder();
                    //    VisualMarkerSelectionRange markerSelRange =
                    //        VisualMarkerSelectionRange.CreateFromSelectionRange(
                    //            internalTextLayerController.SelectionRange.GetSelectionRangeSnapshot());
                    //    //then add to the marker layers
                    //    markerSelRange.BindToTextLayer(textLayer);

                    //    internalTextLayerController.VisualMarkers.Add(markerSelRange);
                    //}

                    //
                    //TextSpanStyle style = internalTextLayerController.GetFirstTextStyleInSelectedRange();
                    //TextSpanStyle textStyle = null;

                    ////test only ***
                    ////TODO: make this more configurable
                    //if (style != null)
                    //{
                    //    TextSpanStyle defaultBeh = ((TextSpanStyle)style);
                    //    if (defaultBeh.FontBold)
                    //    {
                    //        textStyle = StyleHelper.CreateNewStyle(Color.Black);
                    //    }
                    //    else
                    //    {
                    //        textStyle = StyleHelper.CreateNewStyle(Color.Blue);
                    //    }
                    //}
                    //else
                    //{
                    //    textStyle = StyleHelper.CreateNewStyle(Color.Blue);
                    //}

                    //internalTextLayerController.DoFormatSelection(textStyle);

                    //if (internalTextLayerController.updateJustCurrentLine)
                    //{

                    //    InvalidateGraphicOfCurrentLineArea();
                    //}
                    //else
                    //{
                    //    InvalidateGraphics();
                    //}
                }
                break;
                }
            }
            if (textSurfaceEventListener != null)
            {
                TextSurfaceEventListener.NotifyKeyDown(textSurfaceEventListener, e.KeyCode);
            }
        }
Exemple #4
0
        public bool DoBackspace()
        {
#if DEBUG
            if (dbugEnableTextManRecorder)
            {
                dbug_BackSpaceCount++;
                dbugTextManRecorder.WriteInfo("TxLMan::DoBackSpace");
                dbugTextManRecorder.BeginContext();
            }
#endif

            VisualSelectionRangeSnapShot removeSelRange = this.RemoveSelectedText();
            if (!removeSelRange.IsEmpty())
            {
                CancelSelect();
#if DEBUG
                if (dbugEnableTextManRecorder)
                {
                    dbugTextManRecorder.EndContext();
                }
#endif
                return(true);
            }
            else
            {
                updateJustCurrentLine = true;
                char deletedChar = textLineWriter.DoBackspace();
                if (deletedChar == '\0')
                {
                    if (!IsOnFirstLine)
                    {
                        CurrentLineNumber--;
                        DoEnd();
                        commandHistory.AddDocAction(
                            new DocActionJoinWithNextLine(
                                textLineWriter.LineNumber, textLineWriter.CharIndex));
                        JoinWithNextLine();
                    }
#if DEBUG
                    if (dbugEnableTextManRecorder)
                    {
                        dbugTextManRecorder.EndContext();
                    }
#endif
                    return(false);
                }
                else
                {
                    commandHistory.AddDocAction(
                        new DocActionDeleteChar(
                            deletedChar, textLineWriter.LineNumber, textLineWriter.CharIndex));
#if DEBUG
                    if (dbugEnableTextManRecorder)
                    {
                        dbugTextManRecorder.EndContext();
                    }
#endif
                    return(true);
                }
            }
        }
Exemple #5
0
 public void AddMarkerSpan(VisualSelectionRangeSnapShot selectoinRangeSnapshot)
 {
 }