mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add select-up/downstream-nodes action to editor
This commit is contained in:
@@ -17,6 +17,40 @@
|
||||
RED.view.tools = (function() {
|
||||
|
||||
|
||||
function selectDownstream() {
|
||||
selectStream('source','target')
|
||||
}
|
||||
function selectUpstream() {
|
||||
selectStream('target','source')
|
||||
}
|
||||
function selectStream(from,to) {
|
||||
var selection = RED.view.selection();
|
||||
var visited = new Set();
|
||||
if (selection.nodes && selection.nodes.length > 0) {
|
||||
var nodes = [];
|
||||
selection.nodes.forEach(function(n) {
|
||||
visited.add(n);
|
||||
var filter = {};
|
||||
filter[from] = {id:n.id}
|
||||
var initialLinks = RED.nodes.filterLinks(filter);
|
||||
nodes = nodes.concat(initialLinks.map(function(n){return n[to]}));
|
||||
})
|
||||
while(nodes.length > 0) {
|
||||
var n = nodes.shift();
|
||||
visited.add(n);
|
||||
var filter = {};
|
||||
filter[from] = {id:n.id}
|
||||
var links = RED.nodes.filterLinks(filter);
|
||||
links.forEach(function(l) {
|
||||
if (!visited.has(l[to])) {
|
||||
nodes.push(l[to]);
|
||||
}
|
||||
})
|
||||
}
|
||||
RED.view.select({nodes:Array.from(visited)});
|
||||
}
|
||||
}
|
||||
|
||||
function alignToGrid() {
|
||||
var selection = RED.view.selection();
|
||||
if (selection.nodes) {
|
||||
@@ -206,6 +240,9 @@ RED.view.tools = (function() {
|
||||
RED.actions.add("core:step-selection-right", function() { moveSelection(RED.view.gridSize(),0);});
|
||||
RED.actions.add("core:step-selection-down", function() { moveSelection(0,RED.view.gridSize());});
|
||||
RED.actions.add("core:step-selection-left", function() { moveSelection(-RED.view.gridSize(),0);});
|
||||
|
||||
RED.actions.add("core:select-downstream-nodes", selectDownstream);
|
||||
RED.actions.add("core:select-upstream-nodes", selectUpstream);
|
||||
},
|
||||
/**
|
||||
* Aligns all selected nodes to the current grid
|
||||
|
Reference in New Issue
Block a user