Browse Source

Fix bugs in RemoveNodes().

pull/10/head
Daniel Grunwald 15 years ago
parent
commit
8c428c3210
  1. 40
      SharpTreeView/FlatListTreeNode.cs

40
SharpTreeView/FlatListTreeNode.cs

@ -288,26 +288,46 @@ namespace ICSharpCode.TreeView
pos.right = null; pos.right = null;
} }
} }
SharpTreeNode succ = pos.Successor();
DeleteNode(pos); // this will also rebalance out the deletion of the right subtree DeleteNode(pos); // this will also rebalance out the deletion of the right subtree
oldPos = pos; oldPos = pos;
pos = pos.Successor(); pos = succ;
} while (oldPos != end); } while (oldPos != end);
// merge back together the removed subtrees: // merge back together the removed subtrees:
SharpTreeNode removed = removedSubtrees[0];
for (int i = 1; i < removedSubtrees.Count; i++) {
removed = ConcatTrees(removed, removedSubtrees[i]);
}
}
static SharpTreeNode ConcatTrees(SharpTreeNode first, SharpTreeNode second)
{
SharpTreeNode tmp = first;
while (tmp.right != null)
tmp = tmp.right;
InsertNodeAfter(tmp, second);
return tmp.GetListRoot();
} }
SharpTreeNode Successor() SharpTreeNode Successor()
{ {
SharpTreeNode node = this; if (right != null) {
SharpTreeNode oldNode; SharpTreeNode node = right;
do { while (node.left != null)
oldNode = node; node = node.left;
node = node.listParent; return node;
// loop while we are on the way up from the right part } else {
} while (node != null && node.right == oldNode); SharpTreeNode node = this;
return node; SharpTreeNode oldNode;
do {
oldNode = node;
node = node.listParent;
// loop while we are on the way up from the right part
} while (node != null && node.right == oldNode);
return node;
}
} }
static void DeleteNode(SharpTreeNode node) static void DeleteNode(SharpTreeNode node)

Loading…
Cancel
Save