From 766ccf85c25fb135a6804fba1e76d3f82f0d19f7 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Sun, 20 Jan 2019 14:43:17 +0000 Subject: [PATCH] add fast entry via keyboard for string of nodes --- .../editor-client/src/js/ui/typeSearch.js | 16 +++++++++++++--- .../@node-red/editor-client/src/js/ui/view.js | 16 +++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/typeSearch.js b/packages/node_modules/@node-red/editor-client/src/js/ui/typeSearch.js index 532d84274..a14986f83 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/typeSearch.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/typeSearch.js @@ -48,7 +48,7 @@ RED.typeSearch = (function() { //shade = $('
',{class:"red-ui-type-search-shade"}).appendTo("#main-container"); dialog = $("
",{id:"red-ui-type-search",class:"red-ui-search red-ui-type-search"}).appendTo("#main-container"); var searchDiv = $("
",{class:"red-ui-search-container"}).appendTo(dialog); - searchInput = $('').attr("placeholder",RED._("search.addNode")).appendTo(searchDiv).searchBox({ + searchInput = $('').attr("placeholder",RED._("search.addNode")).appendTo(searchDiv).searchBox({ delay: 50, change: function() { search($(this).val()); @@ -79,6 +79,17 @@ RED.typeSearch = (function() { $(children[selected]).addClass('selected'); ensureSelectedIsVisible(); evt.preventDefault(); + } else if ((evt.metaKey || evt.ctrlKey) && evt.keyCode === 13 ) { + // (ctrl or cmd) and enter + var index = Math.max(0,selected); + if (index < children.length) { + var n = $(children[index]).find(".red-ui-editableList-item-content").data('data'); + typesUsed[n.type] = Date.now(); + if (n.def.outputs === 0) { confirm(n); } + else { addCallback(n.type,true); } + $("#red-ui-type-search-input").val(""); + } + evt.preventDefault(); } else if (evt.keyCode === 13) { // Enter var index = Math.max(0,selected); @@ -202,7 +213,7 @@ RED.typeSearch = (function() { } refreshTypeList(opts); addCallback = opts.add; - closeCallback = opts.close; + cancelCallback = opts.cancel; RED.events.emit("type-search:open"); //shade.show(); dialog.css({left:opts.x+"px",top:opts.y+"px"}).show(); @@ -230,7 +241,6 @@ RED.typeSearch = (function() { $(document).off('click.type-search'); } } - function getTypeLabel(type, def) { var label = type; if (typeof def.paletteLabel !== "undefined") { 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 6c8951b34..c02cce13f 100644 --- 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 @@ -650,10 +650,8 @@ RED.view = (function() { mouse_mode = RED.state.PANNING; mouse_position = [d3.event.pageX,d3.event.pageY] scroll_position = [chart.scrollLeft(),chart.scrollTop()]; - return; } - if (!mousedown_node && !mousedown_link) { selected_link = null; updateSelection(); @@ -692,17 +690,21 @@ RED.view = (function() { cancel: function() { quickAddActive = false; resetMouseVars(); + updateSelection(); + hideDragLines(); + redraw(); }, - add: function(type) { + add: function(type,auto) { quickAddActive = false; + if (auto === true) { mouse_mode = RED.state.QUICK_JOINING; } var result = addNode(type); if (!result) { return; } var nn = result.node; var historyEvent = result.historyEvent; - nn.x = point[0]; - nn.y = point[1]; + nn.x = Math.ceil((point[0] - 50) / gridSize) * gridSize + 50; + nn.y = parseInt(point[1] / gridSize) * gridSize; var showLabel = RED.utils.getMessageProperty(RED.settings.get('editor'),"view.view-node-show-label"); if (showLabel !== undefined && !/^link (in|out)$/.test(nn._def.type) && !nn._def.defaults.hasOwnProperty("l")) { @@ -796,6 +798,7 @@ RED.view = (function() { updateActiveNodes(); updateSelection(); redraw(); + if (auto === true) { point[0] = point[0] + ((nn.w < 100) ? 100 : nn.w) + gridSize * 2; } } }); @@ -850,7 +853,6 @@ RED.view = (function() { mouse_position = d3.touches(this)[0]||d3.mouse(this); - if (lasso) { var ox = parseInt(lasso.attr("ox")); var oy = parseInt(lasso.attr("oy")); @@ -1139,7 +1141,7 @@ RED.view = (function() { updateSelection(); lasso.remove(); lasso = null; - } else if (mouse_mode == RED.state.DEFAULT && mousedown_link == null && !d3.event.ctrlKey&& !d3.event.metaKey ) { + } else if (mouse_mode == RED.state.DEFAULT && mousedown_link == null && !d3.event.ctrlKey && !d3.event.metaKey ) { clearSelection(); updateSelection(); }