diff --git a/Gruntfile.js b/Gruntfile.js index 4600d031b..43ff0b370 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -151,6 +151,7 @@ module.exports = function(grunt) { "packages/node_modules/@node-red/editor-client/src/js/ui/workspaces.js", "packages/node_modules/@node-red/editor-client/src/js/ui/view.js", "packages/node_modules/@node-red/editor-client/src/js/ui/view-navigator.js", + "packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js", "packages/node_modules/@node-red/editor-client/src/js/ui/sidebar.js", "packages/node_modules/@node-red/editor-client/src/js/ui/palette.js", "packages/node_modules/@node-red/editor-client/src/js/ui/tab-info.js", diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js b/packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js new file mode 100644 index 000000000..0814892be --- /dev/null +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js @@ -0,0 +1,137 @@ +/** + * Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +RED.view.tools = (function() { + + + function alignToGrid() { + var selection = RED.view.selection(); + if (selection.nodes) { + var changedNodes = []; + selection.nodes.forEach(function(n) { + var x = n.w/2 + Math.round((n.x-n.w/2)/RED.view.gridSize())*RED.view.gridSize(); + var y = Math.round(n.y/RED.view.gridSize())*RED.view.gridSize(); + if (n.x !== x || n.y !== y) { + changedNodes.push({ + n:n, + ox: n.x, + oy: n.y, + moved: n.moved + }); + n.x = x; + n.y = y; + n.dirty = true; + n.moved = true; + } + }); + if (changedNodes.length > 0) { + RED.history.push({t:"move",nodes:changedNodes,dirty:RED.nodes.dirty()}); + RED.nodes.dirty(true); + RED.view.redraw(true); + } + } + } + + var moving_set = null; + var endMoveSet = false; + function endKeyboardMove() { + endMoveSet = false; + if (moving_set.length > 0) { + var ns = []; + for (var i=0;i 0) { + if (!endMoveSet) { + $(document).one('keyup',endKeyboardMove); + endMoveSet = true; + } + var minX = 0; + var minY = 0; + var node; + + for (var i=0;i 0) { - var ns = []; - for (var i=0;i 0) { - if (!endMoveSet) { - $(document).one('keyup',endKeyboardMove); - endMoveSet = true; - } - var minX = 0; - var minY = 0; - var node; - - for (var i=0;i 0) { var node = moving_set[0].n;