コード例 #1
0
ファイル: TextLineWalker.cs プロジェクト: brezza92/PixelFarm
        char BackSpaceOneChar()
        {
            if (CurrentTextRun == null)
            {
                return('\0');
            }
            else
            {
                if (CharIndex == 0)
                {
                    return('\0');
                }

                //move back 1 char and do delete
                Run removingTextRun = CurrentTextRun;
                int removeIndex     = CurrentTextRunCharIndex;
                SetCurrentCharStepLeft();
                char toBeRemovedChar = CurrentChar;

                Run.InnerRemove(removingTextRun, removeIndex, 1, false);
                if (removingTextRun.CharacterCount == 0)
                {
                    Run nextRun = removingTextRun.NextRun;
                    CurrentLine.Remove(removingTextRun);
                    SetCurrentTextRun(nextRun);
                    EnsureCurrentTextRun();
                }
                CurrentLine.TextLineReCalculateActualLineSize();
                CurrentLine.RefreshInlineArrange();
                return(toBeRemovedChar);
            }
        }
コード例 #2
0
ファイル: TextLineWalker.cs プロジェクト: brezza92/PixelFarm
        public void SplitToNewLine()
        {
            Run currentRun = CurrentTextRun;

            if (CurrentLine.IsBlankLine)
            {
                CurrentLine.AddLineBreakAfterLastRun();
            }
            else
            {
                if (CharIndex == -1)
                {
                    CurrentLine.AddLineBreakBeforeFirstRun();
                    SetCurrentTextRun(null);
                }
                else
                {
                    CopyRun rightSplitedPart = Run.InnerRemove(currentRun,
                                                               CurrentTextRunCharIndex + 1, true);
                    if (rightSplitedPart != null)
                    {
                        CurrentLine.AddAfter(currentRun, rightSplitedPart);
                    }

                    CurrentLine.AddLineBreakAfter(currentRun);
                    if (currentRun.CharacterCount == 0)
                    {
                        CurrentLine.Remove(currentRun);
                    }
                }
            }


            this.TextLayer.TopDownReCalculateContentSize();
            EnsureCurrentTextRun();
        }
