本文整理汇总了C#中Mono.TextEditor.Document.OffsetToLineNumber方法的典型用法代码示例。如果您正苦于以下问题:C# Document.OffsetToLineNumber方法的具体用法?C# Document.OffsetToLineNumber怎么用?C# Document.OffsetToLineNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.TextEditor.Document
的用法示例。
在下文中一共展示了Document.OffsetToLineNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindPrevWordOffset
int FindPrevWordOffset (Document doc, int offset, bool subword)
{
int lineNumber = doc.OffsetToLineNumber (offset);
LineSegment line = doc.GetLine (lineNumber);
if (line == null)
return offset;
int result = offset;
if (result == line.Offset) {
line = doc.GetLine (lineNumber - 1);
if (line != null)
result = line.Offset + line.EditableLength;
return result;
}
CharacterClass current = GetCharacterClass (doc.GetCharAt (result - 1), subword, false);
if (current == CharacterClass.Whitespace && result - 1 > line.Offset) {
result--;
current = GetCharacterClass (doc.GetCharAt (result - 2), subword, false);
}
while (result > line.Offset) {
CharacterClass prev = GetCharacterClass (doc.GetCharAt (result - 1), subword, false);
if (prev != current) {
// camelCase and PascalCase handling
bool camelSkip = false;
if (prev == CharacterClass.UppercaseLetter && current == CharacterClass.LowercaseLetter) {
if (result-2 > line.Offset) {
CharacterClass back2 = GetCharacterClass (doc.GetCharAt (result-2), subword, false);
if (back2 == CharacterClass.UppercaseLetter)
result--;
else
camelSkip = true;
}
}
if (!camelSkip)
break;
}
current = prev;
result--;
}
return result;
}
示例2: FindNextWordOffset
int FindNextWordOffset (Document doc, int offset, bool subword)
{
int lineNumber = doc.OffsetToLineNumber (offset);
LineSegment line = doc.GetLine (lineNumber);
if (line == null)
return offset;
int result = offset;
int endOffset = line.Offset + line.EditableLength;
if (result == endOffset) {
line = doc.GetLine (lineNumber + 1);
if (line != null)
result = line.Offset;
return result;
}
CharacterClass current = GetCharacterClass (doc.GetCharAt (result), subword, false);
while (result < endOffset) {
CharacterClass next = GetCharacterClass (doc.GetCharAt (result), subword, false);
if (next != current) {
// camelCase and PascalCase handling
bool camelSkip = false;
if (next == CharacterClass.LowercaseLetter && current == CharacterClass.UppercaseLetter) {
if (result-2 > line.Offset) {
CharacterClass previous = GetCharacterClass (doc.GetCharAt (result-2), subword, false);
if (previous == CharacterClass.UppercaseLetter && result-2 > offset)
result--;
else
camelSkip = true;
}
}
if (!camelSkip)
break;
}
current = next;
result++;
}
while (result < endOffset && GetCharacterClass (doc.GetCharAt (result), subword, false) == CharacterClass.Whitespace) {
result++;
}
return result;
}
示例3: GenerateRtf
static string GenerateRtf (Document doc, Mono.TextEditor.Highlighting.SyntaxMode mode, Mono.TextEditor.Highlighting.Style style, ITextEditorOptions options)
{
StringBuilder rtfText = new StringBuilder ();
List<Gdk.Color> colorList = new List<Gdk.Color> ();
ISegment selection = new Segment (0, doc.Length);
int startLineNumber = doc.OffsetToLineNumber (selection.Offset);
int endLineNumber = doc.OffsetToLineNumber (selection.EndOffset);
bool isItalic = false;
bool isBold = false;
int curColor = -1;
foreach (var line in doc.GetLinesBetween (startLineNumber, endLineNumber)) {
bool appendSpace = false;
for (Chunk chunk = mode.GetChunks (doc, style, line, line.Offset, line.EditableLength); chunk != null; chunk = chunk.Next) {
int start = System.Math.Max (selection.Offset, chunk.Offset);
int end = System.Math.Min (chunk.EndOffset, selection.EndOffset);
ChunkStyle chunkStyle = chunk.GetChunkStyle (style);
if (start < end) {
if (isBold != chunkStyle.Bold) {
rtfText.Append (chunkStyle.Bold ? @"\b" : @"\b0");
isBold = chunkStyle.Bold;
appendSpace = true;
}
if (isItalic != chunkStyle.Italic) {
rtfText.Append (chunkStyle.Italic ? @"\i" : @"\i0");
isItalic = chunkStyle.Italic;
appendSpace = true;
}
if (!colorList.Contains (chunkStyle.Color))
colorList.Add (chunkStyle.Color);
int color = colorList.IndexOf (chunkStyle.Color);
if (curColor != color) {
curColor = color;
rtfText.Append (@"\cf" + (curColor + 1));
appendSpace = true;
}
for (int i = start; i < end; i++) {
char ch = chunk.GetCharAt (doc, i);
switch (ch) {
case '\\':
rtfText.Append (@"\\");
break;
case '{':
rtfText.Append (@"\{");
break;
case '}':
rtfText.Append (@"\}");
break;
case '\t':
rtfText.Append (@"\tab");
appendSpace = true;
break;
default:
if (appendSpace) {
rtfText.Append (' ');
appendSpace = false;
}
rtfText.Append (ch);
break;
}
}
}
}
rtfText.Append (@"\par");
rtfText.AppendLine ();
}
// color table
StringBuilder colorTable = new StringBuilder ();
colorTable.Append (@"{\colortbl ;");
for (int i = 0; i < colorList.Count; i++) {
Gdk.Color color = colorList[i];
colorTable.Append (@"\red");
colorTable.Append (color.Red / 256);
colorTable.Append (@"\green");
colorTable.Append (color.Green / 256);
colorTable.Append (@"\blue");
colorTable.Append (color.Blue / 256);
colorTable.Append (";");
}
colorTable.Append ("}");
StringBuilder rtf = new StringBuilder();
rtf.Append (@"{\rtf1\ansi\deff0\adeflang1025");
// font table
rtf.Append (@"{\fonttbl");
rtf.Append (@"{\f0\fnil\fprq1\fcharset128 " + options.Font.Family + ";}");
rtf.Append ("}");
rtf.Append (colorTable.ToString ());
rtf.Append (@"\viewkind4\uc1\pard");
rtf.Append (@"\f0");
try {
string fontName = options.Font.ToString ();
double fontSize = Double.Parse (fontName.Substring (fontName.LastIndexOf (' ') + 1), System.Globalization.CultureInfo.InvariantCulture) * 2;
rtf.Append (@"\fs");
//.........这里部分代码省略.........