本文整理汇总了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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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)
});
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}
示例14: InsertComment
private void InsertComment(TextDocument doc, DocumentLine line)
{
if (line.TotalLength == 0) return;
doc.Insert(line.Offset, FbCommentString);
}