Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icons disappear when changing node name #83

Open
smahn9123 opened this issue Apr 24, 2023 · 3 comments
Open

Icons disappear when changing node name #83

smahn9123 opened this issue Apr 24, 2023 · 3 comments

Comments

@smahn9123
Copy link

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
Copy link
Author

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
Copy link
Author

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

@smahn9123
Copy link
Author

Opened #84 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant