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


C# TextDocument.Insert方法代码示例

本文整理汇总了C#中ICSharpCode.AvalonEdit.Document.TextDocument.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# TextDocument.Insert方法的具体用法?C# TextDocument.Insert怎么用?C# TextDocument.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.AvalonEdit.Document.TextDocument的用法示例。


在下文中一共展示了TextDocument.Insert方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ContinueUndoGroup

		public void ContinueUndoGroup()
		{
			var doc = new TextDocument();
			doc.Insert(0, "a");
			doc.UndoStack.StartContinuedUndoGroup();
			doc.Insert(1, "b");
			doc.UndoStack.EndUndoGroup();
			doc.UndoStack.Undo();
			Assert.AreEqual("", doc.Text);
		}
开发者ID:bbqchickenrobot,项目名称:AvalonEdit,代码行数:10,代码来源:UndoStackTests.cs

示例2: ContinueEmptyUndoGroup_WithOptionalEntries

		public void ContinueEmptyUndoGroup_WithOptionalEntries()
		{
			var doc = new TextDocument();
			doc.Insert(0, "a");
			doc.UndoStack.StartUndoGroup();
			doc.UndoStack.PushOptional(new StubUndoableAction());
			doc.UndoStack.EndUndoGroup();
			doc.UndoStack.StartContinuedUndoGroup();
			doc.Insert(1, "b");
			doc.UndoStack.EndUndoGroup();
			doc.UndoStack.Undo();
			Assert.AreEqual("a", doc.Text);
		}
开发者ID:bbqchickenrobot,项目名称:AvalonEdit,代码行数:13,代码来源:UndoStackTests.cs

示例3: IndentLine

        /// <inheritdoc cref="IIndentationStrategy.IndentLine"/>
        public override void IndentLine(TextDocument document, DocumentLine line)
        {
            if (line?.PreviousLine == null)
                return;

            var prevLine = document.GetText(line.PreviousLine.Offset, line.PreviousLine.Length);
            var curLine = document.GetText(line.Offset, line.Length);
            int prev = CalcSpace(prevLine);

            var previousIsComment = prevLine.TrimStart().StartsWith("--", StringComparison.CurrentCulture);

            if (Regex.IsMatch(curLine, patternFull) && !previousIsComment)
            {
                var ind = new string(' ', prev);
                document.Insert(line.Offset, ind);
            }
            else if (Regex.IsMatch(prevLine, patternStart) && !previousIsComment)
            {
                var ind = new string(' ', prev + indent_space_count);
                document.Insert(line.Offset, ind);

                var found = false;
                for (int i = line.LineNumber; i < document.LineCount; ++i)
                {
                    var text = document.GetText(document.Lines[i].Offset, document.Lines[i].Length);

                    if (string.IsNullOrWhiteSpace(text) || text.TrimStart().StartsWith("--", StringComparison.CurrentCulture))
                        continue;

                    var sps = CalcSpace(text);

                    if (sps == prev && Regex.IsMatch(text, patternEnd))
                        found = true;
                }

                if (!found)
                {
                    var ntext = Environment.NewLine + new string(' ', prev) + "end";
                    var point = textEditor.SelectionStart;
                    document.Insert(line.Offset + ind.Length, ntext);
                    textEditor.SelectionStart = point;
                }
            }
            else
            {
                var ind = new string(' ', prev);
                if (line != null)
                    document.Insert(line.Offset, ind);
            }
        }
开发者ID:Konctantin,项目名称:Yanitta,代码行数:51,代码来源:LuaIndentationStrategy.cs

