Handle releasing ctrl when using quick-add node dialog

This commit is contained in:
Nick O'Leary 2018-06-15 22:33:53 +01:00
parent de35c7024a
commit 2648b7ca54
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
1 changed files with 15 additions and 9 deletions

View File

@ -59,7 +59,9 @@ RED.view = (function() {
dblClickPrimed = null, dblClickPrimed = null,
clickTime = 0, clickTime = 0,
clickElapsed = 0, clickElapsed = 0,
scroll_position; scroll_position = [],
quickAddActive = false,
quickAddLink = null;
var clipboard = ""; var clipboard = "";
@ -569,14 +571,16 @@ RED.view = (function() {
mouse_mode = RED.state.QUICK_JOINING; mouse_mode = RED.state.QUICK_JOINING;
$(window).on('keyup',disableQuickJoinEventHandler); $(window).on('keyup',disableQuickJoinEventHandler);
} }
quickAddActive = true;
RED.typeSearch.show({ RED.typeSearch.show({
x:d3.event.clientX-mainPos.left-node_width/2, x:d3.event.clientX-mainPos.left-node_width/2,
y:d3.event.clientY-mainPos.top-node_height/2, y:d3.event.clientY-mainPos.top-node_height/2,
cancel: function() { cancel: function() {
quickAddActive = false;
resetMouseVars(); resetMouseVars();
}, },
add: function(type) { add: function(type) {
quickAddActive = false;
var result = addNode(type); var result = addNode(type);
if (!result) { if (!result) {
return; return;
@ -585,11 +589,10 @@ RED.view = (function() {
var historyEvent = result.historyEvent; var historyEvent = result.historyEvent;
nn.x = point[0]; nn.x = point[0];
nn.y = point[1]; nn.y = point[1];
if (mouse_mode === RED.state.QUICK_JOINING) { if (mouse_mode === RED.state.QUICK_JOINING || quickAddLink) {
if (drag_lines.length > 0) { if (quickAddLink || drag_lines.length > 0) {
var drag_line = drag_lines[0]; var drag_line = quickAddLink||drag_lines[0];
var src = null,dst,src_port; var src = null,dst,src_port;
if (drag_line.portType === PORT_TYPE_OUTPUT && nn.inputs > 0) { if (drag_line.portType === PORT_TYPE_OUTPUT && nn.inputs > 0) {
src = drag_line.node; src = drag_line.node;
src_port = drag_line.port; src_port = drag_line.port;
@ -604,9 +607,9 @@ RED.view = (function() {
RED.nodes.addLink(link); RED.nodes.addLink(link);
historyEvent.links = [link]; historyEvent.links = [link];
hideDragLines(); hideDragLines();
if (drag_line.portType === PORT_TYPE_OUTPUT && nn.outputs > 0) { if (!quickAddLink && drag_line.portType === PORT_TYPE_OUTPUT && nn.outputs > 0) {
showDragLines([{node:nn,port:0,portType:PORT_TYPE_OUTPUT}]); showDragLines([{node:nn,port:0,portType:PORT_TYPE_OUTPUT}]);
} else if (drag_line.portType === PORT_TYPE_INPUT && nn.inputs > 0) { } else if (!quickAddLink && drag_line.portType === PORT_TYPE_INPUT && nn.inputs > 0) {
showDragLines([{node:nn,port:0,portType:PORT_TYPE_INPUT}]); showDragLines([{node:nn,port:0,portType:PORT_TYPE_INPUT}]);
} else { } else {
resetMouseVars(); resetMouseVars();
@ -624,9 +627,9 @@ RED.view = (function() {
resetMouseVars(); resetMouseVars();
} }
} }
quickAddLink = null;
} }
RED.history.push(historyEvent); RED.history.push(historyEvent);
RED.nodes.add(nn); RED.nodes.add(nn);
RED.editor.validateNode(nn); RED.editor.validateNode(nn);
@ -1412,6 +1415,9 @@ RED.view = (function() {
function disableQuickJoinEventHandler(evt) { function disableQuickJoinEventHandler(evt) {
// Check for ctrl (all browsers), "Meta" (Chrome/FF), keyCode 91 (Safari) // Check for ctrl (all browsers), "Meta" (Chrome/FF), keyCode 91 (Safari)
if (evt.keyCode === 17 || evt.key === "Meta" || evt.keyCode === 91) { if (evt.keyCode === 17 || evt.key === "Meta" || evt.keyCode === 91) {
if (quickAddActive && drag_lines.length > 0) {
quickAddLink = drag_lines[0];
}
resetMouseVars(); resetMouseVars();
hideDragLines(); hideDragLines();
redraw(); redraw();