/// <summary> Finds a series of nodes that are affected by a change at the given index. </summary> /// <param name="range"> The range at which a change is being applied </param> /// <returns> The nodes that are affected by the change. </returns> private FoundNode GetAffectedNodes(Range range) { var listNode = _subFragments.First; int absoluteIndexOfLastSubFragment = 0; var foundNode = new FoundNode(); while (listNode != null) { MarkupNodeReference subFragment = listNode.Value; var subFragmentAbsoluteStart = absoluteIndexOfLastSubFragment + subFragment.RelativeOffsetSinceLastNode; var nodeRange = new Range(subFragmentAbsoluteStart, subFragmentAbsoluteStart + subFragment.Length); if (range.EndIndex < nodeRange.StartIndex) { // the change is before every remaining sub-fragment, so we can bail out now foundNode.MarkRemaining(listNode); break; } if (nodeRange.OverlapsInclusive(range)) { foundNode.RememberFirstAndLast(nodeRange.StartIndex, listNode); } absoluteIndexOfLastSubFragment = nodeRange.StartIndex; listNode = listNode.Next; } return(foundNode); }
private static FoundNode FindNode(Func <Node, bool> func, Node current, ICollection <Node> visitedNodes, int distance, FoundNode foundNode) { visitedNodes.Add(current); if (func.Invoke(current)) { if (foundNode == null || distance < foundNode.Distance) { foundNode = new FoundNode(distance, current); } } foreach (var currentChild in current.Children) { var found = FindNode(func, currentChild, visitedNodes, distance + 1, foundNode); if (NodeOk(foundNode, found)) { foundNode = found; } } if (current.Parent != null && !visitedNodes.Contains(current.Parent)) { var found = FindNode(func, current.Parent, visitedNodes, distance + 1, foundNode); if (NodeOk(foundNode, found)) { foundNode = found; } } return(foundNode); }
private void PrepareAndAddFoundNode(Employee employee) { FoundNode foundNode = FoundNode.CreateRoot(employee); PrepareAndAdd(foundNode); foundNodes.Add(new KeyValuePair <int, FoundNode>(employee.ID, foundNode)); }
public void SelectFoundFolder(int id, FoundNode node, int curID) { FoundNode found = FindFoundNode(id, node); if (found != null) { node = found; } node.EnsureVisible(); node.SetCurID(curID); SelectedNode = node; }
private static bool NodeOk(FoundNode foundNode, FoundNode found) { return(found != null && (foundNode == null || found.Distance < foundNode.Distance)); }
public FoundNode FindFoundNode(int id, FoundNode node) { return(node == null ? null : node.ID == id ? node : node.Nodes.Cast <FoundNode>().FirstOrDefault(subNode => subNode.ID == id)); }