public GetLineByNumber ( int number ) : |
||
number | int | |
return |
void CheckLines() { string text = document.Text; int lineNumber = 1; int lineStart = 0; for (int i = 0; i < text.Length; i++) { char c = text[i]; if (c == '\r' && i + 1 < text.Length && text[i + 1] == '\n') { DocumentLine line = document.GetLineByNumber(lineNumber); Assert.AreEqual(lineNumber, line.LineNumber); Assert.AreEqual(2, line.DelimiterLength); Assert.AreEqual(lineStart, line.Offset); Assert.AreEqual(i - lineStart, line.Length); i++; // consume \n lineNumber++; lineStart = i + 1; } else if (c == '\r' || c == '\n') { DocumentLine line = document.GetLineByNumber(lineNumber); Assert.AreEqual(lineNumber, line.LineNumber); Assert.AreEqual(1, line.DelimiterLength); Assert.AreEqual(lineStart, line.Offset); Assert.AreEqual(i - lineStart, line.Length); lineNumber++; lineStart = i + 1; } } Assert.AreEqual(lineNumber, document.LineCount); }
/// <summary> /// Creates a new <see cref="FixedHighlighter"/> for a copy of a portion /// of the input document (including the original highlighting). /// </summary> public static FixedHighlighter CreateView(IHighlighter highlighter, int offset, int endOffset) { var oldDocument = highlighter.Document; // ReadOnlyDocument would be better; but displaying the view in AvalonEdit // requires a TextDocument var newDocument = new TextDocument(oldDocument.CreateSnapshot(offset, endOffset - offset)); var oldStartLine = oldDocument.GetLineByOffset(offset); var oldEndLine = oldDocument.GetLineByOffset(endOffset); int oldStartLineNumber = oldStartLine.LineNumber; HighlightedLine[] newLines = new HighlightedLine[oldEndLine.LineNumber - oldStartLineNumber + 1]; highlighter.BeginHighlighting(); try { for (int i = 0; i < newLines.Length; i++) { HighlightedLine oldHighlightedLine = highlighter.HighlightLine(oldStartLineNumber + i); IDocumentLine newLine = newDocument.GetLineByNumber(1 + i); HighlightedLine newHighlightedLine = new HighlightedLine(newDocument, newLine); MoveSections(oldHighlightedLine.Sections, -offset, newLine.Offset, newLine.EndOffset, newHighlightedLine.Sections); newHighlightedLine.ValidateInvariants(); newLines[i] = newHighlightedLine; } } finally { highlighter.EndHighlighting(); } return new FixedHighlighter(newDocument, newLines); }
public ClassMemberBookmark(IMember member, TextDocument document) { this.member = member; int lineNr = member.Region.BeginLine; if (document != null && lineNr > 0 && lineNr <= document.LineCount) this.line = document.GetLineByNumber(lineNr); }
/// <summary> /// Gets the first offset >= startOffset where the generator wants to construct /// an element. /// Return -1 to signal no interest. /// </summary> public override int GetFirstInterestedOffset(int startOffset) { if (LineOfInterest <= 0) { return(-1); } ICSharpCode.AvalonEdit.Document.TextDocument document = CurrentContext.Document; int start = document.GetLineByNumber(LineOfInterest).Offset; // int length = document.GetLineByOffset(startOffset).Length; // string text = document.Text.Substring(start, length); if (start == startOffset) { return(start); } else { // DocumentLine nextLine = document.GetLineByOffset(startOffset).NextLine; // if (nextLine == null) return(-1); // return nextLine.Offset; } //int firstOffset = CurrentContext.VisualLine.FirstDocumentLine.Offset; ////Match m = FindMatch(startOffset); //if (firstOffset >= startOffset) // return firstOffset; //else return -1; }
/// <summary> /// Reindents a set of lines. /// </summary> /// <param name="document"></param> /// <param name="beginLine"></param> /// <param name="endLine"></param> public void IndentLines(TextDocument document, int beginLine, int endLine) { for (var i = beginLine; i <= endLine; i++) { IndentLine(document, document.GetLineByNumber(i)); } }
/// <summary> /// Gets the line terminator for the document around the specified line number. /// </summary> /// <param name="document">The document.</param> /// <param name="lineNumber">The line number.</param> /// <returns>The line terminator.</returns> internal static string GetLineTerminator(TextDocument document, int lineNumber) { DocumentLine line = document.GetLineByNumber(lineNumber); if (line.DelimiterLength == 0) { // at the end of the document, there's no line delimiter, so use the delimiter // from the previous line if (lineNumber == 1) { return(Environment.NewLine); } line = document.GetLineByNumber(lineNumber - 1); } return(document.GetText(line.Offset + line.Length, line.DelimiterLength)); }
public void IndentLines(TextDocument document, int beginLine, int endLine) { _doBeginUpdateManually = true; document.BeginUpdate(); while (beginLine <= endLine) { IndentLine(document, document.GetLineByNumber(beginLine)); beginLine++; } document.EndUpdate(); _doBeginUpdateManually = false; }
public override IEnumerable<NewFolding> CreateNewFoldings(TextDocument document, out int firstErrorOffset) { firstErrorOffset = -1; var folds = new List<NewFolding>(); linenr = 1; prev = false; startfold = 0; endfold = 0; n = 0; var l = document.GetLineByNumber(linenr); int sep = 0; do { int N = l.TotalLength; var line = document.GetText(n, N); var M = r.Match(line); if (M.Success) { if (!prev) { prev = true; startfold = n; } endfold = n + l.Length; } else { if (prev) folds.Add(lastfold=new NewFolding{ StartOffset=startfold, EndOffset= endfold, Name="FileSync Complete", DefaultClosed=true}); prev = false; } linenr++; n += N; } while ((l = l.NextLine) != null); return folds; }
/// <summary> /// Gets the newline sequence used in the document at the specified line. /// </summary> public static string GetNewLineFromDocument(TextDocument document, int lineNumber) { DocumentLine line = document.GetLineByNumber(lineNumber); if (line.DelimiterLength == 0) { // at the end of the document, there's no line delimiter, so use the delimiter // from the previous line line = line.PreviousLine; if (line == null) { return(Environment.NewLine); } } return(document.GetText(line.Offset + line.Length, line.DelimiterLength)); }
public void TestHeightChanged() { heightTree.SetHeight(document.GetLineByNumber(4), 100); CheckHeights(); }
public static HighlightedInlineBuilder CreateInlineBuilder(Location startPosition, Location endPosition, TextDocument document, ISyntaxHighlighter highlighter) { if (startPosition.Line >= 1 && startPosition.Line <= document.LineCount) { HighlightedInlineBuilder inlineBuilder; if (highlighter != null) { inlineBuilder = highlighter.BuildInlines(startPosition.Line); } else { inlineBuilder = new HighlightedInlineBuilder(document.GetText(document.GetLineByNumber(startPosition.Line))); } // now highlight the match in bold if (startPosition.Column >= 1) { if (endPosition.Line == startPosition.Line && endPosition.Column > startPosition.Column) { // subtract one from the column to get the offset inside the line's text int startOffset = startPosition.Column - 1; int endOffset = Math.Min(inlineBuilder.Text.Length, endPosition.Column - 1); inlineBuilder.SetFontWeight(startOffset, endOffset - startOffset, FontWeights.Bold); } } return inlineBuilder; } return null; }
/// <summary> /// Determines whether a line of a document is empty (no characters or whitespace). /// </summary> /// <param name="document">The document.</param> /// <param name="lineNumber">The line number.</param> /// <returns> /// <see langword="true"/> if line is empty of filled with whitespace; otherwise, /// <see langword="false"/>. /// </returns> internal static bool IsEmptyLine(TextDocument document, int lineNumber) { return IsEmptyLine(document, document.GetLineByNumber(lineNumber)); }
public void CheckGetLineInEmptyDocument() { Assert.AreEqual(1, document.Lines.Count); List <DocumentLine> lines = new List <DocumentLine>(document.Lines); Assert.AreEqual(1, lines.Count); DocumentLine line = document.Lines[0]; Assert.AreSame(line, lines[0]); Assert.AreSame(line, document.GetLineByNumber(1)); Assert.AreSame(line, document.GetLineByOffset(0)); }
public LineMarker(TextMarkerService svc, TextDocument doc, int beginLine, int endLine) { TextMarkerService = svc; StartOffset = doc.GetOffset(beginLine, 0); Length = doc.GetLineByNumber(endLine).EndOffset - StartOffset; }
/// <summary> /// Gets the newline sequence used in the document at the specified line. /// </summary> public static string GetNewLineFromDocument(TextDocument document, int lineNumber) { DocumentLine line = document.GetLineByNumber(lineNumber); if (line.DelimiterLength == 0) { // at the end of the document, there's no line delimiter, so use the delimiter // from the previous line line = line.PreviousLine; if (line == null) return Environment.NewLine; } return document.GetText(line.Offset + line.Length, line.DelimiterLength); }
CollapsedLineSection SimpleCheck(int from, int to) { CollapsedLineSection sec1 = heightTree.CollapseText(document.GetLineByNumber(from), document.GetLineByNumber(to)); for (int i = 1; i < from; i++) { Assert.IsFalse(heightTree.GetIsCollapsed(i)); } for (int i = from; i <= to; i++) { Assert.IsTrue(heightTree.GetIsCollapsed(i)); } for (int i = to + 1; i <= 10; i++) { Assert.IsFalse(heightTree.GetIsCollapsed(i)); } CheckHeights(); return(sec1); }
/// <summary> /// Determines whether a line of a document is empty (no characters or whitespace). /// </summary> /// <param name="document">The document.</param> /// <param name="lineNumber">The line number.</param> /// <returns> /// <see langword="true"/> if line is empty of filled with whitespace; otherwise, /// <see langword="false"/>. /// </returns> internal static bool IsEmptyLine(TextDocument document, int lineNumber) { return(IsEmptyLine(document, document.GetLineByNumber(lineNumber))); }
/// <summary> /// Gets the line of the document as <see cref="string"/>. /// </summary> /// <param name="document">The document.</param> /// <param name="lineNumber">The line number.</param> /// <returns>The line as <see cref="string"/>.</returns> internal static string GetLineAsString(this TextDocument document, int lineNumber) { var line = document.GetLineByNumber(lineNumber); return(document.GetText(line)); }
public ClassBookmark(IClass @class, TextDocument document) { this.@class = @class; int lineNr = @class.Region.BeginLine; if (document != null && lineNr > 0 && lineNr <= document.LineCount) this.line = document.GetLineByNumber(lineNr); }
/// <summary> /// Gets the line terminator for the document around the specified line number. /// </summary> /// <param name="document">The document.</param> /// <param name="lineNumber">The line number.</param> /// <returns>The line terminator.</returns> internal static string GetLineTerminator(TextDocument document, int lineNumber) { DocumentLine line = document.GetLineByNumber(lineNumber); if (line.DelimiterLength == 0) { // at the end of the document, there's no line delimiter, so use the delimiter // from the previous line if (lineNumber == 1) return Environment.NewLine; line = document.GetLineByNumber(lineNumber - 1); } return document.GetText(line.Offset + line.Length, line.DelimiterLength); }
/// <summary> /// Gets the document line with the specified index /// (first line at index 0) /// </summary> public ITextLine GetLineByIndex(int lineIndex) { IDocumentLine documentLine = _avalonEditTextDocument.GetLineByNumber(lineIndex + 1); return(BuildTextLineFromDocumentLine(documentLine)); }
public static HighlightedInlineBuilder CreateInlineBuilder(Location startPosition, Location endPosition, TextDocument document, IHighlighter highlighter) { if (startPosition.Line >= 1 && startPosition.Line <= document.LineCount) { var matchedLine = document.GetLineByNumber(startPosition.Line); HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(matchedLine)); if (highlighter != null) { HighlightedLine highlightedLine = highlighter.HighlightLine(startPosition.Line); int startOffset = highlightedLine.DocumentLine.Offset; // copy only the foreground color foreach (HighlightedSection section in highlightedLine.Sections) { if (section.Color.Foreground != null) { inlineBuilder.SetForeground(section.Offset - startOffset, section.Length, section.Color.Foreground.GetBrush(null)); } } } // now highlight the match in bold if (startPosition.Column >= 1) { if (endPosition.Line == startPosition.Line && endPosition.Column > startPosition.Column) { // subtract one from the column to get the offset inside the line's text int startOffset = startPosition.Column - 1; int endOffset = Math.Min(inlineBuilder.Text.Length, endPosition.Column - 1); inlineBuilder.SetFontWeight(startOffset, endOffset - startOffset, FontWeights.Bold); } } return inlineBuilder; } return null; }