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

Merge pull request #4043 from node-red-hitachi/fix-group-undo-position

fix group position after undo
This commit is contained in:
Nick O'Leary 2023-02-03 09:11:20 +00:00 committed by GitHub
commit adfc5b3e98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -586,11 +586,28 @@ RED.view = (function() {
var group = $(ui.helper).data("group"); var group = $(ui.helper).data("group");
if (group) { if (group) {
var oldX = group.x;
var oldY = group.y;
RED.group.addToGroup(group, nn); RED.group.addToGroup(group, nn);
var moveEvent = null;
if ((group.x !== oldX) ||
(group.y !== oldY)) {
moveEvent = {
t: "move",
nodes: [{n: group,
ox: oldX, oy: oldY,
dx: group.x -oldX,
dy: group.y -oldY}],
dirty: true
};
}
historyEvent = { historyEvent = {
t: 'multi', t: 'multi',
events: [historyEvent], events: [historyEvent],
};
if (moveEvent) {
historyEvent.events.push(moveEvent)
} }
historyEvent.events.push({ historyEvent.events.push({
t: "addToGroup", t: "addToGroup",
@ -1350,19 +1367,35 @@ RED.view = (function() {
RED.editor.validateNode(nn); RED.editor.validateNode(nn);
if (targetGroup) { if (targetGroup) {
var oldX = targetGroup.x;
var oldY = targetGroup.y;
RED.group.addToGroup(targetGroup, nn); RED.group.addToGroup(targetGroup, nn);
var moveEvent = null;
if ((targetGroup.x !== oldX) ||
(targetGroup.y !== oldY)) {
moveEvent = {
t: "move",
nodes: [{n: targetGroup,
ox: oldX, oy: oldY,
dx: targetGroup.x -oldX,
dy: targetGroup.y -oldY}],
dirty: true
};
}
if (historyEvent.t !== "multi") { if (historyEvent.t !== "multi") {
historyEvent = { historyEvent = {
t:'multi', t:'multi',
events: [historyEvent] events: [historyEvent]
} };
} }
historyEvent.events.push({ historyEvent.events.push({
t: "addToGroup", t: "addToGroup",
group: targetGroup, group: targetGroup,
nodes: nn nodes: nn
}) });
if (moveEvent) {
historyEvent.events.push(moveEvent);
}
} }
if (spliceLink) { if (spliceLink) {
@ -1698,6 +1731,7 @@ RED.view = (function() {
// Check link splice or group-add // Check link splice or group-add
if (movingSet.length() === 1 && movingSet.get(0).n.type !== "group") { if (movingSet.length() === 1 && movingSet.get(0).n.type !== "group") {
//}{//NIS
node = movingSet.get(0); node = movingSet.get(0);
if (spliceActive) { if (spliceActive) {
if (!spliceTimer) { if (!spliceTimer) {
@ -2057,11 +2091,25 @@ RED.view = (function() {
if (mouse_mode == RED.state.MOVING_ACTIVE) { if (mouse_mode == RED.state.MOVING_ACTIVE) {
if (movingSet.length() > 0) { if (movingSet.length() > 0) {
var addedToGroup = null; var addedToGroup = null;
var moveEvent = null;
if (activeHoverGroup) { if (activeHoverGroup) {
var oldX = activeHoverGroup.x;
var oldY = activeHoverGroup.y;
for (var j=0;j<movingSet.length();j++) { for (var j=0;j<movingSet.length();j++) {
var n = movingSet.get(j); var n = movingSet.get(j);
RED.group.addToGroup(activeHoverGroup,n.n); RED.group.addToGroup(activeHoverGroup,n.n);
} }
if ((activeHoverGroup.x !== oldX) ||
(activeHoverGroup.y !== oldY)) {
moveEvent = {
t: "move",
nodes: [{n: activeHoverGroup,
ox: oldX, oy: oldY,
dx: activeHoverGroup.x -oldX,
dy: activeHoverGroup.y -oldY}],
dirty: true
};
}
addedToGroup = activeHoverGroup; addedToGroup = activeHoverGroup;
activeHoverGroup.hovered = false; activeHoverGroup.hovered = false;
@ -2107,6 +2155,12 @@ RED.view = (function() {
historyEvent.addToGroup = addedToGroup; historyEvent.addToGroup = addedToGroup;
} }
RED.nodes.dirty(true); RED.nodes.dirty(true);
if (moveEvent) {
historyEvent = {
t: "multi",
events: [moveEvent, historyEvent]
};
}
RED.history.push(historyEvent); RED.history.push(historyEvent);
} }
} }
@ -3466,11 +3520,25 @@ RED.view = (function() {
updateActiveNodes(); updateActiveNodes();
} }
var moveEvent = null;
if (activeHoverGroup) { if (activeHoverGroup) {
var oldX = activeHoverGroup.x;
var oldY = activeHoverGroup.y;
for (var j=0;j<movingSet.length();j++) { for (var j=0;j<movingSet.length();j++) {
var n = movingSet.get(j); var n = movingSet.get(j);
RED.group.addToGroup(activeHoverGroup,n.n); RED.group.addToGroup(activeHoverGroup,n.n);
} }
if ((activeHoverGroup.x !== oldX) ||
(activeHoverGroup.y !== oldY)) {
moveEvent = {
t: "move",
nodes: [{n: activeHoverGroup,
ox: oldX, oy: oldY,
dx: activeHoverGroup.x -oldX,
dy: activeHoverGroup.y -oldY}],
dirty: true
};
}
historyEvent.addedToGroup = activeHoverGroup; historyEvent.addedToGroup = activeHoverGroup;
activeHoverGroup.hovered = false; activeHoverGroup.hovered = false;
@ -3479,7 +3547,6 @@ RED.view = (function() {
activeGroup.selected = true; activeGroup.selected = true;
activeHoverGroup = null; activeHoverGroup = null;
} }
if (mouse_mode == RED.state.DETACHED_DRAGGING) { if (mouse_mode == RED.state.DETACHED_DRAGGING) {
var ns = []; var ns = [];
for (var j=0;j<movingSet.length();j++) { for (var j=0;j<movingSet.length();j++) {
@ -3490,7 +3557,15 @@ RED.view = (function() {
n.n.moved = true; n.n.moved = true;
} }
} }
RED.history.replace({t:"multi",events:[historyEvent,{t:"move",nodes:ns}],dirty: historyEvent.dirty}) var event = {t:"multi",events:[historyEvent,{t:"move",nodes:ns}],dirty: historyEvent.dirty};
if (moveEvent) {
event.events.push(moveEvent);
}
RED.history.replace(event)
}
else if(moveEvent) {
var event = {t:"multi", events:[historyEvent, moveEvent], dirty: true};
RED.history.replace(event);
} }
updateSelection(); updateSelection();