diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/palette.js b/packages/node_modules/@node-red/editor-client/src/js/ui/palette.js index 9f20cc674..322283fcb 100755 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/palette.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/palette.js @@ -175,9 +175,19 @@ RED.palette = (function() { $('').appendTo(popOverContent) } - var safeType = type.replace(/'/g,"\\'"); + const safeType = type.replace(/'/g,"\\'"); + function wrapStr(str) { + if(str.indexOf(' ') >= 0) { + return '"' + str + '"' + } + return str + } - $('').appendTo(popOverContent) + $('') + .appendTo(popOverContent) + .on('click', function() { + RED.search.show('type:' + wrapStr(safeType)) + }) $('').appendTo(popOverContent) $('

',{style:"font-size: 0.8em"}).text(metaData).appendTo(popOverContent); diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/search.js b/packages/node_modules/@node-red/editor-client/src/js/ui/search.js index f9cc79f08..d8035908a 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/search.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/search.js @@ -106,14 +106,26 @@ RED.search = (function() { return val; } + function extractType(val, flags) { + // extracts: type:XYZ & type:"X Y Z" + console.log(`extractType(val, flags): val:${val}`) + const regEx = /(?:type):\s*(?:"([^"]+)"|([^" ]+))/; + let m + while ((m = regEx.exec(val)) !== null) { + // avoid infinite loops with zero-width matches + if (m.index === regEx.lastIndex) { + regEx.lastIndex++; + } + val = val.replace(m[0]," ").trim() + const flag = m[2] || m[1] // quoted entries in capture group 1, unquoted in capture group 2 + flags.type = flags.type || []; + flags.type.push(flag); + } + return val; + } + function search(val) { var results = []; - var typeFilter; - var m = /(?:^| )type:([^ ]+)/.exec(val); - if (m) { - val = val.replace(/(?:^| )type:[^ ]+/,""); - typeFilter = m[1]; - } var flags = {}; val = extractFlag(val,"invalid",flags); val = extractFlag(val,"unused",flags); @@ -121,18 +133,20 @@ RED.search = (function() { val = extractFlag(val,"subflow",flags); val = extractFlag(val,"hidden",flags); val = extractFlag(val,"modified",flags); - val = extractValue(val,"flow",flags);// flow:active or flow: + val = extractValue(val,"flow",flags);// flow:current or flow: val = extractValue(val,"uses",flags);// uses: + val = extractType(val,flags);// uses: val = val.trim(); var hasFlags = Object.keys(flags).length > 0; if (flags.flow && flags.flow.indexOf("current") >= 0) { let idx = flags.flow.indexOf("current"); - flags.flow[idx] = RED.workspaces.active();//convert active to flow ID + flags.flow[idx] = RED.workspaces.active();//convert 'current' to active flow ID } if (flags.flow && flags.flow.length) { flags.flow = [ ...new Set(flags.flow) ]; //deduplicate } - if (val.length > 0 || typeFilter || hasFlags) { + const hasTypeFilter = flags.type && flags.type.length > 0 + if (val.length > 0 || hasFlags) { val = val.toLowerCase(); var i; var j; @@ -146,8 +160,8 @@ RED.search = (function() { } for (i=0;i -1) { + var kpos = val ? keys[i].indexOf(val) : -1; + if (kpos > -1 || (val === "" && hasTypeFilter)) { var ids = Object.keys(index[key]||{}); for (j=0;j -1) { + nodes[node.node.id] = nodes[node.node.id] || { node: node.node, label: node.label }; - nodes[node.node.id].index = Math.min(nodes[node.node.id].index||Infinity,kpos); + nodes[node.node.id].index = Math.min(nodes[node.node.id].index || Infinity, typeIndex > -1 ? typeIndex : kpos); } } }