FIX for: moveTo, called by outdent in "complex demo" gets null if node already all the way left
I've just installed Fancy Tree 2.7.1 and am working to adapt the Complex Demo example as a proof of compatibility with the rest of my app (Adobe Air Javascript jQuery with lots of extras.)
I was getting a message that targetParent was null in jquery.fancetree-all.js at line 1116.
I fixed this by modifying the Complex Demo code. In the 'outdent' case of
.on("nodeCommand", function(event, data)
I added a test: if(node.getParent().parent) so that the following moveTo() and setActive() calls would only be invoked if the node returned by getParent() has a parent of its own
While I fixed the issue by modifying the example code, this appears to be a problem in the FancyTree code base.
As I'm just starting to work with this library, I am not at all sure that perhaps there is a much better way to prevent this problem.
Perhaps a change to jquery.fancytree-all.js line 1112 from if(this === targetNode){ to if(this === targetNode || targetNode === null){ (I have not checked this proposed fix -- but my change to the Complex Demo did get rid of the problem)
I checked the change log, and see no recent change in this area, so I've filed this issue in hopes that one of the maintainers will look this over, and being far more familiar then I with the code, they will make the most appropriate changes.
Basically, I've fixed the symptom, but don't know if it indicates a deeper problem.
Thanks Harrison
Thanks for contributing!
I was getting a message that targetParent was null in jquery.fancetree-all.js at line 1116.
How can the error message be reproduced?
I'm using Adobe Air / Javascript + HTML invoked from the command line in a dos window of Windows 8.1.
The error message is logged to the dos window on lines following the invocation.
To confirm in a development environment of your choice, replace my suggested patch (checking if targetParent is null) with some sort of 'assert' or:
if ( targetParent === null ) alert('target Parent is null');
Subsequent to my first report, I was reading through more of the FancyTree documentation, and saw that various API calls that are to return a reference to a requested node, return a null for the root node. This appears to be just that (but then I'm new with this library, and may not have things fully sorted out in my head.)
If you'd like, I can probably capture the logging to a file and upload it, but there really wasn't anything more there than identifying the variable and saying that it was null (and didn't hold a valid object reference) and a stack trace which led me back to the outdent function in the Complex Example.
Harrison
Ok, I was able to reproduce it here: http://wwwendt.de/tech/fancytree/demo/sample-multi-ext.html Simply use Ctrl+RIGHT to indent "node 1.1". I consider this not a bug, rather my sloppy implementation of this demo code, for example:
}).on("nodeCommand", function(event, data){
// Custom event handler that is triggered by keydown-handler and
// context menu:
var refNode, moveMode,
tree = $(this).fancytree("getTree"),
node = tree.getActiveNode();
switch( data.cmd ) {
...
case "indent":
refNode = node.getPrevSibling();
node.moveTo(refNode, "child");
refNode.setExpanded();
node.setActive();
break;
"node 1.1." does not have a previous sibling, so null is returned. It is not allowed to pass null as first argument to moveTo(), so the code should be fixed like
case "indent":
refNode = node.getPrevSibling();
if( refNode ) {
node.moveTo(refNode, "child");
refNode.setExpanded();
node.setActive();
}
break;