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

add fast entry via keyboard for string of nodes

This commit is contained in:
Dave Conway-Jones 2019-01-20 14:43:17 +00:00
parent 7a6e1fe566
commit 766ccf85c2
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 22 additions and 10 deletions

View File

@ -48,7 +48,7 @@ RED.typeSearch = (function() {
//shade = $('<div>',{class:"red-ui-type-search-shade"}).appendTo("#main-container"); //shade = $('<div>',{class:"red-ui-type-search-shade"}).appendTo("#main-container");
dialog = $("<div>",{id:"red-ui-type-search",class:"red-ui-search red-ui-type-search"}).appendTo("#main-container"); dialog = $("<div>",{id:"red-ui-type-search",class:"red-ui-search red-ui-type-search"}).appendTo("#main-container");
var searchDiv = $("<div>",{class:"red-ui-search-container"}).appendTo(dialog); var searchDiv = $("<div>",{class:"red-ui-search-container"}).appendTo(dialog);
searchInput = $('<input type="text">').attr("placeholder",RED._("search.addNode")).appendTo(searchDiv).searchBox({ searchInput = $('<input type="text" id="red-ui-type-search-input">').attr("placeholder",RED._("search.addNode")).appendTo(searchDiv).searchBox({
delay: 50, delay: 50,
change: function() { change: function() {
search($(this).val()); search($(this).val());
@ -79,6 +79,17 @@ RED.typeSearch = (function() {
$(children[selected]).addClass('selected'); $(children[selected]).addClass('selected');
ensureSelectedIsVisible(); ensureSelectedIsVisible();
evt.preventDefault(); 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) { } else if (evt.keyCode === 13) {
// Enter // Enter
var index = Math.max(0,selected); var index = Math.max(0,selected);
@ -202,7 +213,7 @@ RED.typeSearch = (function() {
} }
refreshTypeList(opts); refreshTypeList(opts);
addCallback = opts.add; addCallback = opts.add;
closeCallback = opts.close; cancelCallback = opts.cancel;
RED.events.emit("type-search:open"); RED.events.emit("type-search:open");
//shade.show(); //shade.show();
dialog.css({left:opts.x+"px",top:opts.y+"px"}).show(); dialog.css({left:opts.x+"px",top:opts.y+"px"}).show();
@ -230,7 +241,6 @@ RED.typeSearch = (function() {
$(document).off('click.type-search'); $(document).off('click.type-search');
} }
} }
function getTypeLabel(type, def) { function getTypeLabel(type, def) {
var label = type; var label = type;
if (typeof def.paletteLabel !== "undefined") { if (typeof def.paletteLabel !== "undefined") {

View File

@ -650,10 +650,8 @@ RED.view = (function() {
mouse_mode = RED.state.PANNING; mouse_mode = RED.state.PANNING;
mouse_position = [d3.event.pageX,d3.event.pageY] mouse_position = [d3.event.pageX,d3.event.pageY]
scroll_position = [chart.scrollLeft(),chart.scrollTop()]; scroll_position = [chart.scrollLeft(),chart.scrollTop()];
return; return;
} }
if (!mousedown_node && !mousedown_link) { if (!mousedown_node && !mousedown_link) {
selected_link = null; selected_link = null;
updateSelection(); updateSelection();
@ -692,17 +690,21 @@ RED.view = (function() {
cancel: function() { cancel: function() {
quickAddActive = false; quickAddActive = false;
resetMouseVars(); resetMouseVars();
updateSelection();
hideDragLines();
redraw();
}, },
add: function(type) { add: function(type,auto) {
quickAddActive = false; quickAddActive = false;
if (auto === true) { mouse_mode = RED.state.QUICK_JOINING; }
var result = addNode(type); var result = addNode(type);
if (!result) { if (!result) {
return; return;
} }
var nn = result.node; var nn = result.node;
var historyEvent = result.historyEvent; var historyEvent = result.historyEvent;
nn.x = point[0]; nn.x = Math.ceil((point[0] - 50) / gridSize) * gridSize + 50;
nn.y = point[1]; nn.y = parseInt(point[1] / gridSize) * gridSize;
var showLabel = RED.utils.getMessageProperty(RED.settings.get('editor'),"view.view-node-show-label"); 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")) { if (showLabel !== undefined && !/^link (in|out)$/.test(nn._def.type) && !nn._def.defaults.hasOwnProperty("l")) {
@ -796,6 +798,7 @@ RED.view = (function() {
updateActiveNodes(); updateActiveNodes();
updateSelection(); updateSelection();
redraw(); 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); mouse_position = d3.touches(this)[0]||d3.mouse(this);
if (lasso) { if (lasso) {
var ox = parseInt(lasso.attr("ox")); var ox = parseInt(lasso.attr("ox"));
var oy = parseInt(lasso.attr("oy")); var oy = parseInt(lasso.attr("oy"));
@ -1139,7 +1141,7 @@ RED.view = (function() {
updateSelection(); updateSelection();
lasso.remove(); lasso.remove();
lasso = null; 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(); clearSelection();
updateSelection(); updateSelection();
} }