From e2f42fddb5afa66e57dacb043fd8b581eb09075f Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 13 Jul 2022 12:19:05 +0100 Subject: [PATCH 1/4] Ensire only wire links are split with junctions/links --- .../@node-red/editor-client/src/js/ui/view-tools.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 23316b1a1..7aa9919e3 100644 --- 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 @@ -823,7 +823,7 @@ RED.view.tools = (function() { * @param {Object || Object[]} wires The wire(s) to split and replace with link-out, link-in nodes. */ function splitWiresWithLinkNodes(wires) { - let wiresToSplit = wires || RED.view.selection().links; + let wiresToSplit = wires || (RED.view.selection().links && RED.view.selection().links.filter(e => !e.link)); if (!wiresToSplit) { return } @@ -1061,7 +1061,7 @@ RED.view.tools = (function() { } function addJunctionsToWires(wires) { - let wiresToSplit = wires || RED.view.selection().links; + let wiresToSplit = wires || (RED.view.selection().links && RED.view.selection().links.filter(e => !e.link)); if (!wiresToSplit) { return } From c648e1e8d621fd79e1494c921fe57c379e6ffc5a Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 13 Jul 2022 12:42:55 +0100 Subject: [PATCH 2/4] fix context menu insert junc/links enabled state --- .../@node-red/editor-client/src/js/ui/contextMenu.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js b/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js index 34a16d305..03517e65b 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js @@ -30,11 +30,14 @@ RED.contextMenu = (function () { } const selection = RED.view.selection() + const noSelection = !selection || Object.keys(selection).length === 0 const hasSelection = (selection.nodes && selection.nodes.length > 0); const hasMultipleSelection = hasSelection && selection.nodes.length > 1; - const hasLinks = selection.links && selection.links.length > 0; - const isSingleLink = !hasSelection && hasLinks && selection.links.length === 1 - const isMultipleLinks = !hasSelection && hasLinks && selection.links.length > 1 + const virtulLinks = (selection.links && selection.links.filter(e => !!e.link)) || []; + const wireLinks = (selection.links && selection.links.filter(e => !e.link)) || []; + const hasLinks = wireLinks.length > 0; + const isSingleLink = !hasSelection && hasLinks && wireLinks.length === 1 + const isMultipleLinks = !hasSelection && hasLinks && wireLinks.length > 1 const canDelete = hasSelection || hasLinks const isGroup = hasSelection && selection.nodes.length === 1 && selection.nodes[0].type === 'group' @@ -66,12 +69,13 @@ RED.contextMenu = (function () { }) } }, - (hasSelection || hasLinks) ? { + (hasSelection || hasLinks) ? { // has nodes or at least 1 wire selected label: RED._("contextMenu.junction"), onselect: 'core:split-wires-with-junctions', disabled: !hasLinks } : { label: RED._("contextMenu.junction"), + disabled: !noSelection, // has 0 nodes, 0 links selected (i.e. workspace right click) onselect: function () { const nn = { _def: { defaults: {} }, From 75d3444391306155aaa3655e39f92a184bf77c53 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 13 Jul 2022 12:43:58 +0100 Subject: [PATCH 3/4] Ensure added junc(s) are selected Feature parity with insert node, insert links etc --- .../@node-red/editor-client/src/js/ui/contextMenu.js | 1 + .../node_modules/@node-red/editor-client/src/js/ui/view-tools.js | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js b/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js index 03517e65b..df37a6d89 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js @@ -97,6 +97,7 @@ RED.contextMenu = (function () { RED.nodes.addJunction(nn); RED.history.push(historyEvent); RED.nodes.dirty(true); + RED.view.select({nodes: [nn] }); RED.view.redraw(true) } }, 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 index 7aa9919e3..bc81d4a43 100644 --- 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 @@ -1187,6 +1187,7 @@ RED.view.tools = (function() { removedLinks: Array.from(removedLinks) }) RED.nodes.dirty(true) + RED.view.select({nodes: addedJunctions }); } RED.view.redraw(true); } From 6e5fc29dca2b372c28be7183430ff0bba63b4c34 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 13 Jul 2022 22:34:22 +0100 Subject: [PATCH 4/4] show add junction when nodes are selected --- .../@node-red/editor-client/src/js/ui/contextMenu.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js b/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js index df37a6d89..66ae2b943 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/contextMenu.js @@ -69,13 +69,12 @@ RED.contextMenu = (function () { }) } }, - (hasSelection || hasLinks) ? { // has nodes or at least 1 wire selected + (hasLinks) ? { // has least 1 wire selected label: RED._("contextMenu.junction"), onselect: 'core:split-wires-with-junctions', disabled: !hasLinks } : { label: RED._("contextMenu.junction"), - disabled: !noSelection, // has 0 nodes, 0 links selected (i.e. workspace right click) onselect: function () { const nn = { _def: { defaults: {} },