mirror of
https://github.com/node-red/node-red
synced 2024-11-21 15:43:16 +00:00
Improve the node name auto-generated with the first available nb
This commit is contained in:
parent
27b54199f5
commit
a7b1ce0cf8
@ -1102,18 +1102,27 @@ RED.view.tools = (function() {
|
|||||||
const paletteLabel = RED.utils.getPaletteLabel(n.type, nodeDef)
|
const paletteLabel = RED.utils.getPaletteLabel(n.type, nodeDef)
|
||||||
const defaultNodeNameRE = new RegExp('^'+paletteLabel.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')+' (\\d+)$')
|
const defaultNodeNameRE = new RegExp('^'+paletteLabel.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')+' (\\d+)$')
|
||||||
if (!typeIndex.hasOwnProperty(n.type)) {
|
if (!typeIndex.hasOwnProperty(n.type)) {
|
||||||
const existingNodes = RED.nodes.filterNodes({type: n.type})
|
const existingNodes = RED.nodes.filterNodes({ type: n.type });
|
||||||
let maxNameNumber = 0;
|
const existingIds = existingNodes.reduce((ids, node) => {
|
||||||
existingNodes.forEach(n => {
|
let match = defaultNodeNameRE.exec(node.name);
|
||||||
let match = defaultNodeNameRE.exec(n.name)
|
|
||||||
if (match) {
|
if (match) {
|
||||||
let nodeNumber = parseInt(match[1])
|
const nodeNumber = parseInt(match[1], 10);
|
||||||
if (nodeNumber > maxNameNumber) {
|
if (!ids.includes(nodeNumber)) {
|
||||||
maxNameNumber = nodeNumber
|
ids.push(nodeNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
return ids;
|
||||||
typeIndex[n.type] = maxNameNumber + 1
|
}, []).sort((a, b) => a - b);
|
||||||
|
|
||||||
|
let availableNameNumber = 1;
|
||||||
|
for (let i = 0; i < existingIds.length; i++) {
|
||||||
|
if (existingIds[i] !== availableNameNumber) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
availableNameNumber++;
|
||||||
|
}
|
||||||
|
|
||||||
|
typeIndex[n.type] = availableNameNumber;
|
||||||
}
|
}
|
||||||
if ((options.renameBlank && n.name === '') || (options.renameClash && defaultNodeNameRE.test(n.name))) {
|
if ((options.renameBlank && n.name === '') || (options.renameClash && defaultNodeNameRE.test(n.name))) {
|
||||||
if (generateHistory) {
|
if (generateHistory) {
|
||||||
|
Loading…
Reference in New Issue
Block a user