本文整理汇总了C#中MonoDevelop.Ide.Gui.TextEditor.InsertText方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor.InsertText方法的具体用法?C# TextEditor.InsertText怎么用?C# TextEditor.InsertText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoDevelop.Ide.Gui.TextEditor
的用法示例。
在下文中一共展示了TextEditor.InsertText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: InsertTemplateContents
/// <summary>
/// Don't use this unless you're implementing ICodeTemplateWidget. Use Insert instead.
/// </summary>
public TemplateResult InsertTemplateContents (TextEditor editor, DocumentContext context)
{
var data = editor;
int offset = data.CaretOffset;
// string leadingWhiteSpace = GetLeadingWhiteSpace (editor, editor.CursorLine);
var templateCtx = new TemplateContext {
Template = this,
DocumentContext = context,
Editor = editor,
//ParsedDocument = context.ParsedDocument != null ? context.ParsedDocument.ParsedFile : null,
InsertPosition = data.CaretLocation,
LineIndent = data.GetLineIndent (data.CaretLocation.Line),
TemplateCode = Code
};
if (data.IsSomethingSelected) {
int start = data.SelectionRange.Offset;
while (Char.IsWhiteSpace (data.GetCharAt (start))) {
start++;
}
int end = data.SelectionRange.EndOffset;
while (Char.IsWhiteSpace (data.GetCharAt (end - 1))) {
end--;
}
templateCtx.LineIndent = data.GetLineIndent (data.OffsetToLineNumber (start));
templateCtx.SelectedText = RemoveIndent (data.GetTextBetween (start, end), templateCtx.LineIndent);
data.RemoveText (start, end - start);
offset = start;
} else {
string word = GetTemplateShortcutBeforeCaret (data).Trim ();
if (word.Length > 0)
offset = DeleteTemplateShortcutBeforeCaret (data);
}
TemplateResult template = FillVariables (templateCtx);
template.InsertPosition = offset;
editor.InsertText (offset, template.Code);
int newoffset;
if (template.CaretEndOffset >= 0) {
newoffset = offset + template.CaretEndOffset;
} else {
newoffset = offset + template.Code.Length;
}
editor.CaretLocation = editor.OffsetToLocation (newoffset) ;
var prettyPrinter = CodeFormatterService.GetFormatter (data.MimeType);
if (prettyPrinter != null && prettyPrinter.SupportsOnTheFlyFormatting) {
int endOffset = template.InsertPosition + template.Code.Length;
var oldVersion = data.Version;
prettyPrinter.OnTheFlyFormat (editor, context, TextSegment.FromBounds (template.InsertPosition, endOffset));
foreach (var textLink in template.TextLinks) {
for (int i = 0; i < textLink.Links.Count; i++) {
var segment = textLink.Links [i];
var translatedOffset = oldVersion.MoveOffsetTo (data.Version, template.InsertPosition + segment.Offset) - template.InsertPosition;
textLink.Links [i] = new TextSegment (translatedOffset, segment.Length);
}
}
}
return template;
}
示例3: AddRegisterDirective
public void AddRegisterDirective (RegisterDirective directive, TextEditor editor, bool preserveCaretPosition)
{
var node = GetRegisterInsertionPointNode ();
if (node == null)
return;
Doc.Info.RegisteredTags.Add (directive);
var line = Math.Max (node.Location.EndLine, node.Location.BeginLine);
var pos = editor.GetPositionFromLineColumn (line, editor.GetLineLength (line) + 1);
if (pos < 0)
return;
editor.BeginAtomicUndo ();
var oldCaret = editor.CursorPosition;
var inserted = editor.InsertText (pos, editor.NewLine + directive.ToString ());
if (preserveCaretPosition) {
editor.CursorPosition = (pos < oldCaret)? oldCaret + inserted : oldCaret;
}
editor.EndAtomicUndo ();
}