fix context menu insert junc/links enabled state

This commit is contained in:
Steve-Mcl 2022-07-13 12:42:55 +01:00
parent e2f42fddb5
commit c648e1e8d6
1 changed files with 8 additions and 4 deletions

View File

@ -30,11 +30,14 @@ RED.contextMenu = (function () {
} }
const selection = RED.view.selection() const selection = RED.view.selection()
const noSelection = !selection || Object.keys(selection).length === 0
const hasSelection = (selection.nodes && selection.nodes.length > 0); const hasSelection = (selection.nodes && selection.nodes.length > 0);
const hasMultipleSelection = hasSelection && selection.nodes.length > 1; const hasMultipleSelection = hasSelection && selection.nodes.length > 1;
const hasLinks = selection.links && selection.links.length > 0; const virtulLinks = (selection.links && selection.links.filter(e => !!e.link)) || [];
const isSingleLink = !hasSelection && hasLinks && selection.links.length === 1 const wireLinks = (selection.links && selection.links.filter(e => !e.link)) || [];
const isMultipleLinks = !hasSelection && hasLinks && selection.links.length > 1 const hasLinks = wireLinks.length > 0;
const isSingleLink = !hasSelection && hasLinks && wireLinks.length === 1
const isMultipleLinks = !hasSelection && hasLinks && wireLinks.length > 1
const canDelete = hasSelection || hasLinks const canDelete = hasSelection || hasLinks
const isGroup = hasSelection && selection.nodes.length === 1 && selection.nodes[0].type === 'group' 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"), label: RED._("contextMenu.junction"),
onselect: 'core:split-wires-with-junctions', onselect: 'core:split-wires-with-junctions',
disabled: !hasLinks disabled: !hasLinks
} : { } : {
label: RED._("contextMenu.junction"), label: RED._("contextMenu.junction"),
disabled: !noSelection, // has 0 nodes, 0 links selected (i.e. workspace right click)
onselect: function () { onselect: function () {
const nn = { const nn = {
_def: { defaults: {} }, _def: { defaults: {} },