1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fix remove item when depth=0 and wrong gutter calc

This commit is contained in:
GitHub 2021-04-28 17:25:26 +02:00
parent 0e02d03d9a
commit d47a8aa562

View File

@ -312,7 +312,7 @@
} }
if (child.depth !== parent.depth+1) { if (child.depth !== parent.depth+1) {
child.depth = parent.depth+1; child.depth = parent.depth+1;
var labelPaddingWidth = ((child.gutter?child.gutter.width()+2:0)+(child.depth*20)); var labelPaddingWidth = ((child.gutter ? child.gutter[0].offsetWidth + 2 : 0) + (child.depth * 20));
child.treeList.labelPadding.width(labelPaddingWidth+'px'); child.treeList.labelPadding.width(labelPaddingWidth+'px');
if (child.element) { if (child.element) {
$(child.element).css({ $(child.element).css({
@ -348,6 +348,16 @@
that._selected.delete(item); that._selected.delete(item);
delete item.treeList; delete item.treeList;
delete that._items[item.id]; delete that._items[item.id];
if(item.depth === 0) {
for(var key in that._items) {
var child = that._items[key];
if(child.parent && child.parent.id === item.id) {
delete that._items[key].treeList;
delete that._items[key];
}
}
that._data = that._data.filter(data => data.id !== item.id)
}
} }
item.treeList.insertChildAt = function(newItem,position,select) { item.treeList.insertChildAt = function(newItem,position,select) {
newItem.parent = item; newItem.parent = item;
@ -480,7 +490,10 @@
if (item.treeList.container) { if (item.treeList.container) {
$(item.element).remove(); $(item.element).remove();
$(element).appendTo(item.treeList.label); $(element).appendTo(item.treeList.label);
var labelPaddingWidth = (item.gutter?item.gutter.width()+2:0)+(item.depth*20); // using the JQuery Object, the gutter width will
// be wrong when the element is reattached the second time
var labelPaddingWidth = (item.gutter ? item.gutter[0].offsetWidth + 2 : 0) + (item.depth * 20);
$(element).css({ $(element).css({
width: "calc(100% - "+(labelPaddingWidth+20+(item.icon?20:0))+"px)" width: "calc(100% - "+(labelPaddingWidth+20+(item.icon?20:0))+"px)"
}) })
@ -516,7 +529,7 @@
}).appendTo(label) }).appendTo(label)
} }
var labelPaddingWidth = (item.gutter?item.gutter.width()+2:0)+(depth*20); var labelPaddingWidth = (item.gutter ? item.gutter[0].offsetWidth + 2 : 0) + (depth * 20)
item.treeList.labelPadding = $('<span>').css({ item.treeList.labelPadding = $('<span>').css({
display: "inline-block", display: "inline-block",
width: labelPaddingWidth+'px' width: labelPaddingWidth+'px'