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(); } } }
public static void InnerDoJoinWithNextLine(TextLineBox line) { line.JoinWithNextLine(); }