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


C# IVsTextView.SetSelection方法代码示例

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


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

示例1: UnCommentSelection

    public virtual void UnCommentSelection(IVsTextView textView) {
      CCITracing.TraceCall();

      //get text range
      TextSpan[] aspan = new TextSpan[1];
      textView.GetSelectionSpan(aspan);
      TextSpan span = aspan[0];

      //check bounds
      if (span.iEndIndex == 0) span.iEndLine--;

      //get line lengths
      int startLen,endLen;

      this.textLines.GetLengthOfLine( span.iStartLine, out startLen );
      this.textLines.GetLengthOfLine( span.iEndLine, out endLen );

      // adjust end index if necessary
      if (span.iEndIndex == 0) span.iEndIndex = endLen;

      int adjustment = 0;

      // is block comment selected?
      if (this.commentInfo.blockStart != null && this.commentInfo.blockEnd != null) {

        // TODO: this doesn't work if the selection contains a mix of code and block comments
        // or multiple block comments!!  We should use our parse tree to find the embedded 
        // comments and uncomment the resulting comment spans only.

        string startText = null;
        this.textLines.GetLineText( span.iStartLine, span.iStartIndex, span.iStartLine, span.iStartIndex+this.commentInfo.blockStart.Length, out startText );

        if (startText == this.commentInfo.blockStart) {
          string endText = null;
          this.textLines.GetLineText( span.iEndLine, span.iEndIndex- this.commentInfo.blockEnd.Length, span.iEndLine, span.iEndIndex, out endText );

          if (endText == this.commentInfo.blockEnd) {
            //yes, block comment selected; remove it        
            this.textLines.ReplaceLines( span.iEndLine, span.iEndIndex-this.commentInfo.blockEnd.Length, span.iEndLine, span.iEndIndex, null, 0, null);       
            this.textLines.ReplaceLines( span.iStartLine, span.iStartIndex, span.iStartLine, span.iStartIndex+this.commentInfo.blockStart.Length, null, 0, null);
  
            adjustment = - commentInfo.blockEnd.Length;
            if (span.iStartLine == span.iEndLine) adjustment -= commentInfo.blockStart.Length;
 
            goto end;
          }
        }
      }

      //if no line comment possible, we are done
      if (!this.commentInfo.useLineComments) 
        NativeHelpers.RaiseComError(HResult.S_FALSE);
  
      // try if we can remove line comments, using the scanner to find them
      for (int line = span.iStartLine; line <= span.iEndLine; line++) {

        TokenInfo[] lineInfo = this.colorizer.GetLineInfo(line, this.colorState);

        for (int i = 0, n = lineInfo.Length; i<n; i++) {
          if (lineInfo[i].type == TokenType.LineComment) {            
            this.textLines.ReplaceLines(line, lineInfo[i].startIndex, line, lineInfo[i].startIndex+this.commentInfo.lineStart.Length, null, 0, null);
            if (line == span.iEndLine) {
              adjustment = - this.commentInfo.lineStart.Length;
            }
          }
        }
      }

      end:
        if (TextSpanHelper.TextSpanPositive(span))
          textView.SetSelection( span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex + adjustment );
        else
          textView.SetSelection( span.iEndLine, span.iEndIndex + adjustment, span.iStartLine, span.iStartIndex );
    }
开发者ID:hesam,项目名称:SketchSharp,代码行数:74,代码来源:Source.cs

