internal EditableVisualPointInfo[] Split(VisualSelectionRange selectionRange) { selectionRange.SwapIfUnOrder(); EditableVisualPointInfo startPoint = selectionRange.StartPoint; EditableVisualPointInfo endPoint = selectionRange.EndPoint; if (startPoint.TextRun == endPoint.TextRun) { EditableRun toBeCutTextRun = startPoint.TextRun; EditableRun preCutTextRun = (EditableRun)toBeCutTextRun.LeftCopy(startPoint.RunLocalSelectedIndex); EditableRun middleCutTextRun = (EditableRun)toBeCutTextRun.Copy(startPoint.RunLocalSelectedIndex + 1, endPoint.LineCharIndex - startPoint.LineCharIndex); EditableRun postCutTextRun = (EditableRun)toBeCutTextRun.Copy(endPoint.RunLocalSelectedIndex + 1); EditableVisualPointInfo newStartRangePointInfo = null; EditableVisualPointInfo newEndRangePointInfo = null; EditableTextLine line = this; if (startPoint.LineId != currentLineNumber) { line = editableFlowLayer.GetTextLine(startPoint.LineId); } line.LocalSuspendLineReArrange(); if (preCutTextRun != null) { line.AddBefore(toBeCutTextRun, preCutTextRun); newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, startPoint.X, preCutTextRun, startPoint.TextRunCharOffset, startPoint.TextRunPixelOffset); } else { EditableRun prevTxtRun = GetPrevTextRun((EditableRun)startPoint.TextRun); if (prevTxtRun != null) { newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, startPoint.X, prevTxtRun, startPoint.TextRunCharOffset - preCutTextRun.CharacterCount, startPoint.TextRunPixelOffset - prevTxtRun.Width); } else { newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, 0, null, 0, 0); } } if (postCutTextRun != null) { line.AddAfter(toBeCutTextRun, postCutTextRun); newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, middleCutTextRun, startPoint.TextRunCharOffset + middleCutTextRun.CharacterCount, startPoint.TextRunPixelOffset + middleCutTextRun.Width); } else { EditableRun nextTxtRun = GetNextTextRun((EditableRun)endPoint.TextRun); if (nextTxtRun != null) { newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, nextTxtRun, endPoint.TextRunPixelOffset + endPoint.TextRun.CharacterCount, endPoint.TextRunPixelOffset + endPoint.TextRun.Width); } else { newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, middleCutTextRun, endPoint.TextRunCharOffset, endPoint.TextRunPixelOffset); } } if (middleCutTextRun != null) { line.AddAfter(toBeCutTextRun, middleCutTextRun); } else { throw new NotSupportedException(); } line.Remove(toBeCutTextRun); line.LocalResumeLineReArrange(); return(new EditableVisualPointInfo[] { newStartRangePointInfo, newEndRangePointInfo }); } else { EditableTextLine workingLine = this; if (startPoint.LineId != currentLineNumber) { workingLine = editableFlowLayer.GetTextLine(startPoint.LineId); } EditableVisualPointInfo newStartPoint = workingLine.Split(startPoint); workingLine = this; if (endPoint.LineId != currentLineNumber) { workingLine = editableFlowLayer.GetTextLine(endPoint.LineId); } EditableVisualPointInfo newEndPoint = workingLine.Split(endPoint); return(new EditableVisualPointInfo[] { newStartPoint, newEndPoint }); } }
VisualSelectionRangeSnapShot RemoveSelectedText() { #if DEBUG if (dbugEnableTextManRecorder) { dbugTextManRecorder.WriteInfo("TxLMan::RemoveSelectedText"); dbugTextManRecorder.BeginContext(); } #endif if (selectionRange == null) { #if DEBUG if (dbugEnableTextManRecorder) { dbugTextManRecorder.WriteInfo("NO_SEL_RANGE"); dbugTextManRecorder.EndContext(); } #endif return(VisualSelectionRangeSnapShot.Empty); } else if (!selectionRange.IsValid) { #if DEBUG if (dbugEnableTextManRecorder) { dbugTextManRecorder.WriteInfo("!RANGE_ON_SAME_POINT"); } #endif CancelSelect(); #if DEBUG if (dbugEnableTextManRecorder) { dbugTextManRecorder.EndContext(); } #endif return(VisualSelectionRangeSnapShot.Empty); } selectionRange.SwapIfUnOrder(); VisualSelectionRangeSnapShot selSnapshot = selectionRange.GetSelectionRangeSnapshot(); VisualPointInfo startPoint = selectionRange.StartPoint; CurrentLineNumber = startPoint.LineId; int preCutIndex = startPoint.LineCharIndex; textLineWriter.CharIndex = startPoint.LineCharIndex; if (selectionRange.IsOnTheSameLine) { LinkedList <EditableRun> tobeDeleteTextRun = textLineWriter.CopySelectedTextRuns(selectionRange); if (tobeDeleteTextRun != null) { commandHistory.AddDocAction( new DocActionDeleteRange(tobeDeleteTextRun, selSnapshot.startLineNum, selSnapshot.startColumnNum, selSnapshot.endLineNum, selSnapshot.endColumnNum)); textLineWriter.RemoveSelectedTextRuns(selectionRange); updateJustCurrentLine = true; } } else { int startPointLindId = startPoint.LineId; int startPointCharIndex = startPoint.LineCharIndex; LinkedList <EditableRun> tobeDeleteTextRun = textLineWriter.CopySelectedTextRuns(selectionRange); if (tobeDeleteTextRun != null) { commandHistory.AddDocAction( new DocActionDeleteRange(tobeDeleteTextRun, selSnapshot.startLineNum, selSnapshot.startColumnNum, selSnapshot.endLineNum, selSnapshot.endColumnNum)); textLineWriter.RemoveSelectedTextRuns(selectionRange); updateJustCurrentLine = false; textLineWriter.MoveToLine(startPointLindId); textLineWriter.CharIndex = startPointCharIndex; } } CancelSelect(); TextEditRenderBox.NotifyTextContentSizeChanged(visualTextSurface); #if DEBUG if (dbugEnableTextManRecorder) { dbugTextManRecorder.EndContext(); } #endif return(selSnapshot); }
internal EditableVisualPointInfo[] Split(VisualSelectionRange selectionRange) { selectionRange.SwapIfUnOrder(); EditableVisualPointInfo startPoint = selectionRange.StartPoint; EditableVisualPointInfo endPoint = selectionRange.EndPoint; if (startPoint.TextRun == endPoint.TextRun) { EditableRun toBeCutTextRun = startPoint.TextRun; EditableRun preCutTextRun = (EditableRun)toBeCutTextRun.LeftCopy(startPoint.LocalSelectedIndex); EditableRun middleCutTextRun = (EditableRun)toBeCutTextRun.Copy(startPoint.LocalSelectedIndex + 1, endPoint.LineCharIndex - startPoint.LineCharIndex); EditableRun postCutTextRun = (EditableRun)toBeCutTextRun.Copy(endPoint.LocalSelectedIndex + 1); EditableVisualPointInfo newStartRangePointInfo = null; EditableVisualPointInfo newEndRangePointInfo = null; EditableTextLine line = this; if (startPoint.LineId != currentLineNumber) { line = editableFlowLayer.GetTextLine(startPoint.LineId); } line.LocalSuspendLineReArrange(); if (preCutTextRun != null) { line.AddBefore(toBeCutTextRun, preCutTextRun); newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, startPoint.X, preCutTextRun, startPoint.TextRunCharOffset, startPoint.TextRunPixelOffset); } else { EditableRun prevTxtRun = GetPrevTextRun((EditableRun)startPoint.TextRun); if (prevTxtRun != null) { newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, startPoint.X, prevTxtRun, startPoint.TextRunCharOffset - preCutTextRun.CharacterCount, startPoint.TextRunPixelOffset - prevTxtRun.Width); } else { newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, 0, null, 0, 0); } } if (postCutTextRun != null) { line.AddAfter(toBeCutTextRun, postCutTextRun); newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, middleCutTextRun, startPoint.TextRunCharOffset + middleCutTextRun.CharacterCount, startPoint.TextRunPixelOffset + middleCutTextRun.Width); } else { EditableRun nextTxtRun = GetNextTextRun((EditableRun)endPoint.TextRun); if (nextTxtRun != null) { newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, nextTxtRun, endPoint.TextRunPixelOffset + endPoint.TextRun.CharacterCount, endPoint.TextRunPixelOffset + endPoint.TextRun.Width); } else { newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, middleCutTextRun, endPoint.TextRunCharOffset, endPoint.TextRunPixelOffset); } } if (middleCutTextRun != null) { line.AddAfter(toBeCutTextRun, middleCutTextRun); } else { throw new NotSupportedException(); } line.Remove(toBeCutTextRun); line.LocalResumeLineReArrange(); return new EditableVisualPointInfo[] { newStartRangePointInfo, newEndRangePointInfo }; } else { EditableTextLine workingLine = this; if (startPoint.LineId != currentLineNumber) { workingLine = editableFlowLayer.GetTextLine(startPoint.LineId); } EditableVisualPointInfo newStartPoint = workingLine.Split(startPoint); workingLine = this; if (endPoint.LineId != currentLineNumber) { workingLine = editableFlowLayer.GetTextLine(endPoint.LineId); } EditableVisualPointInfo newEndPoint = workingLine.Split(endPoint); return new EditableVisualPointInfo[] { newStartPoint, newEndPoint }; } }