示例4: IndentLine

        /// <inheritdoc cref="IIndentationStrategy.IndentLine"/>
        public override void IndentLine(TextDocument document, DocumentLine line)
        {
            if (line.PreviousLine == null)
                return;

            int prev = CalcSpace(line.PreviousLine.Text);

            var previousIsComment = line.PreviousLine.Text.TrimStart().StartsWith("--");

            if (Regex.IsMatch(line.Text, @"\b(?<start>function|while(.+)do|if(.+)then|elseif(.+)then|for(.+)do|{{|end|}})\b") && !previousIsComment)
            {
                var ind = new string(' ', prev);
                document.Insert(line.Offset, ind);
            }
            else if (Regex.IsMatch(line.PreviousLine.Text, @"\b(?<start>function|while(.+)do|if(.+)then|elseif(.+)then|for(.+)do|{{)\b") && !previousIsComment)
            {
                var ind = new string(' ', prev + indent_space_count);
                document.Insert(line.Offset, ind);

                var found = false;
                for (int i = line.LineNumber; i < document.LineCount; ++i)
                {
                    var text = document.Lines[i].Text;

                    if (string.IsNullOrWhiteSpace(text) || text.TrimStart().StartsWith("--"))
                        continue;

                    var sps = CalcSpace(text);

                    if (sps == prev && Regex.IsMatch(text, @"\b(?<start>end)\b"))
                        found = true;
                }

                if (!found)
                {
                    var ntext = Environment.NewLine + new string(' ', prev) + "end";
                    var point = textEditor.SelectionStart;
                    document.Insert(line.Offset + ind.Length, ntext);
                    textEditor.SelectionStart = point;
                }
            }
            else
            {
                var ind = new string(' ', prev);
                if (line != null)
                    document.Insert(line.Offset, ind);
            }
        }
开发者ID:arkanoid1,项目名称:FakePacketSender,代码行数:49,代码来源:LuaIndentationStrategy.cs

