當前位置: 首頁>>代碼示例>>C#>>正文


C# TextEditorData.GetVirtualIndentationColumn方法代碼示例

本文整理匯總了C#中Mono.TextEditor.TextEditorData.GetVirtualIndentationColumn方法的典型用法代碼示例。如果您正苦於以下問題:C# TextEditorData.GetVirtualIndentationColumn方法的具體用法?C# TextEditorData.GetVirtualIndentationColumn怎麽用?C# TextEditorData.GetVirtualIndentationColumn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.TextEditor.TextEditorData的用法示例。


在下文中一共展示了TextEditorData.GetVirtualIndentationColumn方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Left

		public static void Left (TextEditorData data)
		{
			if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection) {
				data.Caret.Offset = System.Math.Min (data.SelectionAnchor, data.Caret.Offset);
				data.ClearSelection ();
				return;
			}
			
			if (data.Caret.Column > DocumentLocation.MinColumn) {
				DocumentLine line = data.Document.GetLine (data.Caret.Line);
				if (data.Caret.Column > line.Length + 1) {
					if (data.Caret.AllowCaretBehindLineEnd) {
						data.Caret.Column--;
					} else {
						data.Caret.Column = line.Length + 1;
					}
				} else {
					int offset = data.Caret.Offset - 1;
					foreach (var folding in data.Document.GetFoldingsFromOffset (offset).Where (f => f.IsFolded && f.Offset < offset)) {
						offset = System.Math.Min (offset, folding.Offset);
					}
					data.Caret.Offset = offset;
				}
			} else if (data.Caret.Line > DocumentLocation.MinLine) {
				DocumentLine prevLine = data.Document.GetLine (data.Caret.Line - 1);
				var nextLocation = new DocumentLocation (data.Caret.Line - 1, prevLine.Length + 1);
				if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual && nextLocation.Column == DocumentLocation.MinColumn)
					nextLocation = new DocumentLocation (data.Caret.Line - 1, data.GetVirtualIndentationColumn (nextLocation));
				data.Caret.Location = nextLocation;
			}
		}
開發者ID:RainsSoft,項目名稱:playscript-monodevelop,代碼行數:31,代碼來源:CaretMoveActions.cs

示例2: InsertNewLine

		public static void InsertNewLine (TextEditorData data)
		{
			if (!data.CanEditSelection)
				return;
			
			using (var undo = data.OpenUndoGroup ()) {
				if (data.IsSomethingSelected)
					data.DeleteSelectedText ();
				switch (data.Options.IndentStyle) {
				case IndentStyle.None:
					data.InsertAtCaret (data.EolMarker);
					break;
				case IndentStyle.Auto:
					data.EnsureCaretIsNotVirtual ();
					var sb = new StringBuilder (data.EolMarker);
					sb.Append (data.Document.GetLineIndent (data.Caret.Line));
					data.InsertAtCaret (sb.ToString ());
					break;
				case IndentStyle.Smart:
					if (!data.HasIndentationTracker)
						goto case IndentStyle.Auto;
					NewLineSmartIndent (data);
					break;
				case IndentStyle.Virtual:
					if (!data.HasIndentationTracker)
						goto case IndentStyle.Auto;
					var oldLine = data.Caret.Line;
					var curLine = data.GetLine (oldLine);
					var indentCol = data.GetVirtualIndentationColumn (data.Caret.Location);
					if (curLine.Length >= data.Caret.Column) {
						NewLineSmartIndent (data);
						data.FixVirtualIndentation ();
						data.FixVirtualIndentation (oldLine);
						break;
					}
					data.Insert (data.Caret.Offset, data.EolMarker);
					data.FixVirtualIndentation (oldLine);
					data.Caret.Column = indentCol;
					break;
				default:
					throw new ArgumentOutOfRangeException ();
				}
			}
		}
開發者ID:OnorioCatenacci,項目名稱:monodevelop,代碼行數:44,代碼來源:MiscActions.cs

示例3: InsertNewLine

		public static void InsertNewLine (TextEditorData data)
		{
			if (!data.CanEditSelection)
				return;
			
			using (var undo = data.OpenUndoGroup ()) {
				if (data.IsSomethingSelected) {
					var end = data.MainSelection.End;
					data.DeleteSelectedText ();
					if (end.Column == 1) {
						CaretMoveActions.InternalCaretMoveHome (data, true, false);
						return;
					}
				}
				switch (data.Options.IndentStyle) {
				case IndentStyle.None:
					data.InsertAtCaret (data.EolMarker);
					break;
				case IndentStyle.Auto:
					data.EnsureCaretIsNotVirtual ();
					var indent = data.Document.GetLineIndent (data.Caret.Line);
					data.InsertAtCaret (data.EolMarker);
					data.EnsureCaretIsNotVirtual ();
					if (data.GetLine (data.Caret.Line).Length == 0)
						data.InsertAtCaret (indent);
					break;
				case IndentStyle.Smart:
					if (!data.HasIndentationTracker)
						goto case IndentStyle.Auto;
					NewLineSmartIndent (data);
					break;
				case IndentStyle.Virtual:
					if (!data.HasIndentationTracker)
						goto case IndentStyle.Auto;
					var oldLine = data.Caret.Line;
					var curLine = data.GetLine (oldLine);
					var indentCol = data.GetVirtualIndentationColumn (data.Caret.Location);
					if (curLine.Length >= data.Caret.Column) {
						NewLineSmartIndent (data);
						data.FixVirtualIndentation ();
						data.FixVirtualIndentation (oldLine);
						break;
					}
					data.Insert (data.Caret.Offset, data.EolMarker);
					data.FixVirtualIndentation (oldLine);
					data.Caret.Column = indentCol;
					break;
				default:
					throw new ArgumentOutOfRangeException ();
				}
			}
		}
