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


C# IDocument.GetOffset方法代码示例

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


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

示例1: Create

		public static SearchResultMatch Create(IDocument document, TextLocation startLocation, TextLocation endLocation, IHighlighter highlighter)
		{
			int startOffset = document.GetOffset(startLocation);
			int endOffset = document.GetOffset(endLocation);
			var inlineBuilder = SearchResultsPad.CreateInlineBuilder(startLocation, endLocation, document, highlighter);
			var defaultTextColor = highlighter.DefaultTextColor;
			return new SearchResultMatch(FileName.Create(document.FileName),
			                             startLocation, endLocation,
			                             startOffset, endOffset - startOffset,
			                             inlineBuilder, defaultTextColor);
		}
开发者ID:asiazhang,项目名称:SharpDevelop,代码行数:11,代码来源:SearchResultMatch.cs

示例2: AttachTo

		internal void AttachTo(IDocument document)
		{
			if (isDeleted)
				return;
			Debug.Assert(currentDocument == null && document != null);
			this.currentDocument = document;
			line = Math.Min(line, document.LineCount);
			column = Math.Min(column, document.GetLineByNumber(line).Length + 1);
			baseAnchor = document.CreateAnchor(document.GetOffset(line, column));
			baseAnchor.MovementType = movementType;
			baseAnchor.SurviveDeletion = surviveDeletion;
			baseAnchor.Deleted += baseAnchor_Deleted;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:13,代码来源:PermanentAnchor.cs

示例3: TryFix

		public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
		{
			var typeDeclaration = syntaxTree.GetNodeAt<DelegateDeclaration>(location); 
			if (typeDeclaration != null) {
				if (typeDeclaration.RParToken.IsNull) {
					var lastNode = GetLastNonErrorChild (typeDeclaration);
					if (lastNode == null)
						return false;
					var insertionOffset = document.GetOffset(lastNode.EndLocation);
					document.Insert(insertionOffset, ");\n");
					newOffset += ");\n".Length;
					return true;
				}
			}
			return false;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:16,代码来源:ConstructFixer.cs

示例4: Insert

		public void Insert (IDocument document, string text)
		{
			int offset = document.GetOffset (Location);
			using (var undo = document.OpenUndoGroup ()) {
				text = DocumentUtilities.NormalizeNewLines(text, document, Location.Line);
				
				var line = document.GetLineByOffset (offset);
				int insertionOffset = line.Offset + Location.Column - 1;
				offset = insertionOffset;
				InsertNewLine (document, LineBefore, ref offset);
				
				document.Insert (offset, text);
				offset += text.Length;
				InsertNewLine (document, LineAfter, ref offset);
			}
		}
开发者ID:RHE24,项目名称:SharpDevelop,代码行数:16,代码来源:InsertionPoint.cs

示例5:

        public static QuickFix ForFirstLineInRegion
            (DomRegion region, IDocument document) {
            // Note that we could display an arbitrary amount of
            // context to the user: ranging from one line to tens,
            // hundreds..
            var text = document.GetText
                ( offset: document.GetOffset(region.BeginLine, column: 0)
                , length: document.GetLineByNumber
                            (region.BeginLine).Length)
                .Trim();

            return new QuickFix
                { FileName = region.FileName
                , Line     = region.BeginLine
                , Column   = region.BeginColumn
                , Text     = text};
        }
开发者ID:sphynx79,项目名称:dotfiles,代码行数:17,代码来源:QuickFix.cs

示例6: InsertWithCursorOnLayer

		void InsertWithCursorOnLayer(EditorScript currentScript, InsertionCursorLayer layer, TaskCompletionSource<Script> tcs, IList<AstNode> nodes, IDocument target)
		{
			var doc = target as TextDocument;
			var op = new UndoOperation(layer, tcs);
			if (doc != null) {
				doc.UndoStack.Push(op);
			}
			layer.Exited += delegate(object s, InsertionCursorEventArgs args) {
				doc.UndoStack.StartContinuedUndoGroup();
				try {
					if (args.Success) {
						if (args.InsertionPoint.LineAfter == NewLineInsertion.None &&
						    args.InsertionPoint.LineBefore == NewLineInsertion.None && nodes.Count > 1) {
							args.InsertionPoint.LineAfter = NewLineInsertion.BlankLine;
						}
						foreach (var node in nodes.Reverse ()) {
							int indentLevel = currentScript.GetIndentLevelAt(target.GetOffset(args.InsertionPoint.Location));
							var output = currentScript.OutputNode(indentLevel, node);
							var offset = target.GetOffset(args.InsertionPoint.Location);
							var delta = args.InsertionPoint.Insert(target, output.Text);
							output.RegisterTrackedSegments(currentScript, delta + offset);
						}
						tcs.SetResult(currentScript);
					}
					layer.Dispose();
					DisposeOnClose();
				} finally {
					doc.UndoStack.EndUndoGroup();
				}
				op.Reset();
			};
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:32,代码来源:EditorScript.cs

示例7: CreateProvider

		static CompletionDataList CreateProvider (CSharpCompletionEngine engine, IDocument doc, TextLocation loc)
		{
			var cursorPosition = doc.GetOffset (loc);
			
			var data = engine.GetCompletionData (cursorPosition, true);
			
			return new CompletionDataList {
				Data = data,
				AutoCompleteEmptyMatch = engine.AutoCompleteEmptyMatch,
				AutoSelect = engine.AutoSelect,
				DefaultCompletionString = engine.DefaultCompletionString
			};
		}
开发者ID:furesoft,项目名称:NRefactory,代码行数:13,代码来源:CodeCompletionBugTests.cs

示例8: ExtendSelectionToEndOfLineComments

		/// <summary>
		/// If there is a comment block behind selection on the same line ("var i = 5; // comment"), add it to selection.
		/// </summary>
		Selection ExtendSelectionToEndOfLineComments(IDocument document, TextLocation selectionStart, TextLocation selectionEnd, IEnumerable<AstNode> commentsBlankLines)
		{
			var lineComment = commentsBlankLines.FirstOrDefault(c => c.StartLocation.Line == selectionEnd.Line && c.StartLocation >= selectionEnd);
			if (lineComment == null) {
				return null;
			}
//			bool isWholeLineSelected = IsWhitespaceBetween(document, new TextLocation(selectionStart.Line, 1), selectionStart);
//			if (!isWholeLineSelected) {
//				// whole line must be selected before we add the comment
//				return null;
//			}
			int endPos = document.GetOffset(lineComment.EndLocation);
			return new Selection { Start = selectionStart, End = document.GetLocation(endPos) };
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:17,代码来源:CodeManipulation.cs

示例9: InsertWithCursorOnLayer

		void InsertWithCursorOnLayer(EditorScript currentScript, InsertionCursorLayer layer, TaskCompletionSource<Script> tcs, IList<AstNode> nodes, IDocument target)
		{
			layer.Exited += delegate(object s, InsertionCursorEventArgs args) {
				if (args.Success) {
					if (args.InsertionPoint.LineAfter == NewLineInsertion.None &&
					    args.InsertionPoint.LineBefore == NewLineInsertion.None && nodes.Count > 1) {
						args.InsertionPoint.LineAfter = NewLineInsertion.BlankLine;
					}
					foreach (var node in nodes.Reverse ()) {
						int indentLevel = currentScript.GetIndentLevelAt(target.GetOffset(args.InsertionPoint.Location));
						var output = currentScript.OutputNode(indentLevel, node);
						var offset = target.GetOffset(args.InsertionPoint.Location);
						var delta = args.InsertionPoint.Insert(target, output.Text);
						output.RegisterTrackedSegments(currentScript, delta + offset);
					}
					tcs.SetResult(currentScript);
				}
				layer.Dispose();
				DisposeOnClose();
			};
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:21,代码来源:EditorScript.cs

示例10: GetInsertionPoints

		public static List<InsertionPoint> GetInsertionPoints (IDocument document, IUnresolvedTypeDefinition type)
		{
			if (type == null)
				throw new ArgumentNullException ("type");
			
			// update type from parsed document, since this is always newer.
			//type = parsedDocument.GetInnermostTypeDefinition (type.GetLocation ()) ?? type;
			
			List<InsertionPoint> result = new List<InsertionPoint> ();
			int offset = document.GetOffset (type.Region.Begin);
			if (offset < 0)
				return result;
			while (offset < document.TextLength && document.GetCharAt (offset) != '{') {
				offset++;
			}
			
			var realStartLocation = document.GetLocation (offset);
			result.Add (GetInsertionPosition (document, realStartLocation.Line, realStartLocation.Column));
			result [0].LineBefore = NewLineInsertion.None;
			
			foreach (var member in type.Members) {
				TextLocation domLocation = member.BodyRegion.End;
				if (domLocation.Line <= 0) {
					domLocation = member.Region.End;
				}
				result.Add (GetInsertionPosition (document, domLocation.Line, domLocation.Column));
			}
			result [result.Count - 1].LineAfter = NewLineInsertion.None;
			CheckStartPoint (document, result [0], result.Count == 1);
			if (result.Count > 1) {
				result.RemoveAt (result.Count - 1);
				NewLineInsertion insertLine;
				var lineBefore = GetLineOrNull(document, type.BodyRegion.EndLine - 1);
				if (lineBefore != null && lineBefore.Length == GetLineIndent(document, lineBefore).Length) {
					insertLine = NewLineInsertion.None;
				} else {
					insertLine = NewLineInsertion.Eol;
				}
				// search for line start
				var line = document.GetLineByNumber (type.BodyRegion.EndLine);
				int col = type.BodyRegion.EndColumn - 1;
				while (col > 1 && char.IsWhiteSpace (document.GetCharAt (line.Offset + col - 2)))
					col--;
				result.Add (new InsertionPoint (new TextLocation (type.BodyRegion.EndLine, col), insertLine, NewLineInsertion.Eol));
				CheckEndPoint (document, result [result.Count - 1], result.Count == 1);
			}
			
			/*foreach (var region in parsedDocument.UserRegions.Where (r => type.BodyRegion.IsInside (r.Region.Begin))) {
				result.Add (new InsertionPoint (new DocumentLocation (region.Region.BeginLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
				result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
				result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
			}*/
			result.Sort ((left, right) => left.Location.CompareTo (right.Location));
			return result;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:55,代码来源:InsertionPoint.cs

示例11: SwapText

		/// <summary>
		/// Swaps 2 ranges of text in a document.
		/// </summary>
		void SwapText(IDocument document, TextLocation start1, TextLocation end1, TextLocation start2, TextLocation end2)
		{
			if (start1 > start2) {
				TextLocation sw;
				sw = start1; start1 = start2; start2 = sw;
				sw = end1; end1 = end2; end2 = sw;
			}
			if (end1 >= start2)
				throw new InvalidOperationException("Cannot swap overlaping segments");
			int offset1 = document.GetOffset(start1);
			int len1 = document.GetOffset(end1) - offset1;
			int offset2 = document.GetOffset(start2);
			int len2 = document.GetOffset(end2) - offset2;
			
			string text1 = document.GetText(offset1, len1);
			string text2 = document.GetText(offset2, len2);
			
			using (var undoGroup = document.OpenUndoGroup()) {
				document.Replace(offset2, len2, text1);
				document.Replace(offset1, len1, text2);
			}
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:25,代码来源:CodeManipulation.cs

示例12: ExtendLeft

		/// <summary>
		/// If the text at startPos is preceded by any of the prefixes, moves the start backwards to include one prefix
		/// (the rightmost one).
		/// </summary>
		TextLocation ExtendLeft(TextLocation startPos, IDocument document, params String[] prefixes)
		{
			int startOffset = document.GetOffset(startPos);
			foreach (string prefix in prefixes) {
				if (startOffset < prefix.Length) continue;
				string realPrefix = document.GetText(startOffset - prefix.Length, prefix.Length);
				if (realPrefix == prefix) {
					return document.GetLocation(startOffset - prefix.Length);
				}
			}
			// no prefixes -> do not extend
			return startPos;
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:17,代码来源:CodeManipulation.cs

示例13: IsWhitespaceBetween

		bool IsWhitespaceBetween(IDocument document, TextLocation startPos, TextLocation endPos)
		{
			int startOffset = document.GetOffset(startPos);
			int endOffset = document.GetOffset(endPos);
			if (startOffset > endOffset) {
				throw new ArgumentException("Invalid range for (startPos, endPos)");
			}
			return string.IsNullOrWhiteSpace(document.GetText(startOffset, endOffset - startOffset));
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:9,代码来源:CodeManipulation.cs

示例14: GetEndOffset

 static int GetEndOffset(IDocument document, DomRegion region)
 {
     if (region.EndLine < 1)
         return 0;
     if (region.EndLine > document.LineCount)
         return document.TextLength;
     return document.GetOffset(region.End);
 }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:8,代码来源:ParseInformation.cs

示例15: CopyFileHeader

		string CopyFileHeader(IDocument document, CSharpFullParseInformation info)
		{
			var lastHeadNode = info.SyntaxTree.Children
				.TakeWhile(node => node.NodeType == NodeType.Whitespace && (!(node is Comment) || !((Comment)node).IsDocumentation))
				.LastOrDefault();
			if (lastHeadNode == null)
				return "";
			return document.GetText(0, document.GetOffset(lastHeadNode.EndLocation));
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:9,代码来源:MoveTypeToFileContextAction.cs


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