/// <summary> /// Returns the first non-whitespace position on the given line, or null if /// the line is empty or contains only whitespace. /// </summary> public static int?GetFirstNonWhitespacePosition(this TextLine line) { var firstNonWhitespaceOffset = line.GetFirstNonWhitespaceOffset(); return(firstNonWhitespaceOffset.HasValue ? firstNonWhitespaceOffset + line.Start : null); }
private int GetIndentationOffsetFromLine(FormattingContext context, TextLine line) { var offset = line.GetFirstNonWhitespaceOffset() ?? 0; if (!context.Options.InsertSpaces) { // Normalize to spaces because the rest of the formatting pipeline operates based on the assumption. offset *= (int)context.Options.TabSize; } return(offset); }
private void InsertExteriorTrivia(ITextView view, ITextBuffer subjectBuffer, DocumentOptionSet options, TextLine currentLine, TextLine previousLine) { var insertionText = CreateInsertionTextFromPreviousLine(previousLine, options); var firstNonWhitespaceOffset = currentLine.GetFirstNonWhitespaceOffset(); var replaceSpan = firstNonWhitespaceOffset != null ? TextSpan.FromBounds(currentLine.Start, currentLine.Start + firstNonWhitespaceOffset.Value) : currentLine.Span; subjectBuffer.Replace(replaceSpan.ToSpan(), insertionText); view.TryMoveCaretToAndEnsureVisible(subjectBuffer.CurrentSnapshot.GetPoint(replaceSpan.Start + insertionText.Length)); }