public VisualTextLine CollapseTextRange(TextRange area, IReadOnlyList<string> lines, ICollapseRepresentation collapseRepresentationAlgorithm) { var precedingText = new string(lines[area.StartPosition.Line].Take(area.StartPosition.Column).ToArray()); var followingText = new string(lines[area.EndPosition.Line].Skip(area.EndPosition.Column + 1).ToArray()); var collapsedLineIndex = area.StartPosition.Line; var middlePart = new List<string>(); var start = area.StartPosition.Line; var end = area.EndPosition.Line; if (start != end) { for (var i = start; i <= end; i++) { var currentLine = lines[i]; if (i == start) { currentLine = string.Join("", currentLine.Skip(area.StartPosition.Column)); } else if (i == end) { currentLine = string.Join("", currentLine.Take(area.EndPosition.Column + 1)); } middlePart.Add(currentLine); } } else { middlePart.Add(string.Join("", lines[start].Skip(area.StartPosition.Column).Take((1 + area.EndPosition.Column) - area.StartPosition.Column))); } return VisualTextLine.Create(middlePart, precedingText, followingText, collapsedLineIndex, collapseRepresentationAlgorithm.GetCollapseRepresentation()); }
public ChangeInLinesInfo GetChangeInLines(IReadOnlyList<VisualTextLine> lines, TextRange range) { var orderedRanges = (new[] { range.StartPosition, range.EndPosition }).OrderBy(elem => elem.Line).ThenBy(elem => elem.Column).ToArray(); var pair = new TextRange { StartPosition = orderedRanges[0], EndPosition = orderedRanges[1] }; var rangeEnd = -1; if (pair.StartPosition.Line == pair.EndPosition.Line) { rangeEnd = pair.EndPosition.Line; } else { rangeEnd = pair.EndPosition.Line + 1; } var firstPart = Cut(lines[pair.StartPosition.Line], 0, pair.StartPosition.Column); var secondPart = Cut(lines[pair.EndPosition.Line], pair.EndPosition.Column); return new ChangeInLinesInfo { LinesToChange = new Dictionary<TextPosition, VisualTextLine> { [new TextPosition(pair.StartPosition.Column, pair.StartPosition.Line)] = VisualTextLine.MergeLines(new[] { firstPart, secondPart }, firstPart.Index) }, LinesToRemove = Enumerable.Range(pair.StartPosition.Line, rangeEnd).ToList() }; }
public IEnumerable<VisualTextLine> GetLinesToRedrawAfterCollapse(IReadOnlyList<VisualTextLine> visuals, VisualTextLine collapsedLine, TextRange range) { var linesToRedraw = new List<VisualTextLine>(); if (range.StartPosition.Line == range.EndPosition.Line) { return linesToRedraw; } var collapseEndLine = range.EndPosition.Line; for (int i = collapseEndLine + 1, newIndex = collapsedLine.Index + 1; i < visuals.Count; i++, newIndex++) { var line = visuals[i].CloneWithIndexChange(newIndex); linesToRedraw.Add(line); } return linesToRedraw; }
private bool IsFoldMultiline(TextRange range) => range.StartPosition.Line != range.EndPosition.Line;
private bool IsCaretInbetweenTags(TextRange range) => CaretPosition >= range.StartPosition && CaretPosition <= range.EndPosition;
private void SendMessage(FoldingStates state, FoldingPositionInfo folding) { var areaBeforeFolding = new TextRange(); var areaAfterFolding = new TextRange(); if (state == FoldingStates.FOLDED) { areaBeforeFolding.StartPosition = folding.Position; areaBeforeFolding.EndPosition = foldingPositions.First(pair => Equals(pair.Key, folding)).Value.Position; areaAfterFolding.StartPosition = folding.Position; areaAfterFolding.EndPosition = new TextPosition(column: folding.Position.Column + FoldingAlgorithm.GetCollapsibleRepresentation().Length, line: folding.Position.Line); } else { areaAfterFolding.StartPosition = folding.Position; areaAfterFolding.EndPosition = foldingPositions.First(pair => Equals(pair.Key, folding)).Value.Position; areaBeforeFolding.StartPosition = folding.Position; areaBeforeFolding.EndPosition = new TextPosition(column: folding.Position.Column + FoldingAlgorithm.GetCollapsibleRepresentation().Length, line: folding.Position.Line); } Postbox.Put(new FoldClickedMessage { AreaBeforeFolding = areaBeforeFolding, AreaAfterFolding = areaAfterFolding, ClosingTag = FoldingAlgorithm.GetClosingTag(), OpeningTag = FoldingAlgorithm.GetOpeningTag(), State = state }); }
public void RemoveText(TextRange range) { var removalInfo = removingAlgorithm.GetChangeInLines(GetVisualLines(), range); if (removalInfo.LinesToChange.Any()) { DeleteText(removalInfo); UpdateSize(); } }
public void ReplaceText(string enteredText, TextRange range) { RemoveText(range); InputText(enteredText); UpdateSize(); }
public IEnumerable<VisualTextLine> ExpandTextRange(TextRange area, IEnumerable<string> lines) => lines.Skip(area.StartPosition.Line).Take(1 + area.EndPosition.Line - area.StartPosition.Line).Select((line, index) => VisualTextLine.Create(line, area.StartPosition.Line + index));