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


C# TextEditorData.SetSelection方法代码示例

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


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

示例1: SetSelectLines

        // TODO: move this somewhere else? extend TextEditor?
        public static void SetSelectLines(TextEditorData editor, int start, int end)
        {
            start = Math.Min(start, editor.LineCount);
            end = Math.Min(end, editor.LineCount);

            var startLine = start > end ? editor.GetLine(end) : editor.GetLine(start);
            var endLine = start > end ? editor.GetLine(start) : editor.GetLine(end);

            editor.SetSelection(startLine.Offset, endLine.EndOffsetIncludingDelimiter);
        }
开发者ID:shirshov,项目名称:monodevelop-justenoughvi,代码行数:11,代码来源:Motion.cs

示例2: RemoveIndentSelection

		public static void RemoveIndentSelection (TextEditorData data)
		{
			if (!data.IsSomethingSelected)
				return;
			int startLineNr, endLineNr;
			GetSelectedLines (data, out startLineNr, out endLineNr);
			
			using (var undo = data.OpenUndoGroup (OperationType.Format)) {
				var anchor = data.MainSelection.Anchor;
				var lead = data.MainSelection.Lead;
				bool first = true;
				bool removedFromLast = false;
				int removeLast = 0;
				bool removedFromFirst = false;
				int removeFirst = 0;
				foreach (var line in data.SelectedLines) {
					int remove = RemoveTabInLine (data, line);
					removedFromLast |= remove > 0;
					removeLast = remove;
					if (first) {
						removedFromFirst = remove > 0;
						removeFirst = remove;
						first = false;
					}
				}

				var ac = System.Math.Max (DocumentLocation.MinColumn, anchor.Column - (anchor < lead ? removeFirst : removeLast));
				var lc = System.Math.Max (DocumentLocation.MinColumn, lead.Column - (anchor < lead ? removeLast : removeFirst));
				
				if (anchor < lead) {
					if (!removedFromFirst)
						ac = anchor.Column;
					if (!removedFromLast)
						lc = lead.Column;
				} else {
					if (!removedFromFirst)
						lc = lead.Column;
					if (!removedFromLast)
						ac = anchor.Column;
				}
				data.SetSelection (anchor.Line, ac, lead.Line, lc);
			}
			data.Document.RequestUpdate (new MultipleLineUpdate (startLineNr, endLineNr));
			data.Document.CommitDocumentUpdate ();
		}
开发者ID:OnorioCatenacci,项目名称:monodevelop,代码行数:45,代码来源:MiscActions.cs

示例3: MoveBlockDown

		public static void MoveBlockDown (TextEditorData data)
		{
			int lineStart = data.Caret.Line;
			int lineEnd = data.Caret.Line;
			bool setSelection = lineStart != lineEnd;
			DocumentLocation anchor = DocumentLocation.Empty, lead = DocumentLocation.Empty;
			if (data.IsSomethingSelected) {
				setSelection = true;
				lineStart = data.MainSelection.MinLine;
				lineEnd = data.MainSelection.MaxLine;
				anchor = data.MainSelection.Anchor;
				lead = data.MainSelection.Lead;
			}
			
			if (lineStart <= 0)
				return;
			using (var undo = data.OpenUndoGroup ()) {
				
				//Mono.TextEditor.LineSegment startLine = data.Document.GetLine (lineStart);
				//int relCaretOffset = data.Caret.Offset - startLine.Offset;
				
				Mono.TextEditor.DocumentLine nextLine = data.Document.GetLine (lineEnd + 1);
				if (nextLine == null)
					return;
				string text = data.Document.GetTextAt (nextLine.Offset, nextLine.Length);
				List<TextLineMarker> prevLineMarkers = new List<TextLineMarker> (nextLine.Markers);
				nextLine.ClearMarker ();
				var loc = data.Caret.Location;
				for (int i = lineEnd + 1; i >= lineStart; i--) {
					DocumentLine cur = data.Document.GetLine (i);
					DocumentLine prev = data.Document.GetLine (i - 1);
					data.Replace (cur.Offset, cur.Length, i != lineStart ? data.Document.GetTextAt (prev.Offset, prev.Length) : text);
					data.Document.GetLine (i).ClearMarker ();
					foreach (TextLineMarker marker in (i != lineStart ? data.Document.GetLine (i - 1).Markers : prevLineMarkers)) {
						data.Document.GetLine (i).AddMarker (marker);
					}
				}
				
				data.Caret.Location = new DocumentLocation (loc.Line + 1, loc.Column);
				if (setSelection)
					data.SetSelection (anchor.Line + 1, anchor.Column, lead.Line + 1, lead.Column);
			}
		}
