当前位置: 首页>>代码示例>>C#>>正文


C# TextEditor.EndChange方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:nikolalukovic,项目名称:Markdown-Edit,代码行数:45,代码来源:EditorUtilities.cs

示例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);
            }
        }
开发者ID:nikolalukovic,项目名称:Markdown-Edit,代码行数:38,代码来源:EditorUtilities.cs

示例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();
            }
        }
开发者ID:nikolalukovic,项目名称:Markdown-Edit,代码行数:25,代码来源:EditorUtilities.cs


注:本文中的ICSharpCode.AvalonEdit.TextEditor.EndChange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。