private VisualTextLine Cut(VisualTextLine line, int startIndex, int? count = null) { var substringLength = count == null ? line.Length - startIndex : count.Value; if (line is CollapsedVisualTextLine) { var charInfos = Enumerable.Range(startIndex, substringLength).Select(index => line.GetCharInfoAt(index)); if (charInfos.Any(info => !info.IsCharacter)) { return GetPartialLineBeforeCollapse(charInfos, line, startIndex, substringLength); } else { return GetPartialLineAfterCollapse(line, startIndex, substringLength); } } else { return CutStandardLine(line, startIndex, substringLength); } }
private int[] GetCollapseSelectionRange(TextPosition clickPosition, VisualTextLine activeLine, int lineLength) { var startColumn = clickPosition.Column; var endColumn = clickPosition.Column; if (endColumn + 1 <= lineLength) { endColumn += 1; } else { startColumn -= 1; } // move left from current position for (var i = clickPosition.Column; i >= 0; i--) { var charInfo = activeLine.GetCharInfoAt(i); if (!charInfo.IsCharacter && !char.IsLetterOrDigit(charInfo.Text[0])) { startColumn = i; } else { break; } } // move right from current position for (var i = clickPosition.Column; i < lineLength; i++) { var charInfo = activeLine.GetCharInfoAt(i); if (!charInfo.IsCharacter && !char.IsLetterOrDigit(charInfo.Text[0])) { endColumn = i + 1; } else { break; } } return new[] { startColumn, endColumn }; }