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


C# IDocument.GetLineSegmentForOffset方法代码示例

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


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

示例1: FindWordEnd

        static int FindWordEnd(IDocument document, int offset)
        {
            LineSegment line = document.GetLineSegmentForOffset(offset);
              int endPos = line.Offset + line.Length;
              offset = Math.Min(offset, endPos - 1);

              if (IsSelectableChar(document.GetCharAt(offset)))
              {
            while (offset < endPos && IsSelectableChar(document.GetCharAt(offset)))
            {
              ++offset;
            }
              }
              else if (Char.IsWhiteSpace(document.GetCharAt(offset)))
              {
            if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1)))
            {
              while (offset < endPos && Char.IsWhiteSpace(document.GetCharAt(offset)))
              {
            ++offset;
              }
            }
              }
              else
              {
            return Math.Max(0, offset + 1);
              }

              return offset;
        }
开发者ID:cavaliercoder,项目名称:expression-lab,代码行数:30,代码来源:TextAreaMouseHandler.cs

示例2: FindWordEnd

        public static int FindWordEnd(IDocument document, int offset)
        {
            LineSegment line   = document.GetLineSegmentForOffset(offset);
            int     endPos = line.Offset + line.Length;
            while (offset < endPos && IsLetterDigitOrUnderscore(document.GetCharAt(offset))) {
                ++offset;
            }

            return offset;
        }
开发者ID:umabiel,项目名称:WsdlUI,代码行数:10,代码来源:TextUtilities.cs

示例3: FindNext

        static int FindNext(IDocument document, int offset, char ch)
        {
            LineSegment line = document.GetLineSegmentForOffset(offset);
              int endPos = line.Offset + line.Length;

              while (offset < endPos && document.GetCharAt(offset) != ch)
            ++offset;

              return offset;
        }
开发者ID:cavaliercoder,项目名称:expression-lab,代码行数:10,代码来源:TextAreaMouseHandler.cs

示例4: FindNextWordStart

        // go forward to the start of the next word
        // if the cursor is at the start or in the middle of a word we move to the end of the word
        // and then past any whitespace that follows it
        // if the cursor is at the start or in the middle of some whitespace we move to the start of the
        // next word
        public static int FindNextWordStart(IDocument document, int offset)
        {
            LineSegment line   = document.GetLineSegmentForOffset(offset);
            int     endPos = line.Offset + line.Length;
            // lets go to the end of the word, whitespace or operator
            CharacterType t = GetCharacterType(document.GetCharAt(offset));
            while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == t) {
                ++offset;
            }

            // now we're at the end of the word, lets find the start of the next one by skipping whitespace
            while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == CharacterType.WhiteSpace) {
                ++offset;
            }

            return offset;
        }
开发者ID:umabiel,项目名称:WsdlUI,代码行数:22,代码来源:TextUtilities.cs

示例5: FindPrevWordStart

        // go back to the start of the word we are on
        // if we are already at the start of a word or if we are in whitespace, then go back
        // to the start of the previous word
        public static int FindPrevWordStart(IDocument document, int offset)
        {
            if (offset > 0) {
                LineSegment line = document.GetLineSegmentForOffset(offset);
                CharacterType t = GetCharacterType(document.GetCharAt(offset - 1));
                while (offset > line.Offset && GetCharacterType(document.GetCharAt(offset - 1)) == t) {
                    --offset;
                }

                // if we were in whitespace, and now we're at the end of a word or operator, go back to the beginning of it
                if(t == CharacterType.WhiteSpace && offset > line.Offset) {
                    t = GetCharacterType(document.GetCharAt(offset - 1));
                    while (offset > line.Offset && GetCharacterType(document.GetCharAt(offset - 1)) == t) {
                        --offset;
                    }
                }
            }

            return offset;
        }
开发者ID:umabiel,项目名称:WsdlUI,代码行数:23,代码来源:TextUtilities.cs

示例6: FindWordStart

		int FindWordStart(IDocument document, int offset)
		{
			LineSegment line = document.GetLineSegmentForOffset(offset);
			
			if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1)) && Char.IsWhiteSpace(document.GetCharAt(offset))) {
				while (offset > line.Offset && Char.IsWhiteSpace(document.GetCharAt(offset - 1))) {
					--offset;
				}
			} else  if (IsSelectableChar(document.GetCharAt(offset)) || (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset)) && IsSelectableChar(document.GetCharAt(offset - 1))))  {
				while (offset > line.Offset && IsSelectableChar(document.GetCharAt(offset - 1))) {
					--offset;
				}
			} else {
				if (offset > 0 && !Char.IsWhiteSpace(document.GetCharAt(offset - 1)) && !IsSelectableChar(document.GetCharAt(offset - 1)) ) {
					return Math.Max(0, offset - 1);
				}
			}
			return offset;
		}