开发者ID:OnorioCatenacci,项目名称:monodevelop,代码行数:43,代码来源:MiscActions.cs

示例4: IndentSelection

		public static void IndentSelection (TextEditorData data)
		{
			if (!data.IsSomethingSelected)
				return;
			int startLineNr, endLineNr;
			GetSelectedLines (data, out startLineNr, out endLineNr);
			var anchor = data.MainSelection.Anchor;
			var lead = data.MainSelection.Lead;
			var indentationString = data.Options.IndentationString;
			using (var undo = data.OpenUndoGroup (OperationType.Format)) {
				foreach (DocumentLine line in data.SelectedLines) {
					if (data.Options.IndentStyle == IndentStyle.Virtual && line.Length == 0)
						continue;
					data.Insert (line.Offset, indentationString);
				}
			}
			int chars = indentationString.Length;
			var leadCol = lead.Column > 1 || lead < anchor ? lead.Column + chars : 1;
			var anchorCol = anchor.Column > 1 || anchor < lead ? anchor.Column + chars : 1;
			data.SetSelection (anchor.Line, anchorCol, lead.Line, leadCol);
			data.Document.RequestUpdate (new MultipleLineUpdate (startLineNr, endLineNr));
			data.Document.CommitDocumentUpdate ();
		}
开发者ID:OnorioCatenacci,项目名称:monodevelop,代码行数:23,代码来源:MiscActions.cs

示例5: Create

        public static TextEditorData Create(string content, ITextEditorOptions options = null)
        {
            var data = new TextEditorData ();
            data.Options.DefaultEolMarker = eolMarker;
            data.Options.IndentStyle = IndentStyle.Smart;
            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 (caretIndex < 0)
                        data.Caret.Offset = selectionEnd;
                }
            }
            if (foldSegments.Count > 0)
                data.Document.UpdateFoldSegments (foldSegments);
            return data;
        }
开发者ID:Kalnor,项目名称:monodevelop,代码行数:87,代码来源:CSharpTextEditorIndentationTests.cs

