private void CaretMovedOrSelectionChanged() { if (_ChangingInternally) return; _Caret = null; _Anchor = null; }
private LanguageElement GetChildElement(LanguageElement element, ElementLocation location) { if (element == null || location == null) return null; NodeList nodes; if (location._IsDetailNode) nodes = element.DetailNodes; else nodes = element.Nodes; return FindNthElement(nodes, location._PreviousMatchingSiblings + 1, location._ElementType); }
private static ElementLocation FromLanguageElement(LanguageElement element, SourcePoint target) { ElementLocation elementLocation = new ElementLocation(); elementLocation._ElementType = element.ElementType; elementLocation._IsDetailNode = element.IsDetailNode; elementLocation._PreviousMatchingSiblings = CalculatePreviousMatchingSiblings(elementLocation, element); elementLocation._Vector = GetClosestVector(element, target); return elementLocation; }
private static int CalculatePreviousMatchingSiblings(ElementLocation elementLocation, LanguageElement testElement) { int previousSiblings = 0; NodeList nodes; LanguageElement testElementParent = testElement.Parent; if (testElementParent == null) return 0; if (testElement.IsDetailNode) nodes = testElementParent.DetailNodes; else nodes = testElementParent.Nodes; foreach (LanguageElement element in nodes) { if (element == testElement) break; if (element.ElementType == elementLocation._ElementType) previousSiblings++; } return previousSiblings; }
private void NavToSibling(ApplyContentEventArgs ea, SiblingDirection siblingDirection) { LanguageElement methodOrProperty = CodeRush.Source.ActiveMethodOrProperty; if (methodOrProperty == null) return; LanguageElement sibling = methodOrProperty; while (sibling != null) { if (siblingDirection == SiblingDirection.Next) sibling = sibling.NextCodeSibling; else sibling = sibling.PreviousCodeSibling; if (sibling is Method || sibling is Property) break; } if (sibling == null) { string msg; string searchItem; if (methodOrProperty is Property) searchItem = "properties"; else searchItem = "methods"; if (siblingDirection == SiblingDirection.Next) msg = String.Format("No more {0} below this location.", searchItem); // Translate: {0} is the item we're searching for (e.g., "properties" or "methods"). else msg = String.Format("No more {0} above this location.", searchItem); // Translate: {0} is the item we're searching for (e.g., "properties" or "methods"). CodeRush.ApplicationObject.StatusBar.Text = msg; return; } if (_Caret == null) _Caret = ElementLocation.From(methodOrProperty, CodeRush.Caret.SourcePoint); TextView textView = ea.TextView; if (textView == null) return; if (_Anchor == null) if (textView.Selection.Exists) _Anchor = ElementLocation.From(methodOrProperty, textView.Selection.AnchorSourcePoint); Restore(sibling, textView); }