示例5: BackwardChanges

		public void BackwardChanges()
		{
			TextDocument document = new TextDocument("initial text");
			ITextSource snapshot1 = document.CreateSnapshot();
			document.Replace(0, 7, "nw");
			document.Insert(1, "e");
			ITextSource snapshot2 = document.CreateSnapshot();
			Assert.AreEqual(1, snapshot2.Version.CompareAge(snapshot1.Version));
			TextChangeEventArgs[] arr = snapshot2.Version.GetChangesTo(snapshot1.Version).ToArray();
			Assert.AreEqual(2, arr.Length);
			Assert.AreEqual("", arr[0].InsertedText.Text);
			Assert.AreEqual("initial", arr[1].InsertedText.Text);
			
			Assert.AreEqual("initial text", snapshot1.Text);
			Assert.AreEqual("new text", snapshot2.Text);
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:16,代码来源:ChangeTrackingTest.cs

示例6: BackwardChanges

		public void BackwardChanges()
		{
			TextDocument document = new TextDocument("initial text");
			ChangeTrackingCheckpoint checkpoint1, checkpoint2;
			ITextSource snapshot1 = document.CreateSnapshot(out checkpoint1);
			document.Replace(0, 7, "nw");
			document.Insert(1, "e");
			ITextSource snapshot2 = document.CreateSnapshot(out checkpoint2);
			Assert.AreEqual(1, checkpoint2.CompareAge(checkpoint1));
			DocumentChangeEventArgs[] arr = checkpoint2.GetChangesTo(checkpoint1).ToArray();
			Assert.AreEqual(2, arr.Length);
			Assert.AreEqual("", arr[0].InsertedText);
			Assert.AreEqual("initial", arr[1].InsertedText);
			
			Assert.AreEqual("initial text", snapshot1.Text);
			Assert.AreEqual("new text", snapshot2.Text);
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:17,代码来源:ChangeTrackingTest.cs

示例7: DocumentDoesNotHoldReferenceToTextView

		public void DocumentDoesNotHoldReferenceToTextView()
		{
			TextDocument textDocument = new TextDocument();
			Assert.AreEqual(0, textDocument.LineTrackers.Count);
			
			TextView textView = new TextView();
			WeakReference wr = new WeakReference(textView);
			textView.Document = textDocument;
			Assert.AreEqual(1, textDocument.LineTrackers.Count);
			textView = null;
			
			GarbageCollect();
			Assert.IsFalse(wr.IsAlive);
			// document cannot immediately clear the line tracker
			Assert.AreEqual(1, textDocument.LineTrackers.Count);
			
			// but it should clear it on the next change
			textDocument.Insert(0, "a");
			Assert.AreEqual(0, textDocument.LineTrackers.Count);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:20,代码来源:WeakReferenceTests.cs

示例8: InsertBold

        public void InsertBold(int start, int length, TextDocument document)
        {
            var chs = document.GetCharAt(start);
            var che = document.GetCharAt(start + length - 1);

            document.Insert(start + length - 1, che.ToString());
            document.Replace(start + length, 1, "]");   //trick to keep anchors

            document.Insert(start + 1, chs.ToString());
            document.Replace(start, 1, "["); //trick to keep anchors

            Blocks.Add(new TextBlockBold()
            {
                OriginallyLength = length + 2,
                OriginallyOffset = start,
                MyAnchor = new AnchorSegment(document, start, length + 2)
            });
        }
开发者ID:yetanothervan,项目名称:conspector,代码行数:18,代码来源:TextModel.cs

示例9: CommentAtBeginOfText

 private bool CommentAtBeginOfText(TextDocument document, DocumentLine documentLine)
 {
     var text = document.GetText(documentLine);
     if (string.IsNullOrEmpty(text))
     {
         return false;
     }
     if (!AllowMultipleComments && text.TrimStart(Whitespaces.ToArray()).StartsWith(commentMarker))
     {
         return false;
     }
     var num = documentLine.Offset;
     var text2 = text;
     var i = 0;
     while (i < text2.Length)
     {
         var letter = text2[i];
         if (IsWhitespace(letter))
         {
             num++;
             i++;
         }
         else
         {
             if (num >= documentLine.EndOffset)
             {
                 return false;
             }
             break;
         }
     }
     document.Insert(num, CommentMarker);
     return true;
 }
开发者ID:mookiejones,项目名称:miEditor,代码行数:34,代码来源:CodeCommenter.cs

示例10: CommentAtBeginOfLine

 private bool CommentAtBeginOfLine(TextDocument document, DocumentLine documentLine)
 {
     var text = document.GetText(documentLine).TrimStart(Whitespaces.ToArray());
     if (string.IsNullOrEmpty(text))
     {
         return false;
     }
     if (!AllowMultipleComments && text.StartsWith(CommentMarker))
     {
         return false;
     }
     document.Insert(documentLine.Offset, CommentMarker);
     return true;
 }
开发者ID:mookiejones,项目名称:miEditor,代码行数:14,代码来源:CodeCommenter.cs

示例11: IndentLine

 public override void IndentLine(TextDocument document, DocumentLine line)
 {
     base.IndentLine(document, line);
     if (document.GetText(line.PreviousLine).Trim().EndsWith("{"))
         document.Insert(line.Offset, _options.IndentationString);
 }
开发者ID:itsbth,项目名称:E2Edit,代码行数:6,代码来源:E2IndentationStrategy.cs

示例12: DocumentDoesNotHoldReferenceToTextView

        public void DocumentDoesNotHoldReferenceToTextView()
        {
            bool collectedTextView = false;
            TextDocument textDocument = new TextDocument();
            Assert.AreEqual(0, textDocument.LineTrackers.Count);

            TextView textView = new TextViewWithGCCallback(delegate { collectedTextView = true; });
            textView.Document = textDocument;
            Assert.AreEqual(1, textDocument.LineTrackers.Count);
            textView = null;

            GarbageCollect();
            Assert.IsTrue(collectedTextView);
            // document cannot immediately clear the line tracker
            Assert.AreEqual(1, textDocument.LineTrackers.Count);

            // but it should clear it on the next change
            textDocument.Insert(0, "a");
            Assert.AreEqual(0, textDocument.LineTrackers.Count);
        }
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:20,代码来源:WeakReferenceTests.cs

示例13: RawlyIndentLine

        public void RawlyIndentLine(int tabsToInsert, TextDocument document, DocumentLine line)
        {
            if (!_doBeginUpdateManually)
                document.BeginUpdate();
            /*
             * 1) Remove old indentation
             * 2) Insert new one
             */

            // 1)
            int prevInd = 0;
            int curOff = line.Offset;
            if (curOff < document.TextLength)
            {
                char curChar = '\0';
                while (curOff < document.TextLength && ((curChar = document.GetCharAt(curOff)) == ' ' || curChar == '\t'))
                {
                    prevInd++;
                    curOff++;
                }

                document.Remove(line.Offset, prevInd);
            }

            // 2)
            string indentString = "";
            for (int i = 0; i < tabsToInsert; i++)
                indentString += dEditor.Editor.Options.IndentationString;

            document.Insert(line.Offset, indentString);
            if (!_doBeginUpdateManually)
                document.EndUpdate();
        }
开发者ID:rumbu13,项目名称:D-IDE,代码行数:33,代码来源:DIndentationStrategy.cs

示例14: InsertComment

 private void InsertComment(TextDocument doc, DocumentLine line)
 {
     if (line.TotalLength == 0) return;
     doc.Insert(line.Offset, FbCommentString);
 }
开发者ID:degarashi0913,项目名称:FAManagementStudio,代码行数:5,代码来源:BindableEditor.cs


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