コード例 #3
0
        internal void Remove(VisualSelectionRange selectionRange)
        {
            EditableVisualPointInfo startPoint = selectionRange.StartPoint;
            EditableVisualPointInfo endPoint   = selectionRange.EndPoint;

            if (startPoint.Run != null)
            {
                if (startPoint.Run == endPoint.Run)
                {
                    Run removedRun = startPoint.Run;
                    Run.InnerRemove(removedRun,
                                    startPoint.RunLocalSelectedIndex,
                                    endPoint.LineCharIndex - startPoint.LineCharIndex, false);
                    if (removedRun.CharacterCount == 0)
                    {
                        if (startPoint.LineId == _currentLineNumber)
                        {
                            this.Remove(removedRun);
                        }
                        else
                        {
                            TextLineBox line = _textFlowLayer.GetTextLine(startPoint.LineId);
                            line.Remove(removedRun);
                        }
                    }
                }
                else
                {
                    GetStartAndStopLine(startPoint, endPoint, out TextLineBox startLine, out TextLineBox stopLine);

                    EditableVisualPointInfo newStartPoint = startLine.Split(startPoint);
                    EditableVisualPointInfo newStopPoint  = stopLine.Split(endPoint);

                    if (startLine == stopLine)
                    {
                        if (newStartPoint.Run != null)
                        {
                            LinkedList <Run> tobeRemoveRuns = new LinkedList <Run>();
                            if (newStartPoint.LineCharIndex == 0)
                            {
                                foreach (Run t in _textFlowLayer.TextRunForward(
                                             newStartPoint.Run,
                                             newStopPoint.Run))
                                {
                                    tobeRemoveRuns.AddLast(t);
                                }
                            }
                            else
                            {
                                foreach (Run t in _textFlowLayer.TextRunForward(
                                             newStartPoint.Run.NextRun,
                                             newStopPoint.Run))
                                {
                                    tobeRemoveRuns.AddLast(t);
                                }
                            }
                            startLine.LocalSuspendLineReArrange();
                            foreach (Run t in tobeRemoveRuns)
                            {
                                startLine.Remove(t);
                            }
                            startLine.LocalResumeLineReArrange();
                        }
                        else
                        {
                            //this may be the blank line
                            startLine.Clear();
#if DEBUG
                            //TODO: review here again
                            //System.Diagnostics.Debug.WriteLine("EditableTextLine_adv1");
#endif
                        }
                    }
                    else
                    {
                        int startLineId = newStartPoint.LineId;
                        int stopLineId  = newStopPoint.LineId;
                        if (newStopPoint.LineCharIndex > 0)
                        {
                            stopLine.RemoveLeft(newStopPoint.Run);
                        }
                        for (int i = stopLineId - 1; i > startLineId; i--)
                        {
                            TextLineBox line = _textFlowLayer.GetTextLine(i);
                            line.Clear();
                            line.JoinWithNextLine();
                        }
                        if (newStartPoint.LineCharIndex == 0)
                        {
                            startLine.RemoveRight(newStartPoint.Run);
                        }
                        else
                        {
                            Run nextRun = (newStartPoint.Run).NextRun;
                            if (nextRun != null)
                            {
                                startLine.RemoveRight(nextRun);
                            }
                        }
                        startLine.JoinWithNextLine();
                    }
                }
            }
            else
            {
                GetStartAndStopLine(startPoint, endPoint, out TextLineBox startLine, out TextLineBox stopLine);
                EditableVisualPointInfo newStartPoint = startLine.Split(startPoint);
                EditableVisualPointInfo newStopPoint  = stopLine.Split(endPoint);
                if (startLine == stopLine)
                {
                    if (newStartPoint.Run != null)
                    {
                        LinkedList <Run> tobeRemoveRuns = new LinkedList <Run>();
                        if (newStartPoint.LineCharIndex == -1)
                        {
                            foreach (Run t in _textFlowLayer.TextRunForward(
                                         newStartPoint.Run,
                                         newStopPoint.Run))
                            {
                                tobeRemoveRuns.AddLast(t);
                            }
                        }
                        else
                        {
                            foreach (Run t in _textFlowLayer.TextRunForward(
                                         newStartPoint.Run.NextRun,
                                         newStopPoint.Run))
                            {
                                tobeRemoveRuns.AddLast(t);
                            }
                        }
                        foreach (Run t in tobeRemoveRuns)
                        {
                            startLine.Remove(t);
                        }
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
                else
                {
                    int startLineId = newStartPoint.LineId;
                    int stopLineId  = newStopPoint.LineId;
                    if (newStopPoint.LineCharIndex > -1)
                    {
                        stopLine.RemoveLeft(newStopPoint.Run);
                    }
                    for (int i = stopLineId - 1; i > startLineId; i--)
                    {
                        TextLineBox line = _textFlowLayer.GetTextLine(i);
                        line.Clear();
                        line.JoinWithNextLine();
                    }
                    if (newStartPoint.LineCharIndex == -1)
                    {
                        //TODO: review here again
                        //at this point newStartPoint.TextRun should always null
                        if (newStartPoint.Run != null)
                        {
                            startLine.RemoveRight(newStartPoint.Run);
                        }
                    }
                    else
                    {
                        //at this point newStartPoint.TextRun should always null
                        //TODO newStartPoint.TextRun == null???
                        if (newStartPoint.Run != null)
                        {
                            Run nextRun = newStartPoint.Run.NextRun;
                            if (nextRun != null)
                            {
                                startLine.RemoveRight(nextRun);
                            }
                        }
                    }
                    startLine.JoinWithNextLine();
                }
            }
        }