void LeftCopy(VisualPointInfo pointInfo, TextRangeCopy output) { if (pointInfo.LineId != _currentLineNumber) { throw new NotSupportedException(); } Run tobeCutRun = pointInfo.Run; if (tobeCutRun == null) { return; } foreach (Run run in _runs) { if (run != tobeCutRun) { output.AppendRun(run); } else { break; } } CopyRun leftPart = tobeCutRun.LeftCopy(pointInfo.RunLocalSelectedIndex); if (leftPart != null) { output.AppendRun(leftPart); } }
internal EditableVisualPointInfo Split(EditableVisualPointInfo pointInfo) { if (pointInfo.LineId != _currentLineNumber) { throw new NotSupportedException(); } Run tobeCutRun = pointInfo.Run; if (tobeCutRun == null) { return(CreateTextPointInfo( pointInfo.LineId, pointInfo.LineCharIndex, pointInfo.X, null, pointInfo.TextRunCharOffset, pointInfo.TextRunPixelOffset)); } this.LocalSuspendLineReArrange(); EditableVisualPointInfo result = null; CopyRun leftPart = tobeCutRun.LeftCopy(pointInfo.RunLocalSelectedIndex); CopyRun rightPart = tobeCutRun.Copy(pointInfo.RunLocalSelectedIndex); if (leftPart != null) { Run leftRun = AddBefore(tobeCutRun, leftPart); if (rightPart != null) { this.AddAfter(tobeCutRun, rightPart); } result = CreateTextPointInfo( pointInfo.LineId, pointInfo.LineCharIndex, pointInfo.X, leftRun, pointInfo.TextRunCharOffset, pointInfo.TextRunPixelOffset); } else { if (rightPart != null) { this.AddAfter(tobeCutRun, rightPart); } Run infoTextRun = null; if (IsSingleLine) { if (tobeCutRun.PrevRun != null) { infoTextRun = tobeCutRun.PrevRun; } else { infoTextRun = tobeCutRun.NextRun; } } else { if (IsFirstLine) { if (tobeCutRun.PrevRun != null) { infoTextRun = tobeCutRun.PrevRun; } else { if (tobeCutRun.NextRun == null) { infoTextRun = null; } else { infoTextRun = tobeCutRun.NextRun; } } } else if (IsLastLine) { if (tobeCutRun.PrevRun != null) { infoTextRun = tobeCutRun.PrevRun; } else { } } else { if (tobeCutRun.NextRun != null) { infoTextRun = tobeCutRun.NextRun; } else { infoTextRun = null; } } } result = CreateTextPointInfo( pointInfo.LineId, pointInfo.LineCharIndex, pointInfo.X, infoTextRun, pointInfo.TextRunCharOffset, pointInfo.TextRunPixelOffset); } this.Remove(tobeCutRun); this.LocalResumeLineReArrange(); return(result); }
internal SelectionRangeInfo Split(VisualSelectionRange selectionRange) { selectionRange.SwapIfUnOrder(); EditableVisualPointInfo startPoint = selectionRange.StartPoint; EditableVisualPointInfo endPoint = selectionRange.EndPoint; if (startPoint.Run == endPoint.Run) { Run toBeCutTextRun = startPoint.Run; CopyRun leftPart = toBeCutTextRun.LeftCopy(startPoint.RunLocalSelectedIndex); CopyRun middlePart = toBeCutTextRun.Copy(startPoint.RunLocalSelectedIndex, endPoint.LineCharIndex - startPoint.LineCharIndex); CopyRun rightPart = toBeCutTextRun.Copy(endPoint.RunLocalSelectedIndex); EditableVisualPointInfo newStartRangePointInfo = null; EditableVisualPointInfo newEndRangePointInfo = null; TextLineBox line = this; if (startPoint.LineId != _currentLineNumber) { line = _textFlowLayer.GetTextLine(startPoint.LineId); } line.LocalSuspendLineReArrange(); if (leftPart != null) { Run leftRun = line.AddBefore(toBeCutTextRun, leftPart); newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, startPoint.X, leftRun, startPoint.TextRunCharOffset, startPoint.TextRunPixelOffset); } else { //no left part, //so we connect to prev text run Run prevTxtRun = startPoint.Run.PrevRun; if (prevTxtRun != null) { newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, startPoint.X, prevTxtRun, startPoint.TextRunCharOffset - leftPart.CharacterCount, startPoint.TextRunPixelOffset - prevTxtRun.Width); } else { //no prev run, we are at the begining of the line newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, 0, null, 0, 0); } } if (rightPart != null) { Run rightRun = line.AddAfter(toBeCutTextRun, rightPart); newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, null, ///?? startPoint.TextRunCharOffset + middlePart.CharacterCount, startPoint.TextRunPixelOffset + MeasureCopyRunLength(middlePart).Width); } else { Run nextTxtRun = endPoint.Run.NextRun; if (nextTxtRun != null) { newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, null, ///?? endPoint.TextRunPixelOffset + endPoint.Run.CharacterCount, endPoint.TextRunPixelOffset + endPoint.Run.Width); } else { newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, null, endPoint.TextRunCharOffset, endPoint.TextRunPixelOffset); } } if (middlePart != null) { line.AddAfter(toBeCutTextRun, middlePart); } else { throw new NotSupportedException(); } line.Remove(toBeCutTextRun); line.LocalResumeLineReArrange(); return(new SelectionRangeInfo(newStartRangePointInfo, newEndRangePointInfo)); } else { TextLineBox workingLine = this; if (startPoint.LineId != _currentLineNumber) { workingLine = _textFlowLayer.GetTextLine(startPoint.LineId); } EditableVisualPointInfo newStartPoint = workingLine.Split(startPoint); workingLine = this; if (endPoint.LineId != _currentLineNumber) { workingLine = _textFlowLayer.GetTextLine(endPoint.LineId); } EditableVisualPointInfo newEndPoint = workingLine.Split(endPoint); return(new SelectionRangeInfo(newStartPoint, newEndPoint)); } }