本文整理汇总了C#中IDocument.GetLineByOffset方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.GetLineByOffset方法的具体用法?C# IDocument.GetLineByOffset怎么用?C# IDocument.GetLineByOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.GetLineByOffset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAlignedText
public static string GetAlignedText(IDocument document, int startOffset, int endOffset, int maxLineCount = 15)
{
// This fixes SD-1394:
// Each line is checked for leading indentation whitespaces. If
// a line has the same or more indentation than the first line,
// it is reduced. If a line is less indented than the first line
// the indentation is removed completely.
//
// See the following example:
// line 1
// line 2
// line 3
// line 4
//
// is reduced to:
// line 1
// line 2
// line 3
// line 4
if (maxLineCount < 1)
maxLineCount = int.MaxValue;
IDocumentLine startLine = document.GetLineByOffset(startOffset);
IDocumentLine endLine = document.GetLineByOffset(endOffset);
StringBuilder builder = new StringBuilder();
IDocumentLine current = startLine;
ISegment startIndent = TextUtilities.GetWhitespaceAfter(document, startLine.Offset);
int lineCount = 0;
while (current != endLine.NextLine && lineCount < maxLineCount) {
ISegment currentIndent = TextUtilities.GetWhitespaceAfter(document, current.Offset);
if (current == startLine && current == endLine)
builder.Append(document.GetText(startOffset, endOffset - startOffset));
else if (current == startLine) {
if (current.EndOffset - startOffset > 0)
builder.AppendLine(document.GetText(startOffset, current.EndOffset - startOffset).TrimStart());
} else if (current == endLine) {
if (startIndent.Length <= currentIndent.Length)
builder.Append(document.GetText(current.Offset + startIndent.Length, endOffset - current.Offset - startIndent.Length));
else
builder.Append(document.GetText(current.Offset + currentIndent.Length, endOffset - current.Offset - currentIndent.Length));
} else {
if (startIndent.Length <= currentIndent.Length)
builder.AppendLine(document.GetText(current.Offset + startIndent.Length, current.Length - startIndent.Length));
else
builder.AppendLine(document.GetText(current.Offset + currentIndent.Length, current.Length - currentIndent.Length));
}
current = current.NextLine;
lineCount++;
}
if (current != endLine.NextLine)
builder.Append("...");
return builder.ToString();
}
示例2: CreateHtmlFragment
/// <summary>
/// Creates a HTML fragment from a part of a document.
/// </summary>
/// <param name="document">The document to create HTML from.</param>
/// <param name="highlighter">The highlighter used to highlight the document. <c>null</c> is valid and will create HTML without any highlighting.</param>
/// <param name="segment">The part of the document to create HTML for. You can pass <c>null</c> to create HTML for the whole document.</param>
/// <param name="options">The options for the HTML creation.</param>
/// <returns>HTML code for the document part.</returns>
public static string CreateHtmlFragment(IDocument document, IHighlighter highlighter, ISegment segment, HtmlOptions options)
{
if (document == null)
throw new ArgumentNullException("document");
if (options == null)
throw new ArgumentNullException("options");
if (highlighter != null && highlighter.Document != document)
throw new ArgumentException("Highlighter does not belong to the specified document.");
if (segment == null)
segment = new SimpleSegment(0, document.TextLength);
StringBuilder html = new StringBuilder();
int segmentEndOffset = segment.EndOffset;
IDocumentLine line = document.GetLineByOffset(segment.Offset);
while (line != null && line.Offset < segmentEndOffset) {
HighlightedLine highlightedLine;
if (highlighter != null)
highlightedLine = highlighter.HighlightLine(line.LineNumber);
else
highlightedLine = new HighlightedLine(document, line);
SimpleSegment s = SimpleSegment.GetOverlap(segment, line);
if (html.Length > 0)
html.AppendLine("<br>");
html.Append(highlightedLine.ToHtml(s.Offset, s.EndOffset, options));
line = line.NextLine;
}
return html.ToString();
}
示例3: DocumentTextWriter
/// <summary>
/// Creates a new DocumentTextWriter that inserts into document, starting at insertionOffset.
/// </summary>
public DocumentTextWriter(IDocument document, int insertionOffset)
{
this.insertionOffset = insertionOffset;
if (document == null)
throw new ArgumentNullException("document");
this.document = document;
var line = document.GetLineByOffset(insertionOffset);
if (line.DelimiterLength == 0)
line = line.PreviousLine;
if (line != null)
this.NewLine = document.GetText(line.EndOffset, line.DelimiterLength);
}
示例4: SearchDefinition
void SearchDefinition(IDocument document, BracketSearchResult result)
{
if (document.GetCharAt(result.OpeningBracketOffset) != '{')
return;
// get line
var documentLine = document.GetLineByOffset(result.OpeningBracketOffset);
while (documentLine != null && IsBracketOnly(document, documentLine))
documentLine = documentLine.PreviousLine;
if (documentLine != null) {
result.DefinitionHeaderOffset = documentLine.Offset;
result.DefinitionHeaderLength = documentLine.Length;
}
}
示例5: Insert
public int Insert (IDocument document, string text)
{
int offset = document.GetOffset (Location);
using (var undo = document.OpenUndoGroup ()) {
text = DocumentUtilities.NormalizeNewLines(text, document, Location.Line);
var line = document.GetLineByOffset (offset);
int insertionOffset = line.Offset + Location.Column - 1;
offset = insertionOffset;
InsertNewLine (document, LineBefore, ref offset);
document.Insert (offset, text);
offset += text.Length;
InsertNewLine (document, LineAfter, ref offset);
return offset;
}
}