1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #3727 from node-red/rh-click-link-actions

Update add-junction menu to work in more cases
This commit is contained in:
Nick O'Leary 2022-07-01 12:22:00 +01:00 committed by GitHub
commit db7e196bf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,7 +43,16 @@ RED.contextMenu = (function() {
const isGroup = hasSelection && selection.nodes.length === 1 && selection.nodes[0].type === 'group'
const canRemoveFromGroup = hasSelection && !!selection.nodes[0].g
const offset = $("#red-ui-workspace-chart").offset()
let addX = options.x - offset.left + $("#red-ui-workspace-chart").scrollLeft()
let addY = options.y - offset.top + $("#red-ui-workspace-chart").scrollTop()
if (RED.view.snapGrid) {
const gridSize = RED.view.gridSize()
addX = gridSize*Math.floor(addX/gridSize)
addY = gridSize*Math.floor(addY/gridSize)
}
const menuItems = [
{ onselect: 'core:show-action-list', onpostselect: function() {} },
@ -54,17 +63,42 @@ RED.contextMenu = (function() {
label: RED._("contextMenu.node"),
onselect: function() {
RED.view.showQuickAddDialog({
position: [ options.x - offset.left, options.y - offset.top ],
position: [ addX, addY ],
touchTrigger: true,
splice: isSingleLink?selection.links[0]:undefined,
// spliceMultiple: isMultipleLinks
})
}
},
{
( hasSelection || hasLinks ) ? {
label: RED._("contextMenu.junction"),
onselect: 'core:split-wires-with-junctions',
disabled: hasSelection || !hasLinks
disabled: !hasLinks
} : {
label: RED._("contextMenu.junction"),
onselect: function() {
const nn = {
_def: {defaults:{}},
type: 'junction',
z: RED.workspaces.active(),
id: RED.nodes.id(),
x: addX,
y: addY,
w: 0, h: 0,
outputs: 1,
inputs: 1,
dirty: true
}
const historyEvent = {
dirty: RED.nodes.dirty(),
t:'add',
junctions:[nn]
}
RED.nodes.addJunction(nn);
RED.history.push(historyEvent);
RED.nodes.dirty(true);
RED.view.redraw(true)
}
},
{
label: RED._("contextMenu.linkNodes"),
@ -118,7 +152,6 @@ RED.contextMenu = (function() {
}
}
const offset = $("#red-ui-workspace-chart").offset()
menu = RED.menu.init({
direction: 'right',
onpreselect: function() {