開發者ID:FreeBSD-DotNet,項目名稱:monodevelop,代碼行數:52,代碼來源:MiscActions.cs

示例4: Right

		public static void Right (TextEditorData data)
		{
			if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection) {
				data.Caret.Offset = System.Math.Max (data.SelectionAnchor, data.Caret.Offset);
				data.ClearSelection ();
				return;
			}
			
			DocumentLine line = data.Document.GetLine (data.Caret.Line);
			IEnumerable<FoldSegment > foldings = data.Document.GetStartFoldings (line);
			FoldSegment segment = null;
			foreach (FoldSegment folding in foldings) {
				if (folding.IsFolded && folding.Column == data.Caret.Column) {
					segment = folding;
					break;
				}
			}
			if (segment != null) {
				data.Caret.Offset = segment.EndOffset; 
				return;
			}

			if (data.Caret.Column >= line.Length + 1) {
				int nextColumn;
				if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual && data.Caret.Column == DocumentLocation.MinColumn) {
					nextColumn = data.GetVirtualIndentationColumn (data.Caret.Location);
				} else if (data.Caret.AllowCaretBehindLineEnd) {
					nextColumn = data.Caret.Column + 1;
				} else {
					nextColumn = line.Length + 1;
				}

				if (data.Caret.Column < nextColumn) {
					data.Caret.Column = nextColumn;
				} else {
					if (data.Caret.Line < data.LineCount)
						data.Caret.Location = new DocumentLocation (data.Caret.Line + 1, DocumentLocation.MinColumn);
				}
			} else {
				data.Caret.Column++;
			}
		}
開發者ID:RainsSoft,項目名稱:playscript-monodevelop,代碼行數:42,代碼來源:CaretMoveActions.cs

示例5: LineEnd

		public static void LineEnd (TextEditorData data)
		{
			if (!data.Caret.PreserveSelection)
				data.ClearSelection ();
			var line = data.Document.GetLine (data.Caret.Line);
			var newLocation = new DocumentLocation (data.Caret.Line, line.Length + 1);

			// handle folding
			IEnumerable<FoldSegment> foldings = data.Document.GetStartFoldings (line);
			FoldSegment segment = null;
			foreach (FoldSegment folding in foldings) {
				if (folding.IsFolded && folding.Contains (data.Document.LocationToOffset (newLocation))) {
					segment = folding;
					break;
				}
			}
			if (segment != null) 
				newLocation = data.Document.OffsetToLocation (segment.EndLine.Offset + segment.EndColumn - 1); 
			if (newLocation != data.Caret.Location)
				data.Caret.Location = newLocation;
			
			if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual) {
				int virtualIndentColumn = data.GetVirtualIndentationColumn (data.Caret.Location);
				if (virtualIndentColumn > data.Caret.Column)
					data.Caret.Column = virtualIndentColumn;
			}
			
		}
開發者ID:RainsSoft,項目名稱:playscript-monodevelop,代碼行數:28,代碼來源:CaretMoveActions.cs

