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


C# TextEditor.InsertText方法代码示例

本文整理汇总了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;
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:60,代码来源:BaseXmlEditorExtension.cs

示例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;
		}
开发者ID:ZZHGit,项目名称:monodevelop,代码行数:67,代码来源:CodeTemplate.cs

示例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 ();
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:22,代码来源:DocumentReferenceManager.cs


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