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


C# TextEditor.InsertAtCaret方法代码示例

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


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

示例1: Handle

		public override bool Handle (TextEditor editor, DocumentContext ctx, KeyDescriptor descriptor)
		{
			char closingBrace;
			if (!IsSupportedOpeningBrace (descriptor.KeyChar, out closingBrace)  || !CheckCodeContext (editor, ctx, editor.CaretOffset - 1, descriptor.KeyChar, default (CancellationToken)))
				return false;
			
			var session = CreateEditorSession (editor, ctx, editor.CaretOffset, descriptor.KeyChar, default (CancellationToken));
			session.SetEditor (editor);
			if (session == null | !((ICheckPointEditSession)session).CheckOpeningPoint (editor, ctx, default (CancellationToken)))
				return false;
			using (var undo = editor.OpenUndoGroup ()) {
				editor.EnsureCaretIsNotVirtual ();
				editor.InsertAtCaret (closingBrace.ToString ());
				editor.CaretOffset--;
				editor.StartSession (session);
			}
			return true;
		}
开发者ID:vvarshne,项目名称:monodevelop,代码行数:18,代码来源:CSharpAutoInsertBracketHandler.cs

示例2: 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));
				}
			}
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:16,代码来源:EditActions.cs

示例3: 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;
			}
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:53,代码来源:EditActions.cs

示例4: Handle

		public override bool Handle (TextEditor editor, DocumentContext ctx, KeyDescriptor descriptor)
		{
			int braceIndex = openBrackets.IndexOf (descriptor.KeyChar);
			if (braceIndex < 0)
				return false;
			
			var extEditor = ((SourceEditorView)editor.Implementation).SourceEditorWidget.TextEditor;

			var line = extEditor.Document.GetLine (extEditor.Caret.Line);
			if (line == null)
				return false;

			bool inStringOrComment = false;

			var stack = line.StartSpan.Clone ();
			var sm = extEditor.Document.SyntaxMode as SyntaxMode;
			if (sm != null)
				// extEditor.Caret.Offset - 1 means we care if we were inside string
				// before typing current char
				Mono.TextEditor.Highlighting.SyntaxModeService.ScanSpans (extEditor.Document, sm, sm, stack, line.Offset, extEditor.Caret.Offset - 1);
			foreach (var span in stack) {
				if (string.IsNullOrEmpty (span.Color))
					continue;
				if (span.Color.StartsWith ("String", StringComparison.Ordinal) ||
				    span.Color.StartsWith ("Comment", StringComparison.Ordinal) ||
				    span.Color.StartsWith ("Xml Attribute Value", StringComparison.Ordinal)) {
					inStringOrComment = true;
					break;
				}
			}
			char insertionChar = '\0';
			bool insertMatchingBracket = false;
			if (!inStringOrComment) {
				char closingBrace = closingBrackets [braceIndex];
				char openingBrace = openBrackets [braceIndex];

				int count = 0;
				foreach (char curCh in ExtensibleTextEditor.GetTextWithoutCommentsAndStrings(extEditor.Document, 0, extEditor.Document.TextLength)) {
					if (curCh == openingBrace) {
						count++;
					} else if (curCh == closingBrace) {
						count--;
					}
				}

				if (count >= 0) {
					insertMatchingBracket = true;
					insertionChar = closingBrace;
				}
			}

			if (insertMatchingBracket) {
				using (var undo = editor.OpenUndoGroup ()) {
					editor.EnsureCaretIsNotVirtual ();
					editor.InsertAtCaret (insertionChar.ToString ());
					editor.CaretOffset--;
					editor.StartSession (new SkipCharSession (insertionChar));
				}
				return true;
			}

			return false;
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:63,代码来源:DefaultAutoInsertBracketHandler.cs


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