ipytree icon indicating copy to clipboard operation
ipytree copied to clipboard

Icons disappear when changing node name

Open smahn9123 opened this issue 1 year ago • 3 comments

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 avatar Apr 24 '23 04:04 smahn9123

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 avatar Apr 24 '23 07:04 smahn9123

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

smahn9123 avatar Apr 24 '23 08:04 smahn9123

Opened #84 .

smahn9123 avatar Apr 24 '23 13:04 smahn9123