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


C# IVsTextView.GetCaretPos方法代码示例

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


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

示例1: OnCommand

    public virtual void OnCommand(IVsTextView textView, VsCommands2K command, bool backward) {
      
      if (textView == null) return;

      int line, idx;
      textView.GetCaretPos(out line, out idx);
      TokenInfo info = GetTokenInfo(textView);
      TokenTrigger triggerClass = info.trigger;

      if ((triggerClass & TokenTrigger.MemberSelect)!=0 && (command == VsCommands2K.TYPECHAR) && this.service.Preferences.AutoListMembers) {
        Trace.WriteLine("Source::OnCommand: member select");
        this.Completion( textView, info, false );
      }
     
      if ((triggerClass & TokenTrigger.MatchBraces)!=0 && this.service.Preferences.EnableMatchBraces) {
        if ( (command != VsCommands2K.BACKSPACE) && ((command == VsCommands2K.TYPECHAR) || this.service.Preferences.EnableMatchBracesAtCaret)) {
          Trace.WriteLine("Source::OnCommand: match braces");
          this.MatchBraces(textView, line, idx, info);
        }
      }

      //displayed & a trigger found
      // todo: This means the method tip disappears if you type "ENTER" 
      // while entering method arguments, which is bad.
      if ((triggerClass & TokenTrigger.MethodTip)!=0 && this.methodData.IsDisplayed) {    
        if (CommandOneOnLine(command) && ((triggerClass & TokenTrigger.MethodTip) == TokenTrigger.ParamNext)) {
          //this is an optimization
          Trace.WriteLine("Source::OnCommand: method info - displayed - adjust parameter" );
          methodData.AdjustCurrentParameter( (backward && idx > 0) ? -1 : +1 );
        }
        else {
          //this is the general case
          Trace.WriteLine("Source::OnCommand: method info - displayed - trigger");
          this.MethodTip( textView, line, (backward && idx > 0) ? idx-1 : idx, info);
        }
      }
        //displayed & complex command
      else if (methodData.IsDisplayed && ! CommandOneOnLine(command)) { 
        Trace.WriteLine("Source::OnCommand: method info - displayed - complex command");
        this.MethodTip(textView, line, idx, info);
      }
        //not displayed & trigger found & character typed & method info enabled
      else if ((triggerClass & TokenTrigger.MethodTip)!=0 && (command == VsCommands2K.TYPECHAR) && this.service.Preferences.ParameterInformation) {
        Trace.WriteLine("Source::OnCommand: method info");
        this.MethodTip(textView, line, idx, info);
      }
    }
开发者ID:hesam,项目名称:SketchSharp,代码行数:47,代码来源:Source.cs

示例2: Completion

 public virtual void Completion( IVsTextView textView, TokenInfo info, bool completeWord ) {
   int line;
   int idx;
   textView.GetCaretPos( out line, out idx );
   this.completeWord = completeWord;
   ParseReason reason = completeWord ? ParseReason.CompleteWord : ParseReason.MemberSelect;
   this.BeginParse(line, idx, info, reason, textView, new ParseResultHandler(this.HandleCompletionResponse));
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:8,代码来源:Source.cs

示例3: CheckCaretPosition

 public void CheckCaretPosition (IVsTextView textView) {
   if (textView == null) return;
   int line, col, pos, space;
   textView.GetCaretPos (out line, out col);
   textView.GetNearestPosition(line, col, out pos, out space);
   if (pos < this.pos || pos > this.pos + this.len) {
     textView.UpdateTipWindow (this.textTipWindow, (uint)TipWindowFlags.UTW_DISMISS);
   }
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:9,代码来源:ViewFilter.cs

示例4: GetTokenInfo

    public TokenInfo GetTokenInfo(IVsTextView textView) {
      //get current line 
      int line, idx;
      textView.GetCaretPos(out line, out idx);
      
      TokenInfo info = new TokenInfo();

      //get line info
      TokenInfo[] lineInfo = this.colorizer.GetLineInfo(line, this.colorState);
      if (lineInfo != null) {
        //get character info      
        GetTokenInfoAt(lineInfo, idx - 1, ref info);
      }
      return info;
    }
开发者ID:hesam,项目名称:SketchSharp,代码行数:15,代码来源:Source.cs

示例5: CheckCaretPosition

        public void CheckCaretPosition(IVsTextView textView)
        {
            if (textView == null) return;

            int line, col, pos, space;

            var hr = textView.GetCaretPos(out line, out col);
            if (NativeMethods.Failed(hr))
                return;

            NativeMethods.ThrowOnFailure(textView.GetNearestPosition(line, col, out pos, out space));
            if (pos < this.pos || pos > this.pos + this.len)
            {
                NativeMethods.ThrowOnFailure(textView.UpdateTipWindow(this.textTipWindow, (uint)TipWindowFlags.UTW_DISMISS));
            }
        }
开发者ID:CaptainHayashi,项目名称:visualfsharp,代码行数:16,代码来源:ViewFilter.cs

示例6: OnCommand

        public void OnCommand(IVsTextView textView, VsCommands2K command, char ch)
        {
            if (textView == null || this.service == null || !this.service.Preferences.EnableCodeSense)
                return;

            bool backward = (command == VsCommands2K.BACKSPACE || command == VsCommands2K.BACKTAB || command == VsCommands2K.LEFT || command == VsCommands2K.LEFT_EXT);

            int line, idx;

            var hr = textView.GetCaretPos(out line, out idx);
            if (NativeMethods.Failed(hr))
                return;

            TokenInfo info = GetTokenInfo(line, idx);
            TokenTriggers triggerClass = info.Trigger;


            var matchBraces = false;
            var methodTip = false;
            MethodTipMiscellany misc = 0;

            if ((triggerClass & TokenTriggers.MemberSelect) != 0 && (command == VsCommands2K.TYPECHAR))
            {
                BackgroundRequestReason reason = ((triggerClass & TokenTriggers.MatchBraces) != 0) ? BackgroundRequestReason.MemberSelectAndHighlightBraces : BackgroundRequestReason.MemberSelect;
                this.Completion(textView, info, reason, RequireFreshResults.No);
            }
            else if (this.service.Preferences.EnableMatchBraces &&
                ((command != VsCommands2K.BACKSPACE) && ((command == VsCommands2K.TYPECHAR) || this.service.Preferences.EnableMatchBracesAtCaret)))
            {

                // For brace matching when the caret is before the opening brace, we need to check the token at next index
                TokenInfo nextInfo = GetTokenInfo(line, idx + 1); // ??? overflow
                TokenTriggers nextTriggerClass = nextInfo.Trigger;

                if (((nextTriggerClass & (TokenTriggers.MatchBraces)) != 0) || ((triggerClass & (TokenTriggers.MatchBraces)) != 0))
                    matchBraces = true;
            }

            if ((triggerClass & TokenTriggers.MethodTip) != 0   // open paren, close paren, or comma
                && (command == VsCommands2K.TYPECHAR))          // they typed it, not just arrowed over it
            {
                methodTip = true;

                misc = MethodTipMiscellany.JustPressedOpenParen;
                if ((triggerClass & TokenTriggers.ParameterNext) != 0)
                    misc = MethodTipMiscellany.JustPressedComma;
                if ((triggerClass & TokenTriggers.ParameterEnd) != 0)
                    misc = MethodTipMiscellany.JustPressedCloseParen;
            }
            else if (this.methodData.IsDisplayed)
            {
                if (command == VsCommands2K.BACKSPACE)
                {
                    // the may have just erased a paren or comma, need to re-parse
                    methodTip = true;
                    misc = MethodTipMiscellany.JustPressedBackspace;
                }
                else
                {
                    this.methodData.Refresh(MethodTipMiscellany.Typing);
                }
            }

            if (matchBraces && methodTip)
            {
                // matchBraces = true and methodTip = true

                // backward is true when command is one of these: VsCommands2K.BACKSPACE | VsCommands2K.BACKTAB | VsCommands2K.LEFT | VsCommands2K.LEFT_EXT (1)
                // matchBraces = true when command is not BACKSPACE => BACKSPACE is excluded from the set (1)
                // methodTip = true when command is TYPECHAR or BACKSPACE => BACKSPACE is already excluded and TYPECHAR is not contained in set (1)
                // ergo: backward is always false here
                Debug.Assert(!backward);
                MatchBracesAndMethodTip(textView, line, idx, misc, info);
            }
            else if (matchBraces)
            {
                MatchBraces(textView, line, idx, info);
            }
            else if (methodTip)
            {
                MethodTip(textView, line, (backward && idx > 0) ? idx - 1 : idx, info, misc, RequireFreshResults.No);
            }
        }
开发者ID:svick,项目名称:visualfsharp,代码行数:83,代码来源:Source.cs

示例7: ShowAst

        private void ShowAst(IVsTextView view, bool showInfo)
        {
            NemerleSource source = Source as NemerleSource;
            if (source != null && source.ProjectInfo != null)
            {
                int line, col;
                ErrorHandler.ThrowOnFailure(view.GetCaretPos(out line, out col));
                //Debug.WriteLine(
                //		string.Format("OnChangeScrollInfo line={0}, col={1}", line + 1, col + 1));
                AstToolWindow tw = (AstToolWindow)source.ProjectInfo.ProjectNode.Package
                    .FindToolWindow(typeof(AstToolWindow), 0, true);

                if (showInfo)
                    tw.ShowInfo(source);

                tw.Activate(line + 1, col + 1);
            }
        }
开发者ID:89sos98,项目名称:nemerle,代码行数:18,代码来源:NemerleViewFilter.cs

示例8: OnChangeScrollInfo

        public override void OnChangeScrollInfo(IVsTextView view, int iBar,
            int iMinUnit, int iMaxUnits, int iVisibleUnits, int iFirstVisibleUnit)
        {
            base.OnChangeScrollInfo(view, iBar, iMinUnit, iMaxUnits, iVisibleUnits, iFirstVisibleUnit);

            Source.Service.Hint.Close();

            var viewUnknown = Utilities.QueryInterfaceIUnknown(view);
            if (viewUnknown != IntPtr.Zero)
                Marshal.Release(viewUnknown);

            TupleIntInt pos;
            var posExists = _viewsCarretInfo.TryGetValue(viewUnknown, out pos);
            int line, idx;
            if (view.GetCaretPos(out line, out idx) == VSConstants.S_OK)
            {
                if (!posExists || pos.Field0 != line || pos.Field1 != idx)
                {
                    // pos was changed
                    _viewsCarretInfo[viewUnknown] = new TupleIntInt(line, idx);
                    Source.CaretChanged(view, line, idx);
                    //Source.TryHighlightBraces1(view);
                    //Debug.WriteLine("pos was changed line=" + line + " col=" + idx);
                }
            }
        }
开发者ID:89sos98,项目名称:nemerle,代码行数:26,代码来源:NemerleViewFilter.cs

示例9: SynchronizeDropdowns

        public void SynchronizeDropdowns(IVsTextView view)
        {
            var mgr = GetCodeWindowManagerForView(view);
            if (mgr == null || mgr.DropDownHelper == null)
                return;

            var dropDownHelper = (NemerleTypeAndMemberDropdownBars)mgr.DropDownHelper;
            int line = -1, col = -1;
            if (!ErrorHandler.Failed(view.GetCaretPos(out line, out col)))
                dropDownHelper.SynchronizeDropdownsRsdn(view, line, col);
        }
开发者ID:vestild,项目名称:nemerle,代码行数:11,代码来源:NemerleLanguageService.cs

示例10: UpdateViewInfo

        /// <summary>Update current file index, current line & col in Engine</summary>
        /// <param name="line">0 - based</param>
        /// <param name="col">0 - based</param>
        void UpdateViewInfo(IVsTextView textView, int line, int col)
        {
            if (textView != null)
            {
                var source = GetSource(textView) as NemerleSource;

                if (source != null)
                {
                    if (line >= 0 && col >= 0 || !ErrorHandler.Failed(textView.GetCaretPos(out line, out col)))
                        source.GetEngine().SetTextCursorLocation(source.FileIndex, line + 1, col + 1);
                }
            }
        }
开发者ID:vestild,项目名称:nemerle,代码行数:16,代码来源:NemerleLanguageService.cs

示例11: Completor

        /// <include file='doc\Source.uex' path='docs/doc[@for="Completor.Completor"]/*' />
        public Completor(LanguageService langsvc, IVsTextView view, string description)
        {
            this.langsvc = langsvc;
            this.view = view;
            this.src = langsvc.GetSource(view);
            this.sb = new StringBuilder();
            this.caret = 0; // current position within StringBuilder.
            this.ca = CompoundActionFactory.GetCompoundAction(null, this.src, description);
            this.ca.FlushEditActions(); // make sure we see a consistent coordinate system.
            // initialize span representing what we are removing from the buffer.
            NativeMethods.ThrowOnFailure(view.GetCaretPos(out span.iStartLine, out span.iStartIndex));
            this.span.iEndLine = span.iStartLine;
            this.span.iEndIndex = span.iStartIndex;
            RefreshLine();

            macro = this.langsvc.GetIVsTextMacroHelperIfRecordingOn();
        }
开发者ID:Graham-Pedersen,项目名称:IronPlot,代码行数:18,代码来源:Source.cs

示例12: OnCommand

        /// <include file='doc\Source.uex' path='docs/doc[@for="Source.OnCommand"]/*' />
        public virtual void OnCommand(IVsTextView textView, VsCommands2K command, char ch)
        {
            if (textView == null || this.service == null || !this.service.Preferences.EnableCodeSense)
                return;

            bool backward = (command == VsCommands2K.BACKSPACE || command == VsCommands2K.BACKTAB ||
                command == VsCommands2K.LEFT || command == VsCommands2K.LEFT_EXT);

            int line, idx;

            NativeMethods.ThrowOnFailure(textView.GetCaretPos(out line, out idx));

            TokenInfo info = GetTokenInfo(line, idx);
            TokenTriggers triggerClass = info.Trigger;

            if ((triggerClass & TokenTriggers.MemberSelect) != 0 && (command == VsCommands2K.TYPECHAR)) {
                ParseReason reason = ((triggerClass & TokenTriggers.MatchBraces) == TokenTriggers.MatchBraces) ? ParseReason.MemberSelectAndHighlightBraces : ParseReason.MemberSelect;
                this.Completion(textView, info, reason);
            } else if ((triggerClass & TokenTriggers.MatchBraces) != 0 && this.service.Preferences.EnableMatchBraces) {
                if ((command != VsCommands2K.BACKSPACE) && ((command == VsCommands2K.TYPECHAR) || this.service.Preferences.EnableMatchBracesAtCaret)) {
                    this.MatchBraces(textView, line, idx, info);
                }
            }
            //displayed & a trigger found
            // todo: This means the method tip disappears if you type "ENTER"
            // while entering method arguments, which is bad.
            if ((triggerClass & TokenTriggers.MethodTip) != 0 && this.methodData.IsDisplayed) {
                if ((triggerClass & TokenTriggers.MethodTip) == TokenTriggers.ParameterNext) {
                    //this is an optimization
                    methodData.AdjustCurrentParameter((backward && idx > 0) ? -1 : +1);
                } else {
                    //this is the general case
                    this.MethodTip(textView, line, (backward && idx > 0) ? idx - 1 : idx, info);
                }
            } else if ((triggerClass & TokenTriggers.MethodTip) != 0 && (command == VsCommands2K.TYPECHAR) && this.service.Preferences.ParameterInformation) {
                //not displayed & trigger found & character typed & method info enabled
                this.MethodTip(textView, line, idx, info);
            } else if (methodData.IsDisplayed) {
                //displayed & complex command
                this.MethodTip(textView, line, idx, info);
            }
        }
开发者ID:Graham-Pedersen,项目名称:IronPlot,代码行数:43,代码来源:Source.cs

示例13: Completion

 /// <include file='doc\Source.uex' path='docs/doc[@for="Source.Completion"]/*' />
 public virtual void Completion(IVsTextView textView, TokenInfo info, ParseReason reason)
 {
     int line;
     int idx;
     NativeMethods.ThrowOnFailure(textView.GetCaretPos(out line, out idx));
     this.BeginParse(line, idx, info, reason, textView, new ParseResultHandler(this.HandleCompletionResponse));
 }
开发者ID:Graham-Pedersen,项目名称:IronPlot,代码行数:8,代码来源:Source.cs

示例14: SaveLogCursor

        private void SaveLogCursor(IVsTextView pView, int iNewLine, String searchTerm)
        {
            // Get column of cursor position
            int iLine, iCol;
            pView.GetCaretPos(out iLine, out iCol);

            if (searchTerm != "")
            {
                iLine = iNewLine;
            }

            // Usually just stray document open, not worth until actually moving around.
            if (iLine == 0 && iCol == 0)
                return;

            // For now, not handling navigation in dirty files.
            if (IsDirty(pView))
                return;

            // Get latest snapshot and make sure same as current buffer.
            if (!Sync(pView))
                return;

            using (var db = new HistoryContext())
            {
                // Save..
                var click = new CommitAlignedClick()
                {
                    LineNumber = iLine,
                    ColumnNumber = iCol,
                    WordExtent = GetWordExtent(pView, iLine, iCol),
                    Timestamp = DateTime.Now,
                    SearchTerm = searchTerm
                };
                // Need to add to parents?  Otherwise is creating multiple documents!!
                var commit = GetLatestCommit(_fileCommitIdCache[pView]);
                if (commit != null)
                {
                    // This should tell context this belongs to db
                    db.Commits.Attach(commit);
                    // http://stackoverflow.com/questions/7082744/cannot-insert-duplicate-key-in-object-dbo-user-r-nthe-statement-has-been-term
                    click.Commit = commit;
                    commit.Clicks.Add(click);
                    db.Clicks.Add(click);
                    db.SaveChanges();
                }
            }
        }
开发者ID:chrisparnin,项目名称:ganji,代码行数:48,代码来源:NavigateListener.cs

示例15: OnCommand

        //public override void ProcessHiddenRegions(System.Collections.ArrayList hiddenRegions) {
        //    base.ProcessHiddenRegions(hiddenRegions);
        //    return;
        //}
        //class TextSpanEqCmp : IEqualityComparer<TextSpan> {
        //    public bool Equals(TextSpan x, TextSpan y) {
        //        return x.iStartLine == y.iStartLine && x.iEndLine == y.iEndLine
        //               && x.iEndIndex == y.iEndIndex && x.iStartIndex == y.iStartIndex;
        //    }
        //    public int GetHashCode(TextSpan x) {
        //        return x.iStartLine ^ x.iEndLine ^ x.iEndIndex ^ x.iStartIndex;
        //    }
        //    public static readonly TextSpanEqCmp Instance = new TextSpanEqCmp();
        //}
        //bool _processingOfHiddenRegions;
        //public override MethodData CreateMethodData() {
        //    return MethodData = base.CreateMethodData();
        //}
        public override void OnCommand(IVsTextView textView, VsCommands2K command, char ch)
        {
            if (textView == null || Service == null || !Service.Preferences.EnableCodeSense)
                return;

            base.OnCommand(textView, command, ch);
            return;

            int line, idx;
            textView.GetCaretPos(out line, out idx);

            TokenInfo tokenBeforeCaret = GetTokenInfo(line, idx);

            TryHighlightBraces(textView, command, line, idx, tokenBeforeCaret);

            // This code open completion list if user enter '.'.
            if ((tokenBeforeCaret.Trigger & TokenTriggers.MemberSelect) != 0 && (command == VsCommands2K.TYPECHAR)) {
                var spaces = new[] { '\t', ' ', '\u000B', '\u000C' };
                var str = GetText(line, 0, line, idx - 1).Trim(spaces);

                while (str.Length <= 0 && line > 0) { // skip empy lines
                    line--;
                    str = GetLine(line + 1).Trim(spaces);
                }

                if (str.Length > 0) {
                    var lastChar = str[str.Length - 1];

                    // Don't show completion list if previous char not one of following:
                    if (char.IsLetterOrDigit(lastChar) || lastChar == ')' || lastChar == ']')
                        Completion(textView, line, idx, true);
                }
            }
        }
开发者ID:jianboqi,项目名称:NimStudio,代码行数:52,代码来源:NSSource.cs


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