开发者ID:tangxuehua,项目名称:DataStructure,代码行数:19,代码来源:TextAreaMouseHandler.cs

示例7: FindWordStart

		public static int FindWordStart(IDocument document, int offset)
		{
			LineSegment line = document.GetLineSegmentForOffset(offset);
			int lineOffset = line.Offset;
			while (offset > lineOffset && IsLetterDigitOrUnderscore(document.GetCharAt(offset - 1))) {
				--offset;
			}
			
			return offset;
		}
开发者ID:kurniawirawan,项目名称:ICSharpCode.TextEditor,代码行数:10,代码来源:TextUtilities.cs

示例8: FindNextWordStart

    /// <summary>
    /// Finds the offset where the next word starts.
    /// </summary>
    /// <param name="document">The document.</param>
    /// <param name="offset">The offset.</param>
    /// <returns>The start of the next word after <paramref name="offset"/>.</returns>
    public static int FindNextWordStart(IDocument document, int offset)
    {
      // go forward to the start of the next word
      // if the cursor is at the start or in the middle of a word we move to the end of the word
      // and then past any whitespace that follows it
      // if the cursor is at the start or in the middle of some whitespace we move to the start of the
      // next word

      int originalOffset = offset;
      LineSegment line = document.GetLineSegmentForOffset(offset);
      int endPos = line.Offset + line.Length;
      // lets go to the end of the word, whitespace or operator
      CharacterType t = GetCharacterType(document.GetCharAt(offset));
      while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == t)
      {
        ++offset;
      }

      // now we're at the end of the word, lets find the start of the next one by skipping whitespace
      while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == CharacterType.WhiteSpace)
      {
        ++offset;
      }

      return offset;
    }
开发者ID:Finarch,项目名称:DigitalRune.Windows.TextEditor,代码行数:32,代码来源:TextUtilities.cs

示例9: SkipComment

    /// <summary>
    /// Skips any comments that start at the current offset.
    /// </summary>
    /// <param name="document">The document.</param>
    /// <param name="offset">The offset.</param>
    /// <returns>The index of the next character after the comments.</returns>
    private static int SkipComment(IDocument document, int offset)
    {
      if (offset >= document.TextLength - 1)
        return offset + 1;

      char current = document.GetCharAt(offset);
      char next = document.GetCharAt(offset + 1);

      if (current == '/' && next == '/')
      {
        // Skip line comment "//"
        LineSegment line = document.GetLineSegmentForOffset(offset);
        int offsetOfNextLine = line.Offset + line.TotalLength;
        return offsetOfNextLine;
      }
      else if (current == '/' && next == '*')
      {
        // Skip block comment "/* ... */"
        offset += 2;
        while (offset + 1 < document.TextLength)
        {
          if (document.GetCharAt(offset) == '*' && document.GetCharAt(offset + 1) == '/')
          {
            offset = offset + 2;
            break;
          }
          offset++;
        }
        return offset;
      }
      else
      {
        return offset + 1;
      }
    }
开发者ID:sanyaade-fintechnology,项目名称:SquareOne,代码行数:41,代码来源:CSharpFoldingStrategy.cs

示例10: MarkRegion

    /// <summary>
    /// Marks the region that starts at the given offset.
    /// </summary>
    /// <param name="document">The document.</param>
    /// <param name="offset">The offset.</param>
    /// <param name="folds">The fold markers.</param>
    /// <returns>The index of the next character after the region.</returns>
    private static int MarkRegion(IDocument document, int offset, List<Fold> folds)
    {
      if (offset >= document.TextLength)
        return offset;

      if (document.GetCharAt(offset) == '#')
      {
        int startOffset = offset;
        offset++;
        string word = TextHelper.GetIdentifierAt(document, offset);
        if (word == "region")
        {
          offset += "region".Length;

          // Find label
          LineSegment line = document.GetLineSegmentForOffset(offset);
          int lineEnd = line.Offset + line.Length;
          int labelLength = lineEnd - offset;
          string label = document.GetText(offset, labelLength);
          label = label.Trim();
          if (label.Length == 0)
            label = "#region";

          // Find and mark subregions
          offset = FindAndMarkRegions(document, lineEnd, folds);

          if (offset <= document.TextLength)          
          {
            int length = offset - startOffset;
            folds.Add(new Fold(document, startOffset, length, label, true));
            offset++;
          }
        }
      }
      else
      {
        offset++;
      }
      return offset;
    }