示例6: EndLineSelection

		public static void EndLineSelection (TextEditorData data)
		{
			int fromLine = data.MainSelection.Anchor.Line;
			int toLine = data.Caret.Line;
			var toSegment = data.Document.GetLine (toLine);
			
			//flip the anchor if pivoting around the origin line
			if (fromLine == toLine + 1) {
				if ((fromLine - data.MainSelection.Lead.Line) != 2) {
					var fromSegment = data.Document.GetLine (fromLine);
					data.SetSelection (fromSegment.EndOffset, toSegment.Offset);
				} else {
					data.SetSelection (toSegment.Offset, toSegment.EndOffset);
				}
			}
			//else just extend the selection
			else {
				int toOffset = (toLine < fromLine)? toSegment.Offset: toSegment.EndOffset;
				data.ExtendSelectionTo (toOffset);
			}
			data.Caret.PreserveSelection = false;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:22,代码来源:SelectionActions.cs

示例7: HandleSpecialSelectionKey

		public virtual void HandleSpecialSelectionKey (TextEditorData textEditorData,uint unicodeKey)
		{
			string start, end;
			GetSelectionSurroundings (textEditorData, unicodeKey, out start, out end);
			
			if (textEditorData.MainSelection.SelectionMode == SelectionMode.Block) {
				var selection = textEditorData.MainSelection;
				int startCol = System.Math.Min (selection.Anchor.Column, selection.Lead.Column) - 1;
				int endCol = System.Math.Max (selection.Anchor.Column, selection.Lead.Column);
				for (int lineNumber = selection.MinLine; lineNumber <= selection.MaxLine; lineNumber++) {
					DocumentLine lineSegment = textEditorData.GetLine (lineNumber);
					
					if (lineSegment.Offset + startCol < lineSegment.EndOffset)
						textEditorData.Insert (lineSegment.Offset + startCol, start);
					if (lineSegment.Offset + endCol < lineSegment.EndOffset)
						textEditorData.Insert (lineSegment.Offset + endCol, end);
				}
				
				textEditorData.MainSelection = new Selection (
					new DocumentLocation (selection.Anchor.Line, endCol == selection.Anchor.Column ? endCol + start.Length : startCol + 1 + start.Length),
					new DocumentLocation (selection.Lead.Line, endCol == selection.Anchor.Column ? startCol + 1 + start.Length : endCol + start.Length),
					Mono.TextEditor.SelectionMode.Block);
				textEditorData.Document.CommitMultipleLineUpdate (textEditorData.MainSelection.MinLine, textEditorData.MainSelection.MaxLine);
			} else {
				int anchorOffset = textEditorData.MainSelection.GetAnchorOffset (textEditorData);
				int leadOffset = textEditorData.MainSelection.GetLeadOffset (textEditorData);
				if (leadOffset < anchorOffset) {
					int tmp = anchorOffset;
					anchorOffset = leadOffset;
					leadOffset = tmp;
				}
				textEditorData.Insert (anchorOffset, start);
				textEditorData.Insert (leadOffset >= anchorOffset ? leadOffset + start.Length : leadOffset, end);
				textEditorData.SetSelection (anchorOffset + start.Length, leadOffset + start.Length);
			}
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:36,代码来源:ISelectionSurroundingProvider.cs

示例8: IndentSelection

		public static void IndentSelection (TextEditorData data)
		{
			if (!data.IsSomethingSelected)
				return;
			int startLineNr, endLineNr;
			GetSelectedLines (data, out startLineNr, out endLineNr);
			var anchor = data.MainSelection.Anchor;
			var lead = data.MainSelection.Lead;
			using (var undo = data.OpenUndoGroup ()) {
				foreach (DocumentLine line in data.SelectedLines) {
					data.Insert (line.Offset, data.Options.IndentationString);
				}
			}
			var leadCol = lead.Column > 1 || lead < anchor ? lead.Column + 1 : 1;
			var anchorCol = anchor.Column > 1 || anchor < lead ? anchor.Column + 1 : 1;
			data.SetSelection (anchor.Line, anchorCol, lead.Line, leadCol);
			data.Document.RequestUpdate (new MultipleLineUpdate (startLineNr, endLineNr));
			data.Document.CommitDocumentUpdate ();
		}
开发者ID:head-thrash,项目名称:monodevelop,代码行数:19,代码来源:MiscActions.cs

示例9: SortSelectedLines

		public static void SortSelectedLines (TextEditorData data)
		{
			var start = data.MainSelection.Start;
			var end = data.MainSelection.End;
			var caret = data.Caret.Location;

			int startLine = start.Line;
			int endLine = end.Line;
			if (startLine == endLine)
				return;

			int length = 0;
			var lines = new string[endLine - startLine + 1];
			for (int i = startLine; i <= endLine; i++) {
				//get lines *with* line endings
				var lineText = data.GetLineText (i, true);
				lines [i - startLine] = lineText;
				length += lineText.Length;
			}

			var linesUnsorted = new string[lines.Length];

			Array.Sort (lines, StringComparer.Ordinal);

			bool changed = false;
			for (int i = 0; i <= lines.Length; i++) {
				//can't simply use reference comparison as Array.Sort is not stable
				if (string.Equals (lines [i], linesUnsorted [i], StringComparison.Ordinal)) {
					continue;
				}
				changed = true;
				break;
			}
			if (!changed) {
				return;
			}


			var sb = new StringBuilder ();
			for (int i = 0; i < lines.Length; i++) {
				sb.Append (lines [i]);
			}

			var startOffset = data.Document.LocationToOffset (new TextLocation (startLine, 0));
			data.Replace (startOffset, length, sb.ToString ());

			data.Caret.Location = LimitColumn (data, caret);
			data.SetSelection (LimitColumn (data, start), LimitColumn (data, end));
		}
开发者ID:riverans,项目名称:monodevelop,代码行数:49,代码来源:MiscActions.cs

示例10: MoveBlockDown

		public static void MoveBlockDown (TextEditorData data)
		{
			int lineStart = data.Caret.Line;
			int lineEnd = data.Caret.Line;
			bool setSelection = lineStart != lineEnd;
			if (data.IsSomethingSelected) {
				setSelection = true;
				lineStart = data.MainSelection.MinLine;
				lineEnd = data.MainSelection.MaxLine;
			}
			
			if (lineStart <= 0)
				return;
			data.Document.BeginAtomicUndo ();
			
			Mono.TextEditor.LineSegment startLine = data.Document.GetLine (lineStart);
			int relCaretOffset = data.Caret.Offset - startLine.Offset;
			
			Mono.TextEditor.LineSegment nextLine = data.Document.GetLine (lineEnd + 1);
			string text = data.Document.GetTextAt (nextLine.Offset, nextLine.EditableLength);
			List<TextMarker> prevLineMarkers = new List<TextMarker> (nextLine.Markers);
			nextLine.ClearMarker ();
			
			for (int i = lineEnd + 1; i >= lineStart; i--) {
				LineSegment cur = data.Document.GetLine (i);
				LineSegment prev = data.Document.GetLine (i - 1);
				data.Replace (cur.Offset, cur.EditableLength, i != lineStart ? data.Document.GetTextAt (prev.Offset, prev.EditableLength) : text);
				data.Document.GetLine (i).ClearMarker ();
				foreach (TextMarker marker in (i != lineStart ? data.Document.GetLine (i - 1).Markers : prevLineMarkers)) {
					data.Document.GetLine (i).AddMarker (marker);
				}
			}
			
			data.Caret.Offset = nextLine.Offset + relCaretOffset;
			if (setSelection)
				data.SetSelection (data.Document.GetLine (lineStart + 1).Offset, data.Document.GetLine (lineEnd + 1).Offset + data.Document.GetLine (lineEnd + 1).EditableLength);
			data.Document.EndAtomicUndo ();
		}
开发者ID:acken,项目名称:monodevelop,代码行数:38,代码来源:DefaultEditActions.cs

示例11: OnTheFlyFormat

		public override void OnTheFlyFormat (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, 
			TextEditorData data, int startOffset, int endOffset)
		{
			var parser = new CSharpParser ();
			var compilationUnit = parser.ParseSnippet (data);
			if (compilationUnit == null) {
				Console.WriteLine ("couldn't parse : " + data.Text);
				return;
			}
			if (parser.HasErrors)
				return;
			
			var policy = policyParent.Get<CSharpFormattingPolicy> (mimeTypeChain);
			var adapter = new TextEditorDataAdapter (data);
			var factory = new FormattingActionFactory (data);
			
			var formattingVisitor = new ICSharpCode.NRefactory.CSharp.AstFormattingVisitor (policy.CreateOptions (), adapter, factory) {
				HadErrors =  parser.HasErrors
			};
			
			compilationUnit.AcceptVisitor (formattingVisitor, null);
			
			var changes = new List<ICSharpCode.NRefactory.CSharp.Refactoring.Action> ();
			changes.AddRange (formattingVisitor.Changes.
				Where (c => (startOffset <= c.Offset && c.Offset < endOffset)));
			
			var startPositionChange = factory.CreateTextReplaceAction (startOffset, 0, null);
			changes.Add (startPositionChange);
			
			var endPositionChange = factory.CreateTextReplaceAction (endOffset, 0, null);
			changes.Add (endPositionChange);
			
			using (var undo = data.OpenUndoGroup ()) {
				MDRefactoringContext.MdScript.RunActions (changes, null);
			}
			
			if (data.IsSomethingSelected) {
				var range = data.SelectionRange;
				if (range.Offset == startOffset && range.EndOffset == endOffset) {
					data.SetSelection (startPositionChange.Offset, endPositionChange.Offset);
				}
			}
		}
开发者ID:nieve,项目名称:monodevelop,代码行数:43,代码来源:CSharpFormatter.cs

示例12: Run

		public override void Run (RefactoringOptions options)
		{
			fileName = declaringType.CompilationUnit.FileName;
			
			var openDocument = IdeApp.Workbench.OpenDocument (fileName);
			if (openDocument == null) {
				MessageService.ShowError (string.Format (GettextCatalog.GetString ("Can't open file {0}."), fileName));
				return;
			}
			data = openDocument.Editor;
			if (data == null)
				return;
			openDocument.RunWhenLoaded (delegate {
				try {
					indent = data.Document.GetLine (declaringType.Location.Line).GetIndentation (data.Document) ?? "";
				} catch (Exception) {
					indent = "";
				}
				indent += "\t";
				
				InsertionCursorEditMode mode = new InsertionCursorEditMode (data.Parent, CodeGenerationService.GetInsertionPoints (openDocument, declaringType));
				if (fileName == options.Document.FileName) {
					for (int i = 0; i < mode.InsertionPoints.Count; i++) {
						var point = mode.InsertionPoints [i];
						if (point.Location < data.Caret.Location) {
							mode.CurIndex = i;
						} else {
							break;
						}
					}
				}
				
				ModeHelpWindow helpWindow = new ModeHelpWindow ();
				helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
				helpWindow.TitleText = GettextCatalog.GetString ("<b>Create Method -- Targeting</b>");
				helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Key</b>"), GettextCatalog.GetString ("<b>Behavior</b>")));
				helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Up</b>"), GettextCatalog.GetString ("Move to <b>previous</b> target point.")));
				helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Down</b>"), GettextCatalog.GetString ("Move to <b>next</b> target point.")));
				helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Enter</b>"), GettextCatalog.GetString ("<b>Declare new method</b> at target point.")));
				helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Esc</b>"), GettextCatalog.GetString ("<b>Cancel</b> this refactoring.")));
				mode.HelpWindow = helpWindow;
				mode.StartMode ();
				mode.Exited += delegate(object s, InsertionCursorEventArgs args) {
					if (args.Success) {
						SetInsertionPoint (args.InsertionPoint);
						BaseRun (options);
						if (string.IsNullOrEmpty (fileName))
							return;
						data.ClearSelection ();
						data.Caret.Offset = selectionEnd;
						data.SetSelection (selectionStart, selectionEnd);
					}
				};
			});
		}
开发者ID:raufbutt,项目名称:monodevelop-old,代码行数:55,代码来源:CreateMethodCodeGenerator.cs

示例13: MoveBlockDown

		public static void MoveBlockDown (TextEditorData data)
		{
			int lineStart = data.Caret.Line;
			int lineEnd = data.Caret.Line;
			bool setSelection = lineStart != lineEnd;
			if (data.IsSomethingSelected) {
				setSelection = true;
				lineStart = data.MainSelection.MinLine;
				lineEnd = data.MainSelection.MaxLine;
			}
			
			if (lineEnd + 1 >= data.Document.LineCount)
				return;
			
			Mono.TextEditor.LineSegment startLine = data.Document.GetLine (lineStart);
			Mono.TextEditor.LineSegment endLine = data.Document.GetLine (lineEnd);
			Mono.TextEditor.LineSegment nextLine = data.Document.GetLine (lineEnd + 1);
			int relCaretOffset = data.Caret.Offset - startLine.Offset;
			data.Document.BeginAtomicUndo ();
			string text = data.Document.GetTextBetween (startLine.Offset, endLine.EndOffset);
			
			int nextLineOffset = nextLine.EndOffset;
			int delta = endLine.EndOffset - startLine.Offset;
			int newStartOffset = nextLineOffset - delta;
			
			// handle the last line case
			if (nextLine.DelimiterLength == 0) {
				text = data.EolMarker + text.Substring (0, text.Length - endLine.DelimiterLength);
				newStartOffset += data.EolMarker.Length;
			}
			data.Insert (nextLineOffset, text);
			data.Remove (startLine.Offset, delta);
			
			// move markers
			List<TextMarker> markers = new List<TextMarker> (nextLine.Markers);
			nextLine.ClearMarker ();
			for (int i = lineEnd; i <= lineStart; i++) {
				foreach (TextMarker marker in data.Document.GetLine (i).Markers) {
					data.Document.GetLine (i + 1).AddMarker (marker);
				}
				data.Document.GetLine (i).ClearMarker ();
			}
			markers.ForEach (m => startLine.AddMarker (m));

			
			data.Caret.Offset = newStartOffset + relCaretOffset;
			if (setSelection)
				data.SetSelection (newStartOffset, newStartOffset + text.Length - endLine.DelimiterLength);
			data.Document.EndAtomicUndo ();
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:50,代码来源:DefaultEditActions.cs

示例14: MoveBlockUp

		public static void MoveBlockUp (TextEditorData data)
		{
			int lineStart = data.Caret.Line;
			int lineEnd = data.Caret.Line;
			bool setSelection = lineStart != lineEnd;
			if (data.IsSomethingSelected) {
				setSelection = true;
				lineStart = data.MainSelection.MinLine;
				lineEnd = data.MainSelection.MaxLine;
			}
			
			if (lineStart <= 0)
				return;
			
			Mono.TextEditor.LineSegment startLine = data.Document.GetLine (lineStart);
			Mono.TextEditor.LineSegment endLine = data.Document.GetLine (lineEnd);
			Mono.TextEditor.LineSegment prevLine = data.Document.GetLine (lineStart - 1);
			int relCaretOffset = data.Caret.Offset - startLine.Offset;
			data.Document.BeginAtomicUndo ();
			
			string text = data.Document.GetTextBetween (startLine.Offset, endLine.EndOffset);
			
			int delta = endLine.EndOffset - startLine.Offset;
			int newStartOffset = prevLine.Offset;
			bool hasEmptyDelimiter = endLine.DelimiterLength == 0;
			
			data.Remove (startLine.Offset, delta);
			
			// handle the last line case
			if (hasEmptyDelimiter) {
				text = text + data.EolMarker;
				data.Remove (prevLine.Offset + prevLine.EditableLength, prevLine.DelimiterLength);
			}
			
			// move markers
			List<TextMarker> markers = new List<TextMarker> (prevLine.Markers);
			prevLine.ClearMarker ();
			for (int i = lineStart; i <= lineEnd; i++) {
				foreach (TextMarker marker in data.Document.GetLine (i).Markers) {
					data.Document.GetLine (i - 1).AddMarker (marker);
				}
				data.Document.GetLine (i).ClearMarker ();
			}
			markers.ForEach (m => endLine.AddMarker (m));
			
			data.Insert (newStartOffset, text);
			data.Caret.Offset = newStartOffset + relCaretOffset;
			if (setSelection)
				data.SetSelection (newStartOffset, newStartOffset + delta - endLine.DelimiterLength);
			data.Document.EndAtomicUndo ();
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:51,代码来源:DefaultEditActions.cs

示例15: Create

        static TextEditorData Create(string content, ITextEditorOptions options = null)
        {
            var sb = new StringBuilder();
            int caretIndex = -1, selectionStart = -1, selectionEnd = -1;

            for (int i = 0; i < content.Length; i++)
            {
                var ch = content[i];
                switch (ch)
                {
                case '$':
                    caretIndex = sb.Length - 1;
                    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;
                        }
                    }
                    goto default;
                default:
                    sb.Append(ch);
                    break;
                }
            }
            var editor = new TextEditorData();
            editor.Text = sb.ToString();
            if (options != null)
                editor.Options = options;

            if (caretIndex >= 0)
                editor.Caret.Offset = caretIndex;
            if (selectionStart >= 0)
            {
                if (caretIndex == selectionStart)
                {
                    editor.SetSelection(selectionEnd, selectionStart);
                }
                else
                {
                    editor.SetSelection(selectionStart, selectionEnd);
                    if (caretIndex < 0)
                        editor.Caret.Offset = selectionEnd;
                }
            }
            return editor;
        }
开发者ID:hifi,项目名称:monodevelop-justenoughvi,代码行数:63,代码来源:TextEditorTestBase.cs


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