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


C# IDocument.Remove方法代码示例

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


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

示例1: InsertCodeAtEnd

		/// <summary>
		/// Ensure that code is inserted correctly in {} code blocks - SD2-1180
		/// </summary>
		public override void InsertCodeAtEnd(DomRegion region, IDocument document, params AbstractNode[] nodes)
		{
			string beginLineIndentation = GetIndentation(document, region.BeginLine);
			int insertionLine = region.EndLine - 1;
			
			IDocumentLine endLine = document.GetLine(region.EndLine);
			string endLineText = endLine.Text;
			int originalPos = region.EndColumn - 2; // -1 for column coordinate => offset, -1 because EndColumn is after the '}'
			int pos = originalPos;
			if (pos >= endLineText.Length || endLineText[pos] != '}') {
				LoggingService.Warn("CSharpCodeGenerator.InsertCodeAtEnd: position is invalid (not pointing to '}')"
				                    + " endLineText=" + endLineText + ", pos=" + pos);
			} else {
				for (pos--; pos >= 0; pos--) {
					if (!char.IsWhiteSpace(endLineText[pos])) {
						// range before '}' is not empty: we cannot simply insert in the line before the '}', so
						// 
						pos++; // set pos to first whitespace character / the '{' character
						if (pos < originalPos) {
							// remove whitespace between last non-white character and the '}'
							document.Remove(endLine.Offset + pos, originalPos - pos);
						}
						// insert newline and same indentation as used in beginLine before the '}'
						document.Insert(endLine.Offset + pos, Environment.NewLine + beginLineIndentation);
						insertionLine++;
						
						pos = region.BeginColumn - 1;
						if (region.BeginLine == region.EndLine && pos >= 1 && pos < endLineText.Length) {
							// The whole block was in on a single line, e.g. "get { return field; }".
							// Insert an additional newline after the '{'.
							
							originalPos = pos = endLineText.IndexOf('{', pos);
							if (pos >= 0 && pos < region.EndColumn - 1) {
								// find next non-whitespace after originalPos
								originalPos++; // point to insertion position for newline after {
								for (pos++; pos < endLineText.Length; pos++) {
									if (!char.IsWhiteSpace(endLineText[pos])) {
										// remove all between originalPos and pos
										if (originalPos < pos) {
											document.Remove(endLine.Offset + originalPos, pos - originalPos);
										}
										document.Insert(endLine.Offset + originalPos, Environment.NewLine + beginLineIndentation + '\t');
										insertionLine++;
										break;
									}
								}
							}
						}
						break;
					}
				}
			}
			InsertCodeAfter(insertionLine, document, beginLineIndentation + this.Options.IndentString, nodes);
		}
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:57,代码来源:CSharpCodeGenerator.cs

示例2: SortLines

		public void SortLines(IDocument document, int startLine, int endLine, StringComparer comparer, bool removeDuplicates)
		{
			List<string> lines = new List<string>();
			for (int i = startLine; i <= endLine; ++i) {
				IDocumentLine line = document.GetLine(i);
				lines.Add(document.GetText(line.Offset, line.Length));
			}
			
			lines.Sort(comparer);
			
			if (removeDuplicates) {
				lines = lines.Distinct(comparer).ToList();
			}
			
			using (document.OpenUndoGroup()) {
				for (int i = 0; i < lines.Count; ++i) {
					IDocumentLine line = document.GetLine(startLine + i);
					document.Replace(line.Offset, line.Length, lines[i]);
				}
				
				// remove removed duplicate lines
				for (int i = startLine + lines.Count; i <= endLine; ++i) {
					IDocumentLine line = document.GetLine(startLine + lines.Count);
					document.Remove(line.Offset, line.TotalLength);
				}
			}
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:27,代码来源:SortSelectionCommand.cs

示例3: RemoveFieldDeclaration

		protected override void RemoveFieldDeclaration(IDocument document, IField field)
		{
			// In VB, the field region begins at the start of the declaration
			// and ends on the first column of the line following the declaration.
			int startOffset = document.PositionToOffset(field.Region.BeginLine, 1);
			int endOffset   = document.PositionToOffset(field.Region.EndLine, 1);
			document.Remove(startOffset, endOffset - startOffset);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:8,代码来源:VBNetDesignerGenerator.cs

示例4: Convert

		protected override void Convert(IDocument document, int y1, int y2) 
		{
			for (int i = y2 - 1; i >= y1; --i) {
				LineSegment line = document.GetLineSegment(i);
				int removeNumber = 0;
				for (int x = line.Offset + line.Length - 1; x >= line.Offset && Char.IsWhiteSpace(document.GetCharAt(x)); --x) {
					++removeNumber;
				}
				if (removeNumber > 0) {
					document.Remove(line.Offset + line.Length - removeNumber, removeNumber);
				}
			}
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:13,代码来源:FormatActions.cs

示例5: Convert

		protected override void Convert(IDocument document, int y1, int y2) 
		{
			int  redocounter = 0; // must count how many Delete operations occur
			for (int i = y1; i < y2; ++i) {
				LineSegment line = document.GetLineSegment(i);
				int removeNumber = 0;
				for (int x = line.Offset; x < line.Offset + line.Length && Char.IsWhiteSpace(document.GetCharAt(x)); ++x) {
					++removeNumber;
				}
				if (removeNumber > 0) {
					document.Remove(line.Offset, removeNumber);
					++redocounter; // count deletes
				}
			}
			if (redocounter > 0) {
				document.UndoStack.CombineLast(redocounter); // redo the whole operation (not the single deletes)
			}
		}
开发者ID:stophun,项目名称:fdotoolbox,代码行数:18,代码来源:FormatActions.cs

示例6: RemoveComment

 void RemoveComment(IDocument document, BlockCommentRegion commentRegion)
 {
     document.Remove(commentRegion.EndOffset, commentRegion.CommentEnd.Length);
     document.Remove(commentRegion.StartOffset, commentRegion.CommentStart.Length);
 }
开发者ID:KindDragon,项目名称:ICSharpCode.TextEditor.V4,代码行数:5,代码来源:MiscActions.cs

示例7: RemoveCommentAt

        void RemoveCommentAt(IDocument document, string comment, SelectionManager selmgr, int y1, int y2)
        {
            firstLine = y1;
            lastLine  = y2;

            for (int i = y2; i >= y1; --i)
            {
                LineSegment line = document.GetLineSegment(i);
                if (selmgr != null && i == y2 && line.Offset == selmgr.StartOffset + selmgr.Length)
                {
                    --lastLine;
                    continue;
                }

                string lineText = document.GetText(line.Offset, line.Length);
                if (lineText.Trim().StartsWith(comment))
                {
                    document.Remove(line.Offset + lineText.IndexOf(comment), comment.Length);
                }
            }
        }
开发者ID:KindDragon,项目名称:ICSharpCode.TextEditor.V4,代码行数:21,代码来源:MiscActions.cs

示例8: RemoveTabs

        void RemoveTabs(IDocument document, SelectionManager selmgr, int y1, int y2)
        {
            document.UndoStack.StartUndoGroup();
            for (int i = y2; i >= y1; --i)
            {
                LineSegment line = document.GetLineSegment(i);
                if (i == y2 && line.Offset == selmgr.EndOffset)
                {
                    continue;
                }
                if (line.Length > 0)
                {
                    /**** TextPad Strategy:
                    /// first convert leading whitespace to tabs (controversial! - not all editors work like this)
                    string newLine = TextUtilities.LeadingWhiteSpaceToTabs(document.GetText(line.Offset,line.Length),document.Properties.Get("TabIndent", 4));
                    if(newLine.Length > 0 && newLine[0] == '\t') {
                    	document.Replace(line.Offset,line.Length,newLine.Substring(1));
                    	++redocounter;
                    }
                    else if(newLine.Length > 0 && newLine[0] == ' ') {
                    	/// there were just some leading spaces but less than TabIndent of them
                    	int leadingSpaces = 1;
                    	for(leadingSpaces = 1; leadingSpaces < newLine.Length && newLine[leadingSpaces] == ' '; leadingSpaces++) {
                    		/// deliberately empty
                    	}
                    	document.Replace(line.Offset,line.Length,newLine.Substring(leadingSpaces));
                    	++redocounter;
                    }
                    /// else
                    /// there were no leading tabs or spaces on this line so do nothing
                    /// MS Visual Studio 6 strategy:
                     ****/
//					string temp = document.GetText(line.Offset,line.Length);

                    if (line.Length > 0)
                    {
                        int charactersToRemove = 0;
                        if(document.GetCharAt(line.Offset) == '\t')   // first character is a tab - just remove it
                        {
                            charactersToRemove = 1;
                        }
                        else if(document.GetCharAt(line.Offset) == ' ')
                        {
                            int leadingSpaces = 1;
                            int tabIndent = document.TextEditorProperties.IndentationSize;
                            for (leadingSpaces = 1; leadingSpaces < line.Length && document.GetCharAt(line.Offset + leadingSpaces) == ' '; leadingSpaces++)
                            {
                                // deliberately empty
                            }
                            if(leadingSpaces >= tabIndent)
                            {
                                // just remove tabIndent
                                charactersToRemove = tabIndent;
                            }
                            else if(line.Length > leadingSpaces && document.GetCharAt(line.Offset + leadingSpaces) == '\t')
                            {
                                // remove the leading spaces and the following tab as they add up
                                // to just one tab stop
                                charactersToRemove = leadingSpaces+1;
                            }
                            else
                            {
                                // just remove the leading spaces
                                charactersToRemove = leadingSpaces;
                            }
                        }

                        if (charactersToRemove > 0)
                        {
                            document.Remove(line.Offset,charactersToRemove);
                        }
                    }
                }
            }
            document.UndoStack.EndUndoGroup();
        }
开发者ID:KindDragon,项目名称:ICSharpCode.TextEditor.V4,代码行数:76,代码来源:MiscActions.cs

示例9: RemoveFieldDeclaration

		/// <summary>
		/// Removes a field declaration from the source code document.
		/// </summary>
		/// <remarks>
		/// The default implementation assumes that the field region starts at the very beginning
		/// of the line of the field declaration and ends at the end of that line.
		/// Override this method if that is not the case in a specific language.
		/// </remarks>
		protected virtual void RemoveFieldDeclaration(IDocument document, IField field)
		{
			int startOffset = document.PositionToOffset(field.Region.BeginLine, 1);
			int endOffset   = document.PositionToOffset(field.Region.EndLine + 1, 1);
			document.Remove(startOffset, endOffset - startOffset);
		}
开发者ID:TiberiuGal,项目名称:SharpDevelop,代码行数:14,代码来源:AbstractDesignerGenerator.cs

示例10: RemoveCommentAt

        void RemoveCommentAt(IDocument document, string comment, ISelection selection, int y1, int y2)
        {
            int  redocounter = 0;
            firstLine = y1;
            lastLine  = y2;

            for (int i = y2; i >= y1; --i) {
                LineSegment line = document.GetLineSegment(i);
                if (selection != null && i == y2 && line.Offset == selection.Offset + selection.Length) {
                    --lastLine;
                    continue;
                }

                string lineText = document.GetText(line.Offset, line.Length);
                if (lineText.Trim().StartsWith(comment)) {
                    document.Remove(line.Offset + lineText.IndexOf(comment), comment.Length);
                    ++redocounter;
                }
            }

            if (redocounter > 0) {
                document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
            }
        }
开发者ID:slluis,项目名称:monodevelop-prehistoric,代码行数:24,代码来源:MiscActions.cs

示例11: SortLines

		public void SortLines(IDocument document, int startLine, int endLine)
		{
			ArrayList lines = new ArrayList();
			for (int i = startLine; i <= endLine; ++i) {
				LineSegment line = document.GetLineSegment(i);
				lines.Add(document.GetText(line.Offset, line.Length));
			}
			
			lines.Sort(new SortComparer());
			
			bool removeDupes = PropertyService.Get(SortOptionsDialog.removeDupesOption, false);
			if (removeDupes) {
				for (int i = 0; i < lines.Count - 1; ++i) {
					if (lines[i].Equals(lines[i + 1])) {
						lines.RemoveAt(i);
						--i;
					}
				}
			}
			
			for (int i = 0; i < lines.Count; ++i) {
				LineSegment line = document.GetLineSegment(startLine + i);
				document.Replace(line.Offset, line.Length, lines[i].ToString());
			}
			
			// remove removed duplicate lines
			for (int i = startLine + lines.Count; i <= endLine; ++i) {
				LineSegment line = document.GetLineSegment(startLine + lines.Count);
				document.Remove(line.Offset, line.TotalLength);
			}
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:31,代码来源:FormatCommands.cs

示例12: Convert

    /// <summary>
    /// Formats the specified lines.
    /// </summary>
    /// <param name="document">The document.</param>
    /// <param name="startLine">The start line.</param>
    /// <param name="endLine">The end line.</param>
    /// <remarks>
    /// This method is called for all selections in the document.
    /// </remarks>
    protected override void Convert(IDocument document, int startLine, int endLine)
    {
      for (int i = endLine - 1; i >= startLine; --i)
      {
        LineSegment line = document.GetLineSegment(i);

        int removeNumber = 0;
        for (int x = line.Offset + line.Length - 1; x >= line.Offset && Char.IsWhiteSpace(document.GetCharAt(x)); --x)
          ++removeNumber;

        if (removeNumber > 0)
        {
          document.Remove(line.Offset + line.Length - removeNumber, removeNumber);
        }
      }
    }
开发者ID:sanyaade-fintechnology,项目名称:SquareOne,代码行数:25,代码来源:FormatActions.cs

示例13: RemoveTabs

        static void RemoveTabs(IDocument document, ISelection selection, int y1, int y2)
        {
            document.UndoStack.StartUndoGroup();
              for (int i = y2; i >= y1; --i)
              {
            LineSegment line = document.GetLineSegment(i);
            if (i == y2 && line.Offset == selection.EndOffset)
              continue;

            if (line.Length > 0)
            {
              if (line.Length > 0)
              {
            int charactersToRemove = 0;
            if (document.GetCharAt(line.Offset) == '\t')
            {
              // first character is a tab - just remove it
              charactersToRemove = 1;
            }
            else if (document.GetCharAt(line.Offset) == ' ')
            {
              int leadingSpaces;
              int tabIndent = document.TextEditorProperties.IndentationSize;
              for (leadingSpaces = 1; leadingSpaces < line.Length && document.GetCharAt(line.Offset + leadingSpaces) == ' '; leadingSpaces++)
              {
                // deliberately empty
              }
              if (leadingSpaces >= tabIndent)
              {
                // just remove tabIndent
                charactersToRemove = tabIndent;
              }
              else if (line.Length > leadingSpaces && document.GetCharAt(line.Offset + leadingSpaces) == '\t')
              {
                // remove the leading spaces and the following tab as they add up
                // to just one tab stop
                charactersToRemove = leadingSpaces + 1;
              }
              else
              {
                // just remove the leading spaces
                charactersToRemove = leadingSpaces;
              }
            }
            if (charactersToRemove > 0)
            {
              document.Remove(line.Offset, charactersToRemove);
            }
              }
            }
              }
              document.UndoStack.EndUndoGroup();
        }
开发者ID:cavaliercoder,项目名称:expression-lab,代码行数:53,代码来源:MiscActions.cs

示例14: RemoveTabs

		void RemoveTabs(IDocument document, ISelection selection, int y1, int y2) 
		{
			int  redocounter = 0;
			for (int i = y2; i >= y1; --i) {
				LineSegment line = document.GetLineSegment(i);
				if (i == y2 && line.Offset == selection.EndOffset) {
					continue;
				}
				if (line.Length > 0) 
				{

					int charactersToRemove = 0;
					if(document.GetCharAt(line.Offset) == '\t') 
					{ // first character is a tab - just remove it
						charactersToRemove = 1;
					} 
					else if(document.GetCharAt(line.Offset) == ' ') 
					{
						int leadingSpaces = 1;
						int tabIndent = document.TextEditorProperties.TabIndent;
						for (leadingSpaces = 1; leadingSpaces < line.Length && document.GetCharAt(line.Offset + leadingSpaces) == ' '; leadingSpaces++) 
						{
							// deliberately empty
						}
						if(leadingSpaces >= tabIndent) 
						{
							// just remove tabIndent
							charactersToRemove = tabIndent;
						}
						else if(line.Length > leadingSpaces && document.GetCharAt(line.Offset + leadingSpaces) == '\t') 
						{
							// remove the leading spaces and the following tab as they add up
							// to just one tab stop
							charactersToRemove = leadingSpaces+1;
						}
						else 
						{
							// just remove the leading spaces
							charactersToRemove = leadingSpaces;
						}
					}
					if (charactersToRemove > 0) 
					{
						document.Remove(line.Offset,charactersToRemove);
						++redocounter;
					}
					
				}
			}
			
			if (redocounter > 0) {
				document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
			}
		}
开发者ID:tangxuehua,项目名称:DataStructure,代码行数:54,代码来源:MiscActions.cs


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