mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	fix searching by type when type name has a space
This commit is contained in:
		@@ -175,9 +175,19 @@ RED.palette = (function() {
 | 
			
		||||
                    $('<button type="button" onclick="RED.workspaces.show(\''+type.substring(8).replace(/'/g,"\\'")+'\'); return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-pencil"></i></button>').appendTo(popOverContent)
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                var safeType = type.replace(/'/g,"\\'");
 | 
			
		||||
                const safeType = type.replace(/'/g,"\\'");
 | 
			
		||||
                function wrapStr(str) {
 | 
			
		||||
                    if(str.indexOf(' ') >= 0) {
 | 
			
		||||
                        return '"' + str + '"'
 | 
			
		||||
                    }
 | 
			
		||||
                    return str
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                $('<button type="button" onclick="RED.search.show(\'type:'+safeType+'\'); return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-search"></i></button>').appendTo(popOverContent)
 | 
			
		||||
                $('<button type="button"; return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-search"></i></button>')
 | 
			
		||||
                    .appendTo(popOverContent)
 | 
			
		||||
                    .on('click', function() {
 | 
			
		||||
                        RED.search.show('type:' + wrapStr(safeType))
 | 
			
		||||
                    })
 | 
			
		||||
                $('<button type="button" onclick="RED.sidebar.help.show(\''+safeType+'\'); return false;" class="red-ui-button red-ui-button-small" style="float: right; margin-left: 5px;"><i class="fa fa-book"></i></button>').appendTo(popOverContent)
 | 
			
		||||
 | 
			
		||||
                $('<p>',{style:"font-size: 0.8em"}).text(metaData).appendTo(popOverContent);
 | 
			
		||||
 
 | 
			
		||||
@@ -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:<flow-id>
 | 
			
		||||
        val = extractValue(val,"flow",flags);// flow:current or flow:<flow-id>
 | 
			
		||||
        val = extractValue(val,"uses",flags);// uses:<node-id>
 | 
			
		||||
        val = extractType(val,flags);// uses:<node-id>
 | 
			
		||||
        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<keys.length;i++) {
 | 
			
		||||
                var key = keys[i];
 | 
			
		||||
                var kpos = keys[i].indexOf(val);
 | 
			
		||||
                if (kpos > -1) {
 | 
			
		||||
                var kpos = val ? keys[i].indexOf(val) : -1;
 | 
			
		||||
                if (kpos > -1 || (val === "" && hasTypeFilter)) {
 | 
			
		||||
                    var ids = Object.keys(index[key]||{});
 | 
			
		||||
                    for (j=0;j<ids.length;j++) {
 | 
			
		||||
                        var node = index[key][ids[j]];
 | 
			
		||||
@@ -197,12 +211,16 @@ RED.search = (function() {
 | 
			
		||||
                                continue;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        if (!typeFilter || node.node.type === typeFilter) {
 | 
			
		||||
                            nodes[node.node.id] = nodes[node.node.id] = {
 | 
			
		||||
                        let typeIndex = -1
 | 
			
		||||
                        if(hasTypeFilter) {
 | 
			
		||||
                            typeIndex = flags.type.indexOf(node.node.type)
 | 
			
		||||
                        }
 | 
			
		||||
                        if (!hasTypeFilter || typeIndex > -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);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user