示例6: Backspace

		public static void Backspace (TextEditorData data, Action<TextEditorData> removeCharBeforeCaret)
		{
			if (!data.CanEditSelection)
				return;
			using (var undo = data.OpenUndoGroup ()) {
				if (data.IsSomethingSelected) {
					var visualAnchorLocation = data.LogicalToVisualLocation (data.MainSelection.Anchor);
					var visualLeadLocation = data.LogicalToVisualLocation (data.MainSelection.Lead);
					// case: zero width block selection
					if (data.MainSelection.SelectionMode == SelectionMode.Block && visualAnchorLocation.Column == visualLeadLocation.Column) {
						var col = data.MainSelection.Lead.Column;
						if (col <= DocumentLocation.MinColumn) {
							data.ClearSelection ();
							return;
						}
						bool preserve = data.Caret.PreserveSelection;
						data.Caret.PreserveSelection = true;
						for (int lineNumber = data.MainSelection.MinLine; lineNumber <= data.MainSelection.MaxLine; lineNumber++) {
							var lineSegment = data.Document.GetLine (lineNumber);
							int insertOffset = lineSegment.GetLogicalColumn (data, visualAnchorLocation.Column - 1) - 1;
							data.Remove (lineSegment.Offset + insertOffset, 1);
						}

						var visualColumn = data.GetLine (data.Caret.Location.Line).GetVisualColumn (data, col - 1);
						data.MainSelection = new Selection (
							new DocumentLocation (data.MainSelection.Anchor.Line, data.GetLine (data.MainSelection.Anchor.Line).GetLogicalColumn (data, visualColumn)),
							new DocumentLocation (data.MainSelection.Lead.Line, data.GetLine (data.MainSelection.Lead.Line).GetLogicalColumn (data, visualColumn)),
							SelectionMode.Block
						);

						data.Caret.PreserveSelection = preserve;
						data.Document.CommitMultipleLineUpdate (data.MainSelection.MinLine, data.MainSelection.MaxLine);
						return;
					}
					data.DeleteSelectedText (data.MainSelection.SelectionMode != SelectionMode.Block);
					return;
				}

				if (data.Caret.Line == DocumentLocation.MinLine && data.Caret.Column == DocumentLocation.MinColumn)
					return;
			
				// Virtual indentation needs to be fixed before to have the same behavior
				// if it's there or not (otherwise user has to press multiple backspaces in some cases)
				data.EnsureCaretIsNotVirtual ();

				var line = data.Document.GetLine (data.Caret.Line);
				// smart backspace (delete indentation)
				if (data.HasIndentationTracker && (data.IndentationTracker.SupportedFeatures & IndentatitonTrackerFeatures.SmartBackspace) != 0 && (data.Options.IndentStyle == IndentStyle.Smart || data.Options.IndentStyle == IndentStyle.Virtual)) {
					if (data.Caret.Column == data.GetVirtualIndentationColumn (data.Caret.Location)) {
						bool isAllIndent = line.GetIndentation (data.Document).Length == data.Caret.Column - 1;

						if (isAllIndent) {
							var prevLine = line.PreviousLine;
							var prevLineIsEmpty = prevLine != null && prevLine.Length == 0;

							var startOffset = prevLine != null ? prevLine.EndOffset : 0;
							data.Remove (startOffset, data.Caret.Offset - startOffset);
							if (prevLine != null) {
								if (prevLineIsEmpty) {
									if (line.Length - data.Caret.Column - 1 > 0 && data.HasIndentationTracker) {
										data.InsertAtCaret (data.IndentationTracker.GetIndentationString (data.Caret.Offset));
									} else {
										data.Caret.Column = data.GetVirtualIndentationColumn (prevLine.Offset);
									}
								}
								data.FixVirtualIndentation ();
							}
							return;
						}
					}
				}

				// normal backspace.
				if (data.Caret.Column > line.Length + 1) {
					data.Caret.Column = line.Length + 1;
				} else if (data.Caret.Offset == line.Offset) {
					DocumentLine lineAbove = data.Document.GetLine (data.Caret.Line - 1);
					if (lineAbove.Length == 0 && data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual) {
						data.Caret.Location = new DocumentLocation (data.Caret.Line - 1, data.IndentationTracker.GetVirtualIndentationColumn (data.Caret.Line - 1, 1));
						data.Replace (lineAbove.EndOffsetIncludingDelimiter - lineAbove.DelimiterLength, lineAbove.DelimiterLength, data.IndentationTracker.GetIndentationString (data.Caret.Line - 1, 1));
					} else {
						data.Remove (lineAbove.EndOffsetIncludingDelimiter - lineAbove.DelimiterLength, lineAbove.DelimiterLength);
					}
				} else {
					removeCharBeforeCaret (data);
				}

				// Needs to be fixed after, the line may just contain the indentation
				data.FixVirtualIndentation ();
			}
		}
開發者ID:pabloescribanoloza,項目名稱:monodevelop,代碼行數:91,代碼來源:DeleteActions.cs

示例7: SmartBackspace

		static void SmartBackspace (TextEditorData data, DocumentLine line)
		{
			var prevLine = line.PreviousLine;
			var prevLineIsEmpty = prevLine != null && prevLine.Length == 0;

			var startOffset = prevLine != null ? prevLine.EndOffset : 0;
			var count = data.Caret.Offset - startOffset;
			if (count < 0)
				return;
			data.Remove (startOffset, count);
			if (prevLine != null) {
				if (prevLineIsEmpty) {
					if (line.Length - data.Caret.Column - 1 > 0 && data.HasIndentationTracker) {
						data.InsertAtCaret (data.IndentationTracker.GetIndentationString (data.Caret.Offset));
					} else {
						data.Caret.Column = data.GetVirtualIndentationColumn (prevLine.Offset);
					}
				}
				data.FixVirtualIndentation ();
			}
		}
開發者ID:drasticactions,項目名稱:monodevelop,代碼行數:21,代碼來源:DeleteActions.cs


注:本文中的Mono.TextEditor.TextEditorData.GetVirtualIndentationColumn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。