本文整理汇总了C#中Mono.TextEditor.TextDocument.GetLineByOffset方法的典型用法代码示例。如果您正苦于以下问题:C# TextDocument.GetLineByOffset方法的具体用法?C# TextDocument.GetLineByOffset怎么用?C# TextDocument.GetLineByOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.TextEditor.TextDocument
的用法示例。
在下文中一共展示了TextDocument.GetLineByOffset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScanWord
static int ScanWord (TextDocument doc, int offset, bool forwardDirection)
{
if (offset < 0 || offset >= doc.TextLength)
return offset;
var line = doc.GetLineByOffset (offset);
char first = doc.GetCharAt (offset);
if (char.IsPunctuation (first))
return forwardDirection ? System.Math.Min (line.Offset + line.Length, offset + 1) : System.Math.Max (line.Offset, offset - 1);
while (offset >= line.Offset && offset < line.Offset + line.Length) {
char ch = doc.GetCharAt (offset);
if (char.IsWhiteSpace (first) && !char.IsWhiteSpace (ch)
|| WordFindStrategy.IsNoIdentifierPart (first) && !WordFindStrategy.IsNoIdentifierPart (ch)
|| (char.IsLetterOrDigit (first) || first == '_') && !(char.IsLetterOrDigit (ch) || ch == '_'))
break;
offset = forwardDirection ? offset + 1 : offset - 1;
}
return System.Math.Min (line.Offset + line.Length,
System.Math.Max (line.Offset, offset + (forwardDirection ? 0 : 1)));
}
示例2: StartsInLineComment
bool StartsInLineComment (TextDocument document, int offset)
{
List<string> lineComments = GetList (document, "LineComment");
DocumentLine line = document.GetLineByOffset (offset);
for (int i = line.Offset ; i < offset; i++) {
if (StartsWithListMember (document, lineComments, i) >= 0)
return true;
}
return false;
}
示例3: GetLastSourceCodePosition
int GetLastSourceCodePosition (TextDocument document, int lineOffset)
{
DocumentLine line = document.GetLineByOffset (lineOffset);
if (line == null)
return lineOffset;
bool isInBlockComment = false;
bool isInLineComment = false;
int curStringQuote = -1;
List<string> lineComments = GetList (document, "LineComment");
List<string> blockCommentStarts = GetList (document, "BlockCommentStart");
List<string> blockCommentEnds = GetList (document, "BlockCommentEnd");
List<string> stringQuotes = GetList (document, "StringQuote");
for (int i = 0 ; i < line.Length; i++) {
int offset = line.Offset + i;
// check line comments
if (!isInBlockComment && curStringQuote < 0) {
isInLineComment = StartsWithListMember (document, lineComments, offset) >= 0;
if (isInLineComment)
return System.Math.Min (offset, lineOffset);
}
// check block comments
if (!isInLineComment && curStringQuote < 0) {
if (!isInBlockComment) {
isInBlockComment = StartsWithListMember (document, blockCommentStarts, offset) >= 0;
} else {
isInBlockComment = StartsWithListMember (document, blockCommentEnds, offset) < 0;
}
}
if (!isInBlockComment && !isInLineComment) {
int j = StartsWithListMember (document, stringQuotes, offset);
if (j >= 0) {
if (curStringQuote >= 0) {
if (curStringQuote == j)
curStringQuote = -1;
} else {
curStringQuote = j;
}
}
}
}
return lineOffset;
}
示例4: Conflicts
// todo: move to version control backend
static IEnumerable<Conflict> Conflicts (TextDocument doc)
{
int mergeStart = 0;
while ((mergeStart = doc.IndexOf ("<<<<<<<", mergeStart, doc.TextLength - mergeStart, StringComparison.Ordinal)) >= 0) {
DocumentLine start = doc.GetLineByOffset (mergeStart);
if (start.Offset != mergeStart)
continue;
int dividerOffset = doc.IndexOf ("=======", mergeStart, doc.TextLength - mergeStart, StringComparison.Ordinal);
DocumentLine divider = doc.GetLineByOffset (dividerOffset);
int endOffset = doc.IndexOf (">>>>>>>", dividerOffset, doc.TextLength - dividerOffset, StringComparison.Ordinal);
DocumentLine end = doc.GetLineByOffset (endOffset);
mergeStart = dividerOffset + 1;
yield return new Conflict (new TextSegment (start.EndOffsetIncludingDelimiter, divider.Offset - start.EndOffsetIncludingDelimiter),
new TextSegment (divider.EndOffsetIncludingDelimiter, end.Offset - divider.EndOffsetIncludingDelimiter),
start,
divider,
end);
}
}