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


C# TextEditorData.SetSelection方法代码示例

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


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

示例1: Create

		public static TextEditorData Create (string content)
		{
			int caretIndex = content.IndexOf ("$");
			if (caretIndex >= 0)
				content = content.Substring (0, caretIndex) + content.Substring (caretIndex + 1);

			int selection1 = content.IndexOf ("<-");
			int selection2 = content.IndexOf ("->");
			
			int selectionStart = 0;
			int selectionEnd = 0;
			if (0 <= selection1 && selection1 < selection2) {
				content = content.Substring (0, selection2) + content.Substring (selection2 + 2);
				content = content.Substring (0, selection1) + content.Substring (selection1 + 2);
				selectionStart = selection1;
				selectionEnd = selection2 - 2;
				caretIndex = selectionEnd;
			}

			var data = new TextEditorData ();
			data.Text = content;
			if (caretIndex >= 0)
				data.Caret.Offset = caretIndex;
			if (selection1 >= 0) {
				if (caretIndex == selectionStart) {
					data.SetSelection (selectionEnd, selectionStart);
				} else {
					data.SetSelection (selectionStart, selectionEnd);
				}
			}
			return data;
		}
开发者ID:nocache,项目名称:monodevelop,代码行数:32,代码来源:FoldingTests.cs

示例2: Create

		public static TextEditorData Create (string content, ITextEditorOptions options = null)
		{
			var data = new TextEditorData ();
			if (options != null)
				data.Options = options;
			var sb = new StringBuilder ();
			int caretIndex = -1, selectionStart = -1, selectionEnd = -1;
			var foldSegments = new List<FoldSegment> ();
			var foldStack = new Stack<FoldSegment> ();

			for (int i = 0; i < content.Length; i++) {
				var ch = content [i];
				switch (ch) {
				case '$':
					caretIndex = sb.Length;
					break;
				case '<':
					if (i + 1 < content.Length) {
						if (content [i + 1] == '-') {
							selectionStart = sb.Length;
							i++;
							break;
						}
					}
					goto default;
				case '-':
					if (i + 1 < content.Length) {
						var next = content [i + 1];
						if (next == '>') {
							selectionEnd = sb.Length;
							i++;
							break;
						}
						if (next == '[') {
							var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None);
							segment.IsFolded = false;
							foldStack.Push (segment);
							i++;
							break;
						}
					}
					goto default;
				case '+':
					if (i + 1 < content.Length) {
						var next = content [i + 1];
						if (next == '[') {
							var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None);
							segment.IsFolded = true;
							foldStack.Push (segment);
							i++;
							break;
						}
					}
					goto default;
				case ']':
					if (foldStack.Count > 0) {
						FoldSegment segment = foldStack.Pop ();
						segment.Length = sb.Length - segment.Offset;
						foldSegments.Add (segment);
						break;
					}
					goto default;
				default:
					sb.Append (ch);
					break;
				}
			}

			data.Text = sb.ToString ();

			if (caretIndex >= 0)
				data.Caret.Offset = caretIndex;
			if (selectionStart >= 0) {
				if (caretIndex == selectionStart) {
					data.SetSelection (selectionEnd, selectionStart);
				} else {
					data.SetSelection (selectionStart, selectionEnd);
				}
			}
			if (foldSegments.Count > 0)
				data.Document.UpdateFoldSegments (foldSegments);
			return data;
		}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:83,代码来源:TextEditorTestBase.cs


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