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


C# SourceRange.Overlaps方法代码示例

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


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

示例1: AddSelection

        /// <summary>
        /// Adds the selection in the specified TextView (or the active member if there is no selection) to this MultiSelect instance.
        /// </summary>
        public void AddSelection(TextView textView)
        {
            if (textView == null)
                return;
            TextViewSelection textViewSelection = textView.Selection;
            if (textViewSelection == null)
                return;

            PartialSelection newPartialSelection = new PartialSelection(Selections.Count);

            // TODO: Refactor this so we find the selected member in one method (currently we have memberSelected, nodeAtTopOfSelection and selectionScanner performing similar functionality).
            SourcePoint finalCaretPosition = SourcePoint.Empty;
            LanguageElement memberSelected = null;
            if (!textViewSelection.Exists)
            {
                LanguageElement activeMember = CodeRush.Source.ActiveMember;
                if (activeMember != null)
                {
                    SourceRange declareRange = new SourceRange(activeMember.Range.Top, activeMember.NameRange.Bottom);
                    if (declareRange.Contains(textView.Caret.SourcePoint))
                    {
                        SourceRange fullBlockCutRange = activeMember.GetFullBlockCutRange();
                        textView.Selection.Set(fullBlockCutRange);
                        memberSelected = activeMember;
                    }
                    else
                        CodeRush.Command.Execute("SelectionExpand");
                }
                else
                    CodeRush.Command.Execute("SelectionExpand");
                if (!textViewSelection.Exists)
                    return;
            }

            SourceRange selectionRange = new SourceRange(textViewSelection.Range.Top, textViewSelection.Range.Bottom);

            for (int i = Selections.Count - 1; i >= 0; i--)
            {
                PartialSelection compareSelection = Selections[i];
                if (selectionRange.Overlaps(compareSelection.Range))
                {
                    selectionRange = SourceRange.Union(compareSelection.Range, selectionRange);
                    compareSelection.RemoveHighlighter();
                    Selections.RemoveAt(i);
                }
            }
            if (memberSelected != null)
            {
                newPartialSelection.ElementName = memberSelected.Name;
                newPartialSelection.ElementType = memberSelected.ElementType;
                finalCaretPosition = memberSelected.Range.Top;
            }
            else
            {
                LanguageElement nodeAtTopOfSelection = CodeRush.Source.GetNodeAt(selectionRange.Top);
                LanguageElement nodeBeforeEndOfSelection = CodeRush.Source.GetNodeBefore(selectionRange.Bottom);
                if (nodeAtTopOfSelection == nodeBeforeEndOfSelection || nodeAtTopOfSelection.Parents(nodeBeforeEndOfSelection) && selectionRange.Contains(nodeAtTopOfSelection.Range))
                {
                    newPartialSelection.ElementName = nodeAtTopOfSelection.Name;
                    newPartialSelection.ElementType = nodeAtTopOfSelection.ElementType;
                }
                else
                {
                    SelectionScanner selectionScanner = new SelectionScanner();
                    selectionScanner.Scan();
                    if (selectionScanner.ElementsFound == 1)
                        newPartialSelection.ElementName = selectionScanner.ElementName;
                    newPartialSelection.ElementType = selectionScanner.ElementType;
                }
            }
            newPartialSelection.Range = selectionRange;
            SourceRange highlightRange;
            if (memberSelected != null)
            {
                LanguageElement startNode;
                LanguageElement endNode;
                memberSelected.GetFullBlockNodes(out startNode, out endNode);
                highlightRange = new SourceRange(startNode.Range.Top, endNode.Range.Bottom);
                if (Selections.Count == 0)
                    ContainsOnlyMembers = true;
            }
            else
            {
                highlightRange = selectionRange;
                ContainsOnlyMembers = false;
            }
            newPartialSelection.HighlightRange = highlightRange;
            newPartialSelection.Text = textView.TextDocument.GetText(selectionRange);

            if (finalCaretPosition == SourcePoint.Empty)
                finalCaretPosition = textViewSelection.Range.Top;
            newPartialSelection.CaretPosition = finalCaretPosition;
            AddSelection(textView, newPartialSelection);
        }
开发者ID:modulexcite,项目名称:CR_MultiSelect,代码行数:97,代码来源:MultiSelect.cs


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