jupyter-widgets-contrib / ipytree

A Tree Widget using Jupyter-widgets protocol and jsTree
MIT License
130 stars 27 forks source link

Icons disappear when changing node name #83

Open smahn9123 opened 1 year ago

smahn9123 commented 1 year ago

In a nested Tree, when changing name of node like below, +/- icons disappear.

// node is a NodeModel instance
node.set('name', name);
node.save_changes();

I do know this can be resolved by calling NodeView's setOpenCloseIcon(), but I would really like to know why this occurs in the first place.

smahn9123 commented 1 year ago

I found the answer:

jstree defines the prototype of its node in the init stage, and here the 'jstree-icon jstree-ocl' class is used. This does not have any icon related class.

$.jstree.core.prototype = {
        ...
        _create_prototype_node : function () {
            ...
            _temp1.className = 'jstree-icon jstree-ocl';
        ...
        init : function (el, options) {
            this._data.core.node = this._create_prototype_node();
        ...

When the name of node is changed, rename_node() -> set_text() -> redraw_node() is called inside jstree. redraw_node() removes the existing node and creates a new node from the prototype to replace the existing node.

        redraw_node : function (node, deep, is_callback, force_render) {
                ...
                node.remove();
                //node = d.createElement('LI');
                //node = node[0];
            }
            node = this._data.core.node.cloneNode(true);
        ...

When rename_node() is called, any pre-set icon-related class is gone as the node element is replaced. Thus, the user(ipytree) has to set it - Which exactly is what NodeView's setOpenCloseIcon() does. Below is a node icon element with open icon related class added: <i class="jstree-icon jstree-ocl fa fa-plus ipytree-style-default" role="presentation"></i>

smahn9123 commented 1 year ago

So it seems to me that this problem is a bug. I'll work on a PR to address this.

smahn9123 commented 1 year ago

Opened #84 .