LayoutFarm.Text.EditableTextLine.RightCopy C# (CSharp) Метод

RightCopy() приватный Метод

private RightCopy ( VisualPointInfo pointInfo, LinkedList output ) : void
pointInfo VisualPointInfo
output LinkedList
Результат void
        void RightCopy(VisualPointInfo pointInfo, LinkedList<EditableRun> output)
        {
            if (pointInfo.LineId != currentLineNumber)
            {
                throw new NotSupportedException();
            }
            EditableRun tobeCutRun = pointInfo.TextRun;
            if (tobeCutRun == null)
            {
                return;
            }
            EditableRun postCutTextRun = (EditableRun)tobeCutRun.Copy(pointInfo.LocalSelectedIndex + 1);
            if (postCutTextRun != null)
            {
                output.AddLast(postCutTextRun);
            }
            foreach (EditableRun t in GetVisualElementForward(tobeCutRun.NextTextRun, this.LastRun))
            {
                output.AddLast(t.Clone());
            }
        }

Usage Example

Пример #1
0
        public void Copy(VisualSelectionRange selectionRange, List <EditableRun> output)
        {
            EditableVisualPointInfo startPoint = selectionRange.StartPoint;
            EditableVisualPointInfo endPoint   = selectionRange.EndPoint;

            if (startPoint.TextRun != null)
            {
                if (startPoint.TextRun == endPoint.TextRun)
                {
                    EditableRun elem =
                        startPoint.TextRun.Copy(
                            startPoint.RunLocalSelectedIndex,
                            endPoint.LineCharIndex - startPoint.LineCharIndex);
                    if (elem != null)
                    {
                        output.Add(elem);
                    }
                }
                else
                {
                    EditableTextLine startLine = null;
                    EditableTextLine stopLine  = null;
                    if (startPoint.LineId == currentLineNumber)
                    {
                        startLine = this;
                    }
                    else
                    {
                        startLine = editableFlowLayer.GetTextLine(startPoint.LineId);
                    }
                    if (endPoint.LineId == currentLineNumber)
                    {
                        stopLine = this;
                    }
                    else
                    {
                        stopLine = editableFlowLayer.GetTextLine(endPoint.LineId);
                    }
                    if (startLine == stopLine)
                    {
                        EditableRun postCutTextRun = startPoint.TextRun.Copy(startPoint.RunLocalSelectedIndex);
                        if (postCutTextRun != null)
                        {
                            output.Add(postCutTextRun);
                        }
                        if (startPoint.TextRun.NextTextRun != endPoint.TextRun)
                        {
                            foreach (EditableRun t in editableFlowLayer.TextRunForward(startPoint.TextRun.NextTextRun, endPoint.TextRun.PrevTextRun))
                            {
                                output.Add(t.Clone());
                            }
                        }

                        EditableRun preCutTextRun = endPoint.TextRun.LeftCopy(endPoint.RunLocalSelectedIndex);
                        if (preCutTextRun != null)
                        {
                            output.Add(preCutTextRun);
                        }
                    }
                    else
                    {
                        int startLineId = startPoint.LineId;
                        int stopLineId  = endPoint.LineId;
                        startLine.RightCopy(startPoint, output);
                        for (int i = startLineId + 1; i < stopLineId; i++)
                        {
                            output.Add(new EditableTextRun(this.Root, '\n', this.CurrentTextSpanStyle));
                            EditableTextLine line = editableFlowLayer.GetTextLine(i);
                            line.Copy(output);
                        }
                        if (endPoint.LineCharIndex > -1)
                        {
                            output.Add(new EditableTextRun(this.Root, '\n', this.CurrentTextSpanStyle));
                            stopLine.LeftCopy(endPoint, output);
                        }
                    }
                }
            }
            else
            {
                EditableTextLine startLine = null;
                EditableTextLine stopLine  = null;
                if (startPoint.LineId == currentLineNumber)
                {
                    startLine = this;
                }
                else
                {
                    startLine = editableFlowLayer.GetTextLine(startPoint.LineId);
                }

                if (endPoint.LineId == currentLineNumber)
                {
                    stopLine = this;
                }
                else
                {
                    stopLine = editableFlowLayer.GetTextLine(endPoint.LineId);
                }


                if (startLine == stopLine)
                {
                    if (startPoint.LineCharIndex == -1)
                    {
                        foreach (EditableRun t in editableFlowLayer.TextRunForward(startPoint.TextRun, endPoint.TextRun.PrevTextRun))
                        {
                            output.Add(t.Clone());
                        }
                        EditableRun postCutTextRun = endPoint.TextRun.Copy(endPoint.RunLocalSelectedIndex + 1);
                        if (postCutTextRun != null)
                        {
                            output.Add(postCutTextRun);
                        }
                    }
                    else
                    {
                        EditableRun postCutTextRun = startPoint.TextRun.Copy(startPoint.RunLocalSelectedIndex + 1);
                        if (postCutTextRun != null)
                        {
                            output.Add(postCutTextRun);
                        }

                        foreach (EditableRun t in editableFlowLayer.TextRunForward(startPoint.TextRun.NextTextRun, endPoint.TextRun.PrevTextRun))
                        {
                            output.Add(t.Clone());
                        }

                        EditableRun preCutTextRun = endPoint.TextRun.LeftCopy(startPoint.RunLocalSelectedIndex);
                        if (preCutTextRun != null)
                        {
                            output.Add(preCutTextRun);
                        }
                    }
                }
                else
                {
                    int startLineId = startPoint.LineId;
                    int stopLineId  = endPoint.LineId;
                    startLine.RightCopy(startPoint, output);
                    for (int i = startLineId + 1; i < stopLineId; i++)
                    {
                        output.Add(new EditableTextRun(this.Root, '\n', this.CurrentTextSpanStyle));
                        EditableTextLine line = editableFlowLayer.GetTextLine(i);
                        line.Copy(output);
                    }
                    stopLine.LeftCopy(endPoint, output);
                }
            }
        }