本文整理汇总了C#中TextEditorData.SetSelection方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditorData.SetSelection方法的具体用法?C# TextEditorData.SetSelection怎么用?C# TextEditorData.SetSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextEditorData
的用法示例。
在下文中一共展示了TextEditorData.SetSelection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static TextEditorData Create (string content)
{
int caretIndex = content.IndexOf ("$");
if (caretIndex >= 0)
content = content.Substring (0, caretIndex) + content.Substring (caretIndex + 1);
int selection1 = content.IndexOf ("<-");
int selection2 = content.IndexOf ("->");
int selectionStart = 0;
int selectionEnd = 0;
if (0 <= selection1 && selection1 < selection2) {
content = content.Substring (0, selection2) + content.Substring (selection2 + 2);
content = content.Substring (0, selection1) + content.Substring (selection1 + 2);
selectionStart = selection1;
selectionEnd = selection2 - 2;
caretIndex = selectionEnd;
}
var data = new TextEditorData ();
data.Text = content;
if (caretIndex >= 0)
data.Caret.Offset = caretIndex;
if (selection1 >= 0) {
if (caretIndex == selectionStart) {
data.SetSelection (selectionEnd, selectionStart);
} else {
data.SetSelection (selectionStart, selectionEnd);
}
}
return data;
}
示例2: Create
public static TextEditorData Create (string content, ITextEditorOptions options = null)
{
var data = new TextEditorData ();
if (options != null)
data.Options = options;
var sb = new StringBuilder ();
int caretIndex = -1, selectionStart = -1, selectionEnd = -1;
var foldSegments = new List<FoldSegment> ();
var foldStack = new Stack<FoldSegment> ();
for (int i = 0; i < content.Length; i++) {
var ch = content [i];
switch (ch) {
case '$':
caretIndex = sb.Length;
break;
case '<':
if (i + 1 < content.Length) {
if (content [i + 1] == '-') {
selectionStart = sb.Length;
i++;
break;
}
}
goto default;
case '-':
if (i + 1 < content.Length) {
var next = content [i + 1];
if (next == '>') {
selectionEnd = sb.Length;
i++;
break;
}
if (next == '[') {
var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None);
segment.IsFolded = false;
foldStack.Push (segment);
i++;
break;
}
}
goto default;
case '+':
if (i + 1 < content.Length) {
var next = content [i + 1];
if (next == '[') {
var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None);
segment.IsFolded = true;
foldStack.Push (segment);
i++;
break;
}
}
goto default;
case ']':
if (foldStack.Count > 0) {
FoldSegment segment = foldStack.Pop ();
segment.Length = sb.Length - segment.Offset;
foldSegments.Add (segment);
break;
}
goto default;
default:
sb.Append (ch);
break;
}
}
data.Text = sb.ToString ();
if (caretIndex >= 0)
data.Caret.Offset = caretIndex;
if (selectionStart >= 0) {
if (caretIndex == selectionStart) {
data.SetSelection (selectionEnd, selectionStart);
} else {
data.SetSelection (selectionStart, selectionEnd);
}
}
if (foldSegments.Count > 0)
data.Document.UpdateFoldSegments (foldSegments);
return data;
}