Fix up event handling when deleting groups and tabs

This commit is contained in:
Nick O'Leary
2020-06-03 14:23:26 +01:00
parent b6b3ceef4d
commit efecfa328b
4 changed files with 86 additions and 47 deletions

View File

@@ -387,19 +387,16 @@ RED.sidebar.info.outliner = (function() {
var existingObject = objects[n.id];
existingObject.treeList.remove();
delete objects[n.id]
// If this is a group being removed, it may have an empty item
if (empties[n.id]) {
delete empties[n.id];
}
var parent = existingObject.parent;
if (parent.children.length === 0) {
parent.treeList.addChild(getEmptyItem(parent.id));
}
// if (existingObject.children && (existingObject.children.length > 0)) {
// existingObject.children.forEach(function (nc) {
// if (!nc.empty) {
// var childObject = objects[nc.id];
// nc.parent = parent;
// objects[parent.id].treeList.addChild(childObject);
// }
// });
// }
}
function getGutter(n) {
var span = $("<span>",{class:"red-ui-info-outline-gutter"});

View File

@@ -1929,6 +1929,7 @@ if (DEBUG_EVENTS) { console.warn("clearSelection", mouse_mode); }
redraw();
} else if (moving_set.length > 0 || selected_link != null) {
var result;
var node;
var removedNodes = [];
var removedLinks = [];
var removedGroups = [];
@@ -1941,12 +1942,25 @@ if (DEBUG_EVENTS) { console.warn("clearSelection", mouse_mode); }
var startChanged = false;
var selectedGroups = [];
if (moving_set.length > 0) {
for (var i=0;i<moving_set.length;i++) {
var node = moving_set[i].n;
node.selected = false;
node = moving_set[i].n;
if (node.type === "group") {
selectedGroups.push(node);
} else if (node.type != "subflow") {
}
}
// Make sure we have identified all groups about to be deleted
for (i=0;i<selectedGroups.length;i++) {
selectedGroups[i].nodes.forEach(function(n) {
if (n.type === "group" && selectedGroups.indexOf(n) === -1) {
selectedGroups.push(n);
}
})
}
for (var i=0;i<moving_set.length;i++) {
node = moving_set[i].n;
node.selected = false;
if (node.type !== "group" && node.type !== "subflow") {
if (node.x < 0) {
node.x = 25
}
@@ -1956,9 +1970,12 @@ if (DEBUG_EVENTS) { console.warn("clearSelection", mouse_mode); }
removedLinks = removedLinks.concat(removedEntities.links);
if (node.g) {
var group = RED.nodes.group(node.g);
if ((!group.selected || group.active) && (selectedGroups.indexOf(group) < 0)) {
RED.group.removeFromGroup(group,node);
node.g = group.id;
if (selectedGroups.indexOf(group) === -1) {
// Don't use RED.group.removeFromGroup as that emits
// a change event on the node - but we're deleting it
var index = group.nodes.indexOf(node);
group.nodes.splice(index,1);
RED.group.markDirty(group);
}
}
} else {
@@ -1972,17 +1989,13 @@ if (DEBUG_EVENTS) { console.warn("clearSelection", mouse_mode); }
node.dirty = true;
}
}
while (selectedGroups.length > 0) {
var g = selectedGroups.shift();
if (removedGroups.indexOf(g) === -1) {
removedGroups.push(g);
g.nodes.forEach(function(n) {
if (n.type === "group") {
selectedGroups.push(n);
}
})
RED.nodes.removeGroup(g);
}
// Groups must be removed in the right order - from inner-most
// to outermost.
for (i = selectedGroups.length-1; i>=0; i--) {
var g = selectedGroups[i];
removedGroups.push(g);
RED.nodes.removeGroup(g);
}
if (removedSubflowOutputs.length > 0) {
result = RED.subflow.removeOutput(removedSubflowOutputs);