开发者ID:sanyaade-fintechnology,项目名称:SquareOne,代码行数:47,代码来源:CSharpFoldingStrategy.cs

示例11: FindPrevWordStart

    /// <summary>
    /// Finds the start offset the word at or before the specified offset.
    /// </summary>
    /// <param name="document">The document.</param>
    /// <param name="offset">The offset.</param>
    /// <returns>The start of the word before <paramref name="offset"/>.</returns>
    public static int FindPrevWordStart(IDocument document, int offset)
    {
      // go back to the start of the word we are on
      // if we are already at the start of a word or if we are in whitespace, then go back
      // to the start of the previous word

      if (offset > 0)
      {
        LineSegment line = document.GetLineSegmentForOffset(offset);
        CharacterType charType = GetCharacterType(document.GetCharAt(offset - 1));
        int lineOffset = line.Offset;
        while (offset > lineOffset && GetCharacterType(document.GetCharAt(offset - 1)) == charType)
          --offset;

        // if we were in whitespace, and now we're at the end of a word or operator, go back to the beginning of it
        if (charType == CharacterType.WhiteSpace && offset > lineOffset)
        {
          charType = GetCharacterType(document.GetCharAt(offset - 1));
          while (offset > lineOffset && GetCharacterType(document.GetCharAt(offset - 1)) == charType)
            --offset;
        }
      }

      return offset;
    }
开发者ID:sanyaade-fintechnology,项目名称:SquareOne,代码行数:31,代码来源:TextHelper.cs

示例12: FindEndOfIdentifier

    /// <summary>
    /// Finds the end of the identifier at the given offset.
    /// </summary>
    /// <param name="document">The document.</param>
    /// <param name="offset">The offset.</param>
    /// <returns>
    /// The offset of the last character of the identifier; or -1 if there is no
    /// identifier at the specified offset.
    /// </returns>
    /// <remarks>
    /// <para>
    /// An identifier is a single word consisting of letters, digits, or underscores.
    /// An identifier must start with a letter or underscore.
    /// </para>
    /// <para>
    /// <strong>Important: </strong>This method does not guarantee that the word
    /// at <paramref name="offset"/> is an identifier - it could also be a number instead of
    /// an identifier. To make sure that the current word is really an identifier, you should 
    /// search for the start of the identifier and check whether it starts with a letter or 
    /// underscore.
    /// </para>
    /// </remarks>
    public static int FindEndOfIdentifier(IDocument document, int offset)
    {
      if (!IsPartOfIdentifier(document.GetCharAt(offset)))
      {
        // Character at offset is does not belong to an identifier.
        return -1;
      }

      // Search forward
      LineSegment line = document.GetLineSegmentForOffset(offset);
      int lineEnd = line.Offset + line.Length;
      while (offset + 1 < lineEnd && IsPartOfIdentifier(document.GetCharAt(offset + 1)))
        ++offset;

      return offset;
    }
开发者ID:sanyaade-fintechnology,项目名称:SquareOne,代码行数:38,代码来源:TextHelper.cs

示例13: FindStartOfIdentifier

    /// <summary>
    /// Finds the start of the identifier at the given offset.
    /// </summary>
    /// <param name="document">The document.</param>
    /// <param name="offset">The offset.</param>
    /// <returns>
    /// The offset of the first character of the identifier; or -1 if there is no
    /// identifier at the specified offset.
    /// </returns>
    /// <remarks>
    /// <para>
    /// An identifier is a single word consisting of letters, digits, or underscores.
    /// An identifier must start with a letter or underscore.
    /// </para>
    /// </remarks>
    public static int FindStartOfIdentifier(IDocument document, int offset)
    {
      if (offset < 0 || document.TextLength <= offset)
        return -1;

      if (!IsPartOfIdentifier(document.GetCharAt(offset)))
      {
        // Character at offset is does not belong to an identifier.
        return -1;
      }

      // Search backwards
      LineSegment line = document.GetLineSegmentForOffset(offset);
      int lineOffset = line.Offset;
      while (offset > lineOffset && IsPartOfIdentifier(document.GetCharAt(offset - 1)))
        --offset;

      // Check if first character is the start of an identifier.
      // (We need to make sure that it is not a number.)
      char startCharacter = document.GetCharAt(offset);
      if (Char.IsLetter(startCharacter) || startCharacter == '_')
        return offset;
      else
        return -1;
    }
开发者ID:sanyaade-fintechnology,项目名称:SquareOne,代码行数:40,代码来源:TextHelper.cs


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