本文整理汇总了C#中ICSharpCode.AvalonEdit.TextEditor.EndChange方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor.EndChange方法的具体用法?C# TextEditor.EndChange怎么用?C# TextEditor.EndChange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.AvalonEdit.TextEditor
的用法示例。
在下文中一共展示了TextEditor.EndChange方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertSelectionToList
public static void ConvertSelectionToList(TextEditor textEditor)
{
var selection = textEditor.TextArea.Selection;
var start = Math.Min(selection.StartPosition.Line, selection.EndPosition.Line);
if (start == 0) return;
var end = Math.Max(selection.StartPosition.Line, selection.EndPosition.Line);
var document = textEditor.Document;
var ordered = new Regex(@"^\s*\d+\.\s{1,4}");
var unordered = new Regex(@"^\s*[-|\*|\+]\s{1,4}");
textEditor.BeginChange();
var index = 1;
try
{
foreach (var num in Enumerable.Range(start, end - start + 1))
{
var line = document.GetLineByNumber(num);
var offset = line.Offset;
var text = document.GetText(line);
if (string.IsNullOrWhiteSpace(text)) continue;
if (unordered.IsMatch(text))
{
var numbered = Regex.Replace(text, @"[-|\*|\+]", $"{index++}.");
document.Remove(line);
document.Insert(offset, numbered);
}
else if (ordered.IsMatch(text))
{
var unnumbered = Regex.Replace(text, @"\d+\.", "-");
document.Remove(line);
document.Insert(offset, unnumbered);
}
else
{
var indexOfFirstChar = text.TakeWhile(char.IsWhiteSpace).Count();
document.Insert(line.Offset + indexOfFirstChar, "- ");
}
}
}
finally
{
textEditor.EndChange();
}
}
示例2: MoveSegmentUp
public static void MoveSegmentUp(TextEditor textEditor)
{
var textArea = textEditor.TextArea;
var document = textEditor.Document;
int currentLine;
DocumentLine segment;
var selection = textArea.Selection;
if (selection != null && selection.StartPosition.Line > 1)
{
currentLine = Math.Max(selection.StartPosition.Line, selection.EndPosition.Line);
segment = document.GetLineByNumber(Math.Min(selection.StartPosition.Line, selection.EndPosition.Line)).PreviousLine;
}
else
{
currentLine = textArea.Caret.Line;
if (currentLine == 1) return;
segment = document.GetLineByNumber(currentLine).PreviousLine;
}
textEditor.BeginChange();
try
{
var text = document.GetText(segment.Offset, segment.TotalLength);
document.Remove(segment.Offset, segment.TotalLength);
var offset = currentLine >= document.LineCount
? document.TextLength
: document.GetOffset(currentLine, 0);
document.Insert(offset, text);
textArea.Caret.Line = currentLine - 1;
textArea.Caret.BringCaretToView();
}
finally
{
textEditor.EndChange();
textArea.TextView.Redraw(DispatcherPriority.ApplicationIdle);
}
}
示例3: InsertBlockQuote
public static void InsertBlockQuote(TextEditor textEditor)
{
var textArea = textEditor.TextArea;
var document = textEditor.Document;
var selection = textEditor.TextArea.Selection;
var start = Math.Min(selection.StartPosition.Line, selection.EndPosition.Line);
if (start == 0) start = textArea.Caret.Line;
var end = Math.Max(selection.StartPosition.Line, selection.EndPosition.Line);
if (end == 0) end = textArea.Caret.Line;
textEditor.BeginChange();
try
{
foreach (var line in Enumerable.Range(start, end - start + 1))
{
var offset = document.GetOffset(line, 0);
document.Insert(offset, "> ");
}
}
finally
{
textEditor.EndChange();
}
}