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

Better distinguish between ctrl and meta keys on mac

Fixes #4206, #4205
This commit is contained in:
Nick O'Leary 2023-09-05 12:36:44 +01:00
parent de63e17a4d
commit d307968880
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -302,11 +302,21 @@ RED.view = (function() {
return api
})()
const isMac = RED.utils.getBrowserInfo().os === 'mac'
// 'Control' is the main modifier key for mouse actions. On Windows,
// that is the standard Ctrl key. On Mac that is the Cmd key.
function isControlPressed (event) {
return (isMac && event.metaKey) || (!isMac && event.ctrlKey)
}
function init() {
chart = $("#red-ui-workspace-chart");
chart.on('contextmenu', function(evt) {
if (RED.view.DEBUG) {
console.warn("contextmenu", { mouse_mode, event: d3.event });
}
mouse_mode = RED.state.DEFAULT
evt.preventDefault()
evt.stopPropagation()
RED.contextMenu.show({
@ -1190,7 +1200,7 @@ RED.view = (function() {
lasso = null;
}
if (d3.event.touches || d3.event.button === 0) {
if ((mouse_mode === 0 || mouse_mode === RED.state.QUICK_JOINING) && (d3.event.metaKey || d3.event.ctrlKey) && !(d3.event.altKey || d3.event.shiftKey)) {
if ((mouse_mode === 0 || mouse_mode === RED.state.QUICK_JOINING) && isControlPressed(d3.event) && !(d3.event.altKey || d3.event.shiftKey)) {
// Trigger quick add dialog
d3.event.stopPropagation();
clearSelection();
@ -1200,7 +1210,7 @@ RED.view = (function() {
clickedGroup = clickedGroup || RED.nodes.group(drag_lines[0].node.g)
}
showQuickAddDialog({ position: point, group: clickedGroup });
} else if (mouse_mode === 0 && !(d3.event.metaKey || d3.event.ctrlKey)) {
} else if (mouse_mode === 0 && !isControlPressed(d3.event)) {
// CTRL not being held
if (!d3.event.altKey) {
// ALT not held (shift is allowed) Trigger lasso
@ -3540,7 +3550,7 @@ RED.view = (function() {
d3.event.preventDefault()
document.getSelection().removeAllRanges()
if (d.type != "subflow") {
if (/^subflow:/.test(d.type) && (d3.event.ctrlKey || d3.event.metaKey)) {
if (/^subflow:/.test(d.type) && isControlPressed(d3.event)) {
RED.workspaces.show(d.type.substring(8));
} else {
RED.editor.edit(d);
@ -3704,12 +3714,12 @@ RED.view = (function() {
d.type !== 'junction'
lastClickNode = mousedown_node;
if (d.selected && (d3.event.ctrlKey||d3.event.metaKey)) {
if (d.selected && isControlPressed(d3.event)) {
mousedown_node.selected = false;
movingSet.remove(mousedown_node);
} else {
if (d3.event.shiftKey) {
if (!(d3.event.ctrlKey||d3.event.metaKey)) {
if (!isControlPressed(d3.event)) {
clearSelection();
}
var clickPosition = (d3.event.offsetX/scaleFactor - mousedown_node.x)
@ -3878,10 +3888,10 @@ RED.view = (function() {
}
mousedown_link = d;
if (!(d3.event.metaKey || d3.event.ctrlKey)) {
if (!isControlPressed(d3.event)) {
clearSelection();
}
if (d3.event.metaKey || d3.event.ctrlKey) {
if (isControlPressed(d3.event)) {
if (!selectedLinks.has(mousedown_link)) {
selectedLinks.add(mousedown_link);
} else {
@ -3896,7 +3906,7 @@ RED.view = (function() {
redraw();
focusView();
d3.event.stopPropagation();
if (!mousedown_link.link && movingSet.length() === 0 && (d3.event.touches || d3.event.button === 0) && selectedLinks.length() === 1 && selectedLinks.has(mousedown_link) && (d3.event.metaKey || d3.event.ctrlKey)) {
if (!mousedown_link.link && movingSet.length() === 0 && (d3.event.touches || d3.event.button === 0) && selectedLinks.length() === 1 && selectedLinks.has(mousedown_link) && isControlPressed(d3.event)) {
d3.select(this).classed("red-ui-flow-link-splice",true);
var point = d3.mouse(this);
var clickedGroup = getGroupAt(point[0],point[1]);
@ -3977,7 +3987,7 @@ RED.view = (function() {
);
lastClickNode = g;
if (g.selected && (d3.event.ctrlKey||d3.event.metaKey)) {
if (g.selected && isControlPressed(d3.event)) {
selectedGroups.remove(g);
d3.event.stopPropagation();
} else {