From deb9c4ecc098d2cdbecdd777be5a5819ea54dad2 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 9 Jun 2022 15:47:16 -0500 Subject: [PATCH 1/2] Reset mouse state when switching tabs Fixes #3639 --- .../@node-red/editor-client/src/js/ui/view.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/view.js b/packages/node_modules/@node-red/editor-client/src/js/ui/view.js index adab87e38..7d4d950f3 100755 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/view.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/view.js @@ -385,6 +385,9 @@ RED.view = (function() { drag_lines = []; RED.events.on("workspace:change",function(event) { + // Just in case the mouse left the workspace whilst doing an action, + // put us back into default mode so the refresh works + mouse_mode = 0 if (event.old !== 0) { workspaceScrollPositions[event.old] = { left:chart.scrollLeft(), @@ -955,7 +958,7 @@ RED.view = (function() { } function canvasMouseDown() { - if (RED.view.DEBUG) { + if (RED.view.DEBUG) { console.warn("canvasMouseDown", { mouse_mode, point: d3.mouse(this), event: d3.event }); } if (mouse_mode === RED.state.SELECTING_NODE) { @@ -1719,7 +1722,7 @@ RED.view = (function() { function canvasMouseUp() { lastClickPosition = [d3.event.offsetX/scaleFactor,d3.event.offsetY/scaleFactor]; - if (RED.view.DEBUG) { + if (RED.view.DEBUG) { console.warn("canvasMouseUp", { mouse_mode, point: d3.mouse(this), event: d3.event }); } var i; @@ -3719,7 +3722,7 @@ RED.view = (function() { function junctionMouseOutProxy(e) { junctionMouseOut(d3.select(this), this.__data__) } function linkMouseDown(d) { - if (RED.view.DEBUG) { + if (RED.view.DEBUG) { console.warn("linkMouseDown", { mouse_mode, point: d3.mouse(this), event: d3.event }); } if (mouse_mode === RED.state.SELECTING_NODE) { From a16032a8ede59fa838ea235a9bce62ac13d879fa Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 13 Jun 2022 21:01:34 +0100 Subject: [PATCH 2/2] Track mouse release outside workspace so current action completes --- .../@node-red/editor-client/src/js/ui/view.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/view.js b/packages/node_modules/@node-red/editor-client/src/js/ui/view.js index 7d4d950f3..a3bc16e9d 100755 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/view.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/view.js @@ -230,6 +230,7 @@ RED.view = (function() { .on("mousedown", canvasMouseDown) .on("mouseup", canvasMouseUp) .on("mouseenter", function() { + d3.select(document).on('mouseup.red-ui-workspace-tracker', null) if (lasso) { if (d3.event.buttons !== 1) { lasso.remove(); @@ -245,6 +246,7 @@ RED.view = (function() { } } }) + .on("mouseleave", canvasMouseLeave) .on("touchend", function() { d3.event.preventDefault(); clearTimeout(touchStartTime); @@ -1719,7 +1721,14 @@ RED.view = (function() { redraw(); } } - + function canvasMouseLeave() { + if (mouse_mode !== 0 && d3.event.buttons !== 0) { + d3.select(document).on('mouseup.red-ui-workspace-tracker', function() { + d3.select(document).on('mouseup.red-ui-workspace-tracker', null) + canvasMouseUp.call(this) + }) + } + } function canvasMouseUp() { lastClickPosition = [d3.event.offsetX/scaleFactor,d3.event.offsetY/scaleFactor]; if (RED.view.DEBUG) {