本文整理汇总了C#中TextEditor.InsertText方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor.InsertText方法的具体用法?C# TextEditor.InsertText怎么用?C# TextEditor.InsertText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextEditor
的用法示例。
在下文中一共展示了TextEditor.InsertText方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Insert
public int Insert (TextEditor editor, DocumentContext ctx, string text)
{
int offset = editor.LocationToOffset (Location);
using (var undo = editor.OpenUndoGroup ()) {
var line = editor.GetLineByOffset (offset);
int insertionOffset = line.Offset + Location.Column - 1;
offset = insertionOffset;
InsertNewLine (editor, LineBefore, ref offset);
int result = offset - insertionOffset;
editor.InsertText (offset, text);
offset += text.Length;
InsertNewLine (editor, LineAfter, ref offset);
CodeFormatterService.Format (editor, ctx, TextSegment.FromBounds (insertionOffset - 1, offset));
return result;
}
}
示例2: ClosingTagCompletion
protected virtual ICompletionDataList ClosingTagCompletion (TextEditor buf, DocumentLocation currentLocation)
{
//get name of current node in document that's being ended
var el = tracker.Engine.Nodes.Peek () as XElement;
if (el != null && el.Region.End >= currentLocation && !el.IsClosed && el.IsNamed) {
string tag = String.Concat ("</", el.Name.FullName, ">");
if (XmlEditorOptions.AutoCompleteElements) {
// //make sure we have a clean atomic undo so the user can undo the tag insertion
// //independently of the >
// bool wasInAtomicUndo = this.Editor.Document.IsInAtomicUndo;
// if (wasInAtomicUndo)
// this.Editor.Document.EndAtomicUndo ();
using (var undo = buf.OpenUndoGroup ()) {
buf.InsertText (buf.CaretOffset, tag);
buf.CaretOffset -= tag.Length;
}
// if (wasInAtomicUndo)
// this.Editor.Document.BeginAtomicUndo ();
return null;
} else {
var cp = new CompletionDataList ();
cp.Add (new XmlTagCompletionData (tag, 0, true));
return cp;
}
}
return null;
}
示例3: FixLineStart
public bool FixLineStart (TextEditor textEditorData, ICSharpCode.NRefactory6.CSharp.IStateMachineIndentEngine stateTracker, int lineNumber)
{
if (lineNumber > 1) {
var line = textEditorData.GetLine (lineNumber);
if (line == null)
return false;
var prevLine = textEditorData.GetLine (lineNumber - 1);
if (prevLine == null)
return false;
string trimmedPreviousLine = textEditorData.GetTextAt (prevLine).TrimStart ();
//xml doc comments
//check previous line was a doc comment
//check there's a following line?
if (trimmedPreviousLine.StartsWith ("///", StringComparison.Ordinal)) {
if (textEditorData.GetTextAt (line.Offset, line.Length).TrimStart ().StartsWith ("///", StringComparison.Ordinal))
return false;
//check that the newline command actually inserted a newline
textEditorData.EnsureCaretIsNotVirtual ();
var nextLineSegment = textEditorData.GetLine (lineNumber + 1);
string nextLine = nextLineSegment != null ? textEditorData.GetTextAt (nextLineSegment).TrimStart () : "";
if (trimmedPreviousLine.Length > "///".Length || nextLine.StartsWith ("///", StringComparison.Ordinal)) {
var insertionPoint = textEditorData.CaretOffset;
textEditorData.InsertText (insertionPoint, "/// ");
textEditorData.CaretOffset = insertionPoint + "/// ".Length;
return true;
}
//multi-line comments
} else if (stateTracker.IsInsideMultiLineComment) {
if (textEditorData.GetTextAt (line.Offset, line.Length).TrimStart ().StartsWith ("*", StringComparison.Ordinal))
return false;
textEditorData.EnsureCaretIsNotVirtual ();
string commentPrefix = string.Empty;
if (trimmedPreviousLine.StartsWith ("* ", StringComparison.Ordinal)) {
commentPrefix = "* ";
} else if (trimmedPreviousLine.StartsWith ("/**", StringComparison.Ordinal) || trimmedPreviousLine.StartsWith ("/*", StringComparison.Ordinal)) {
commentPrefix = " * ";
} else if (trimmedPreviousLine.StartsWith ("*", StringComparison.Ordinal)) {
commentPrefix = "*";
}
int indentSize = line.GetIndentation (textEditorData).Length;
var insertedText = prevLine.GetIndentation (textEditorData) + commentPrefix;
textEditorData.ReplaceText (line.Offset, indentSize, insertedText);
textEditorData.CaretOffset = line.Offset + insertedText.Length;
return true;
} else if (wasInStringLiteral) {
var lexer = new ICSharpCode.NRefactory.CSharp.Completion.CSharpCompletionEngineBase.MiniLexer (textEditorData.GetTextAt (0, prevLine.EndOffset).TrimEnd ());
lexer.Parse ();
if (!lexer.IsInString)
return false;
textEditorData.EnsureCaretIsNotVirtual ();
textEditorData.InsertText (prevLine.Offset + prevLine.Length, "\" +");
int indentSize = textEditorData.CaretOffset - line.Offset;
var insertedText = prevLine.GetIndentation (textEditorData) + (trimmedPreviousLine.StartsWith ("\"", StringComparison.Ordinal) ? "" : "\t") + "\"";
textEditorData.ReplaceText (line.Offset, indentSize, insertedText);
return true;
}
}
return false;
}
示例4: DuplicateCurrentLine
public static void DuplicateCurrentLine (TextEditor textEditor)
{
// Code from Mono.TextEditor.MiscActions.DuplicateLine
using (var undoGroup = textEditor.OpenUndoGroup ()) {
if (textEditor.IsSomethingSelected) {
var selectedText = textEditor.SelectedText;
textEditor.ClearSelection ();
textEditor.InsertAtCaret (selectedText);
} else {
var line = textEditor.GetLine (textEditor.CaretLine);
if (line == null)
return;
textEditor.InsertText (line.Offset, textEditor.GetTextAt (line.SegmentIncludingDelimiter));
}
}
}
示例5: TransposeCharacters
public static void TransposeCharacters (TextEditor textEditor)
{
// Code from Mono.TextEditor.MiscActions.TransposeCharacters
if (textEditor.CaretOffset == 0)
return;
var line = textEditor.GetLine (textEditor.CaretLine);
if (line == null)
return;
using (var undoGroup = textEditor.OpenUndoGroup ()) {
int transposeOffset = textEditor.CaretOffset - 1;
char ch;
if (textEditor.CaretColumn == 0) {
var lineAbove = textEditor.GetLine (textEditor.CaretLine - 1);
if (lineAbove.Length == 0 && line.Length == 0)
return;
if (line.Length != 0) {
ch = textEditor.GetCharAt (textEditor.CaretOffset);
textEditor.RemoveText (textEditor.CaretOffset, 1);
textEditor.InsertText (lineAbove.Offset + lineAbove.Length, ch.ToString ());
return;
}
int lastCharOffset = lineAbove.Offset + lineAbove.Length - 1;
ch = textEditor.GetCharAt (lastCharOffset);
textEditor.RemoveText (lastCharOffset, 1);
textEditor.InsertAtCaret (ch.ToString ());
return;
}
int offset = textEditor.CaretOffset;
if (textEditor.CaretColumn >= line.Length + 1) {
offset = line.Offset + line.Length - 1;
transposeOffset = offset - 1;
// case one char in line:
if (transposeOffset < line.Offset) {
var lineAbove = textEditor.GetLine (textEditor.CaretLine - 1);
transposeOffset = lineAbove.Offset + lineAbove.Length;
ch = textEditor.GetCharAt (offset);
textEditor.RemoveText (offset, 1);
textEditor.InsertText (transposeOffset, ch.ToString ());
textEditor.CaretOffset = line.Offset;
return;
}
}
ch = textEditor.GetCharAt (offset);
textEditor.ReplaceText (offset, 1, textEditor.GetCharAt (transposeOffset).ToString ());
textEditor.ReplaceText (transposeOffset, 1, ch.ToString ());
if (textEditor.CaretColumn < line.Length + 1)
textEditor.CaretOffset = offset + 1;
}
}
示例6: Decompile
public static List<ReferenceSegment> Decompile (TextEditor data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData, DecompilerSettings settings)
{
var context = new DecompilerContext (module);
var source = new CancellationTokenSource ();
context.CancellationToken = source.Token;
context.CurrentType = currentType;
context.Settings = settings;
try {
var astBuilder = new AstBuilder (context);
setData (astBuilder);
astBuilder.RunTransformations (o => false);
GeneratedCodeSettings.Default.Apply (astBuilder.SyntaxTree);
var output = new ColoredCSharpFormatter (data);
astBuilder.GenerateCode (output);
output.SetDocumentData ();
return output.ReferencedSegments;
} catch (Exception e) {
// exception -> try to decompile without method bodies
try {
var astBuilder = new AstBuilder (context);
astBuilder.DecompileMethodBodies = false;
setData (astBuilder);
astBuilder.RunTransformations (o => false);
GeneratedCodeSettings.Default.Apply (astBuilder.SyntaxTree);
var output = new ColoredCSharpFormatter (data);
astBuilder.GenerateCode (output);
output.SetDocumentData ();
data.InsertText (data.Length, "/* body decompilation failed: \n" + e + " */");
} catch (Exception e2) {
data.Text = "/* fallback decompilation failed: \n" + e2 +"*/";
}
}
return null;
}
示例7: AddRegisterDirective
public void AddRegisterDirective (WebFormsPageInfo.RegisterDirective directive, TextEditor editor, bool preserveCaretPosition)
{
if (doc == null)
return;
var node = GetRegisterInsertionPointNode ();
if (node == null)
return;
doc.Info.RegisteredTags.Add (directive);
var line = Math.Max (node.Region.EndLine, node.Region.BeginLine);
var pos = editor.LocationToOffset (line, editor.GetLine (line - 1).Length);
if (pos < 0)
return;
using (var undo = editor.OpenUndoGroup ()) {
var oldCaret = editor.CaretOffset;
var text = editor.FormatString (pos, editor.EolMarker + directive);
var inserted = text.Length;
editor.InsertText (pos, text);
if (preserveCaretPosition) {
editor.CaretOffset = (pos < oldCaret)? oldCaret + inserted : oldCaret;
}
}
}