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


C# IVsTextView.GetSelection方法代码示例

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


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

示例1: 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


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