示例2: OnTypeChar

        public void OnTypeChar(IVsTextView pView, string ch)
        {
            if (ch == "{")
            {
                // add a closing "}" if it makes a complete expression or condition where one doesn't exist otherwise

                _TextSpan selection;
                pView.GetSelectionSpan(out selection);

                IVsTextLines buffer;
                pView.GetBuffer(out buffer);

                string before;
                buffer.GetLineText(0, 0, selection.iStartLine, selection.iStartIndex, out before);

                int iLastLine, iLastColumn;
                buffer.GetLastLineIndex(out iLastLine, out iLastColumn);

                string after;
                buffer.GetLineText(selection.iEndLine, selection.iEndIndex, iLastLine, iLastColumn, out after);

                var existingResult = _grammar.Nodes(new Position(new SourceContext(before + ch + after)));
                var expressionHits = existingResult.Rest.GetPaint()
                    .OfType<Paint<Node>>()
                    .Where(p => p.Begin.Offset <= before.Length && before.Length <= p.End.Offset && (p.Value is ExpressionNode || p.Value is ConditionNode));

                // if a node exists normally, do nothing
                if (expressionHits.Count() != 0)
                    return;

                var withCloseResult = _grammar.Nodes(new Position(new SourceContext(before + ch + "}" + after)));
                var withCloseHits = withCloseResult.Rest.GetPaint()
                    .OfType<Paint<Node>>()
                    .Where(p => p.Begin.Offset <= before.Length && before.Length <= p.End.Offset && (p.Value is ExpressionNode || p.Value is ConditionNode));

                // if a close brace doesn't cause a node to exist, do nothing
                if (withCloseHits.Count() == 0)
                    return;

                // add a closing } after the selection, then set the selection back to what it was
                int iAnchorLine, iAnchorCol, iEndLine, iEndCol;
                pView.GetSelection(out iAnchorLine, out iAnchorCol, out iEndLine, out iEndCol);
                _TextSpan inserted;
                buffer.ReplaceLines(selection.iEndLine, selection.iEndIndex, selection.iEndLine, selection.iEndIndex, "}", 1, out inserted);
                pView.SetSelection(iAnchorLine, iAnchorCol, iEndLine, iEndCol);
            }
        }
开发者ID:ronniebarker,项目名称:spark,代码行数:47,代码来源:SourceSupervisor.cs

示例3: CommentSelection

    // Special View filter command handling.
    public virtual void CommentSelection(IVsTextView textView) {
      CCITracing.TraceCall();

      //get text range
      TextSpan[] aspan = new TextSpan[1];
      textView.GetSelectionSpan(aspan);
      TextSpan span = aspan[0];

      //check bounds
      if (span.iEndIndex == 0) span.iEndLine--;

      //get line lengths
      int startLen,endLen;

      this.textLines.GetLengthOfLine( span.iStartLine, out startLen );
      this.textLines.GetLengthOfLine( span.iEndLine, out endLen );

      // adjust end index if necessary
      if (span.iEndIndex == 0) span.iEndIndex = endLen;

      int adjustment = 0;

      //try to use line comments first, if we can.        
      if (this.commentInfo.useLineComments && span.iStartIndex == 0 && span.iEndIndex == endLen) { 
        //comment each line
        for (int line = span.iStartLine; line <= span.iEndLine; line++) {
          this.textLines.ReplaceLines( line, 0, line, 0, this.commentInfo.lineStart, this.commentInfo.lineStart.Length, null);
        }
        adjustment = this.commentInfo.lineStart.Length;
        span.iStartIndex = 0;
      }
        // otherwise try to use block comments
      else if (this.commentInfo.blockStart != null && this.commentInfo.blockEnd != null) {
        //add end comment
        this.textLines.ReplaceLines( span.iEndLine, span.iEndIndex, span.iEndLine, span.iEndIndex
          , this.commentInfo.blockEnd, this.commentInfo.blockEnd.Length, null);
        //add start comment
        this.textLines.ReplaceLines( span.iStartLine, span.iStartIndex, span.iStartLine, span.iStartIndex
          , this.commentInfo.blockStart, this.commentInfo.blockStart.Length, null);

        adjustment = this.commentInfo.blockEnd.Length;
        if (span.iStartLine == span.iEndLine) adjustment += this.commentInfo.blockStart.Length;
      }
      else
        NativeHelpers.RaiseComError(HResult.E_FAIL);

       
      if (TextSpanHelper.TextSpanPositive(span))
        textView.SetSelection( span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex + adjustment );
      else
        textView.SetSelection( span.iEndLine, span.iEndIndex + adjustment, span.iStartLine, span.iStartIndex );
  
    }
开发者ID:hesam,项目名称:SketchSharp,代码行数:54,代码来源:Source.cs


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