Merge pull request #3731 from node-red-hitachi/fix-node-move

Fix to prevent node from moving out of workspace
This commit is contained in:
Stephen McLaughlin 2022-07-06 10:35:54 +01:00 committed by GitHub
commit a38d3981df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -105,6 +105,9 @@ RED.view.tools = (function() {
$(document).one('keyup',endKeyboardMove);
endMoveSet = true;
}
var dim = RED.view.dimensions();
var space_width = dim.width;
var space_height = dim.height;
var minX = 0;
var minY = 0;
var node;
@ -120,6 +123,12 @@ RED.view.tools = (function() {
node.n.dirty = true;
node.n.x += dx;
node.n.y += dy;
if ((node.n.x +node.n.w/2) >= space_width) {
node.n.x = space_width -node.n.w/2;
}
if ((node.n.y +node.n.h/2) >= space_height) {
node.n.y = space_height -node.n.h/2;
}
node.n.dirty = true;
if (node.n.type === "group") {
RED.group.markDirty(node.n);

View File

@ -6236,6 +6236,12 @@ RED.view = (function() {
showQuickAddDialog:showQuickAddDialog,
calculateNodeDimensions: calculateNodeDimensions,
getElementPosition:getElementPosition,
showTooltip:showTooltip
showTooltip:showTooltip,
dimensions: function() {
return {
width: space_width,
height: space_height
};
}
};
})();