public virtual void HandleDoubleClick(UIMouseEventArgs e) { _editSession.CancelSelect(); Run textRun = this.CurrentTextRun; if (textRun != null) { #if DEBUG VisualPointInfo pointInfo = _editSession.GetCurrentPointInfo(); int lineCharacterIndex = pointInfo.LineCharIndex; int local_sel_Index = pointInfo.RunLocalSelectedIndex; #endif //default behaviour is select only a hit word under the caret //so ask the text layer to find a hit word _editSession.FindUnderlyingWord(out int startAt, out int len); if (len > 0) { InvalidateGraphicOfCurrentLineArea(); _editSession.TryMoveCaretTo(startAt, true); _editSession.StartSelect(); _editSession.TryMoveCaretTo(startAt + len); _editSession.EndSelect(); //internalTextLayerController.TryMoveCaretTo(lineCharacterIndex - local_sel_Index, true); //internalTextLayerController.StartSelect(); //internalTextLayerController.TryMoveCaretTo(internalTextLayerController.CharIndex + textRun.CharacterCount); //internalTextLayerController.EndSelect(); InvalidateGraphicOfCurrentLineArea(); } } }
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); } }
void LeftCopy(VisualPointInfo pointInfo, List <EditableRun> output) { if (pointInfo.LineId != _currentLineNumber) { throw new NotSupportedException(); } EditableRun tobeCutRun = pointInfo.TextRun; if (tobeCutRun == null) { return; } foreach (EditableRun t in _runs) { if (t != tobeCutRun) { output.Add(t.Clone()); } else { break; } } EditableRun preCutTextRun = tobeCutRun.LeftCopy(pointInfo.RunLocalSelectedIndex); if (preCutTextRun != null) { output.Add(preCutTextRun); } }
public void CopySelectedTextToPlainText(StringBuilder stBuilder) { if (_selectionRange != null) { _selectionRange.SwapIfUnOrder(); if (_selectionRange.IsOnTheSameLine) { List <EditableRun> copyRuns = new List <EditableRun>(); _textLineWriter.CopySelectedTextRuns(_selectionRange, copyRuns); foreach (EditableRun t in copyRuns) { t.CopyContentToStringBuilder(stBuilder); } } else { VisualPointInfo startPoint = _selectionRange.StartPoint; CurrentLineNumber = startPoint.LineId; _textLineWriter.SetCurrentCharIndex(startPoint.LineCharIndex); List <EditableRun> copyRuns = new List <EditableRun>(); _textLineWriter.CopySelectedTextRuns(_selectionRange, copyRuns); foreach (EditableRun t in copyRuns) { t.CopyContentToStringBuilder(stBuilder); } } } }
public void AddTextSpan(EditableRun textRun) { if (CurrentLine.IsBlankLine) { CurrentLine.AddLast(textRun); SetCurrentTextRun(textRun); CurrentLine.TextLineReCalculateActualLineSize(); CurrentLine.RefreshInlineArrange(); SetCurrentCharIndex(CharIndex + textRun.CharacterCount); } else { if (CurrentTextRun != null) { VisualPointInfo newPointInfo = CurrentLine.Split(GetCurrentPointInfo()); if (newPointInfo.IsOnTheBeginOfLine) { CurrentLine.AddBefore((EditableRun)newPointInfo.TextRun, textRun); } else { CurrentLine.AddAfter((EditableRun)newPointInfo.TextRun, textRun); } CurrentLine.TextLineReCalculateActualLineSize(); CurrentLine.RefreshInlineArrange(); EnsureCurrentTextRun(CharIndex + textRun.CharacterCount); } else { throw new NotSupportedException(); } } }
public void FindCurrentUnderlyingWord(out int startAt, out int len) { Run textRun = this.CurrentTextRun; if (textRun != null) { #if DEBUG VisualPointInfo pointInfo = _editSession.GetCurrentPointInfo(); int lineCharacterIndex = pointInfo.LineCharIndex; int local_sel_Index = pointInfo.RunLocalSelectedIndex; #endif //default behaviour is select only a hit word under the caret //so ask the text layer to find a hit word _editSession.FindUnderlyingWord(out startAt, out len); } else { startAt = len = 0; } }
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); } } }
void RightCopy(VisualPointInfo pointInfo, TextRangeCopy output) { if (pointInfo.LineId != _currentLineNumber) { throw new NotSupportedException(); } Run tobeCutRun = pointInfo.Run; if (tobeCutRun == null) { return; } CopyRun rightPart = tobeCutRun.Copy(pointInfo.RunLocalSelectedIndex); if (rightPart != null) { output.AppendRun(rightPart); } foreach (Run run in GetRunIterForward(tobeCutRun.NextRun, this.LastRun)) { output.AppendRun(run); } }
public Rectangle dbugGetRectAreaOf(int beginlineNum, int beginColumnNum, int endLineNum, int endColumnNum) { TextFlowLayer flowLayer = _textLayer; TextLineBox beginLine = flowLayer.GetTextLineAtPos(beginlineNum); if (beginLine == null) { return(Rectangle.Empty); } if (beginlineNum == endLineNum) { VisualPointInfo beginPoint = beginLine.GetTextPointInfoFromCharIndex(beginColumnNum); VisualPointInfo endPoint = beginLine.GetTextPointInfoFromCharIndex(endColumnNum); return(new Rectangle(beginPoint.X, beginLine.Top, endPoint.X, beginLine.ActualLineHeight)); } else { VisualPointInfo beginPoint = beginLine.GetTextPointInfoFromCharIndex(beginColumnNum); TextLineBox endLine = flowLayer.GetTextLineAtPos(endLineNum); VisualPointInfo endPoint = endLine.GetTextPointInfoFromCharIndex(endColumnNum); return(new Rectangle(beginPoint.X, beginLine.Top, endPoint.X, beginLine.ActualLineHeight)); } }
void RightCopy(VisualPointInfo pointInfo, List <EditableRun> output) { if (pointInfo.LineId != _currentLineNumber) { throw new NotSupportedException(); } EditableRun tobeCutRun = pointInfo.TextRun; if (tobeCutRun == null) { return; } EditableRun postCutTextRun = (EditableRun)tobeCutRun.Copy(pointInfo.RunLocalSelectedIndex); if (postCutTextRun != null) { output.Add(postCutTextRun); } foreach (EditableRun t in GetVisualElementForward(tobeCutRun.NextTextRun, this.LastRun)) { output.Add(t.Clone()); } }
internal void Remove(VisualSelectionRange selectionRange) { EditableVisualPointInfo startPoint = selectionRange.StartPoint; EditableVisualPointInfo endPoint = selectionRange.EndPoint; if (startPoint.TextRun != null) { if (startPoint.TextRun == endPoint.TextRun) { EditableRun removedRun = (EditableRun)startPoint.TextRun; EditableRun.InnerRemove(removedRun, startPoint.RunLocalSelectedIndex, endPoint.LineCharIndex - startPoint.LineCharIndex, false); if (removedRun.CharacterCount == 0) { if (startPoint.LineId == _currentLineNumber) { this.Remove(removedRun); } else { EditableTextLine line = EditableFlowLayer.GetTextLine(startPoint.LineId); line.Remove(removedRun); } } } else { EditableVisualPointInfo newStartPoint = null; EditableVisualPointInfo newStopPoint = null; EditableTextLine startLine = null; EditableTextLine stopLine = null; if (startPoint.LineId == _currentLineNumber) { startLine = this; } else { startLine = EditableFlowLayer.GetTextLine(startPoint.LineId); } newStartPoint = startLine.Split(startPoint); if (endPoint.LineId == _currentLineNumber) { stopLine = this; } else { stopLine = EditableFlowLayer.GetTextLine(endPoint.LineId); } newStopPoint = stopLine.Split(endPoint); if (startLine == stopLine) { if (newStartPoint.TextRun != null) { LinkedList <EditableRun> tobeRemoveRuns = new LinkedList <EditableRun>(); if (newStartPoint.LineCharIndex == 0) { foreach (EditableRun t in EditableFlowLayer.TextRunForward( (EditableRun)newStartPoint.TextRun, (EditableRun)newStopPoint.TextRun)) { tobeRemoveRuns.AddLast(t); } } else { foreach (EditableRun t in EditableFlowLayer.TextRunForward( newStartPoint.TextRun.NextTextRun, (EditableRun)newStopPoint.TextRun)) { tobeRemoveRuns.AddLast(t); } } startLine.LocalSuspendLineReArrange(); foreach (EditableRun 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((EditableRun)newStopPoint.TextRun); } for (int i = stopLineId - 1; i > startLineId; i--) { EditableTextLine line = EditableFlowLayer.GetTextLine(i); line.Clear(); line.JoinWithNextLine(); } if (newStartPoint.LineCharIndex == 0) { startLine.RemoveRight((EditableRun)newStartPoint.TextRun); } else { EditableRun nextRun = ((EditableRun)newStartPoint.TextRun).NextTextRun; if (nextRun != null && !nextRun.IsLineBreak) { startLine.RemoveRight(nextRun); } } startLine.JoinWithNextLine(); } } } else { VisualPointInfo newStartPoint = null; VisualPointInfo newStopPoint = null; EditableTextLine startLine = null; EditableTextLine stopLine = null; if (startPoint.LineId == _currentLineNumber) { startLine = this; } else { startLine = EditableFlowLayer.GetTextLine(startPoint.LineId); } newStartPoint = startLine.Split(startPoint); if (endPoint.LineId == _currentLineNumber) { stopLine = this; } else { stopLine = EditableFlowLayer.GetTextLine(endPoint.LineId); } newStopPoint = stopLine.Split(endPoint); if (startLine == stopLine) { if (newStartPoint.TextRun != null) { LinkedList <EditableRun> tobeRemoveRuns = new LinkedList <EditableRun>(); if (newStartPoint.LineCharIndex == -1) { foreach (EditableRun t in EditableFlowLayer.TextRunForward( (EditableRun)newStartPoint.TextRun, (EditableRun)newStopPoint.TextRun)) { tobeRemoveRuns.AddLast(t); } } else { foreach (EditableRun t in EditableFlowLayer.TextRunForward( newStartPoint.TextRun.NextTextRun, (EditableRun)newStopPoint.TextRun)) { tobeRemoveRuns.AddLast(t); } } foreach (EditableRun 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((EditableRun)newStopPoint.TextRun); } for (int i = stopLineId - 1; i > startLineId; i--) { EditableTextLine line = EditableFlowLayer.GetTextLine(i); line.Clear(); line.JoinWithNextLine(); } if (newStartPoint.LineCharIndex == -1) { //TODO: review here again //at this point newStartPoint.TextRun should always null if (newStartPoint.TextRun != null) { startLine.RemoveRight((EditableRun)newStartPoint.TextRun); } } else { //at this point newStartPoint.TextRun should always null //TODO newStartPoint.TextRun == null??? if (newStartPoint.TextRun != null) { EditableRun nextRun = newStartPoint.TextRun.NextTextRun; if (nextRun != null && !nextRun.IsLineBreak) { startLine.RemoveRight(nextRun); } } } startLine.JoinWithNextLine(); } } }