public void CopySelectedTextToPlainText(StringBuilder stBuilder) { if (_selectionRange != null) { _selectionRange.SwapIfUnOrder(); if (_selectionRange.IsOnTheSameLine) { var copyRuns = new TextRangeCopy(); _lineEditor.CopySelectedTextRuns(_selectionRange, copyRuns); copyRuns.CopyContentToStringBuilder(stBuilder); } else { VisualPointInfo startPoint = _selectionRange.StartPoint; CurrentLineNumber = startPoint.LineId; _lineEditor.SetCurrentCharIndex(startPoint.LineCharIndex); var copyRuns = new TextRangeCopy(); _lineEditor.CopySelectedTextRuns(_selectionRange, copyRuns); copyRuns.CopyContentToStringBuilder(stBuilder); } } }
public void DoTab() { if (!_isEditable) { return; } // if (_editSession.SelectionRange != null) { VisualSelectionRange visualSelectionRange = _editSession.SelectionRange; visualSelectionRange.SwapIfUnOrder(); if (visualSelectionRange.IsValid && !visualSelectionRange.IsOnTheSameLine) { InvalidateGraphicOfCurrentSelectionArea(); // _editSession.DoTabOverSelectedRange(); return; //finish here } } //------------ //do tab as usuall int insertAt = _editSession.CurrentLineCharIndex; for (int i = NumOfWhitespaceForSingleTab; i >= 0; --i) { _editSession.AddCharToCurrentLine(' '); } if (_textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyStringAdded(_textSurfaceEventListener, insertAt, new string(' ', NumOfWhitespaceForSingleTab)); } InvalidateGraphicOfCurrentLineArea(); }
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)); } }
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, endPoint.LineCharIndex - startPoint.LineCharIndex); EditableRun postCutTextRun = (EditableRun)toBeCutTextRun.Copy(endPoint.RunLocalSelectedIndex); 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 }); } }