diff --git a/packages/node_modules/@node-red/editor-client/src/js/nodes.js b/packages/node_modules/@node-red/editor-client/src/js/nodes.js index 1f60acee0..c4b8e2b34 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/nodes.js +++ b/packages/node_modules/@node-red/editor-client/src/js/nodes.js @@ -298,10 +298,14 @@ RED.nodes = (function() { } } - function addWorkspace(ws) { + function addWorkspace(ws,targetIndex) { workspaces[ws.id] = ws; ws._def = RED.nodes.getType('tab'); - workspacesOrder.push(ws.id); + if (targetIndex === undefined) { + workspacesOrder.push(ws.id); + } else { + workspacesOrder.splice(targetIndex,0,ws.id); + } } function getWorkspace(id) { return workspaces[id]; diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/common/tabs.js b/packages/node_modules/@node-red/editor-client/src/js/ui/common/tabs.js index 02736a9b4..1e23febaa 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/common/tabs.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/common/tabs.js @@ -52,6 +52,25 @@ RED.tabs = (function() { } RED.popover.tooltip(addButton,l,options.addButton); } + ul.on("dblclick", function(evt) { + var existingTabs = ul.children(); + var clickX = evt.clientX; + var targetIndex = 0; + existingTabs.each(function(index) { + var pos = $(this).offset(); + if (pos.left > clickX) { + return false; + } + targetIndex = index+1; + }) + if (typeof options.addButton === 'function') { + options.addButton({index:targetIndex}); + } else if (typeof options.addButton === 'string') { + RED.actions.invoke(options.addButton,{index:targetIndex}); + } + }); + + } var scrollLeft; var scrollRight; @@ -321,9 +340,16 @@ RED.tabs = (function() { } return { - addTab: function(tab) { + addTab: function(tab,targetIndex) { tabs[tab.id] = tab; - var li = $("
  • ",{class:"red-ui-tab"}).appendTo(ul); + var li = $("
  • ",{class:"red-ui-tab"}); + if (targetIndex === undefined) { + li.appendTo(ul); + } else if (targetIndex === 0) { + li.prependTo(ul); + } else { + li.insertAfter(ul.find("li:nth-child("+(targetIndex)+")")); + } li.attr('id',"red-ui-tab-"+(tab.id.replace(".","-"))); li.data("tabId",tab.id); diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/workspaces.js b/packages/node_modules/@node-red/editor-client/src/js/ui/workspaces.js index 86171b471..2e8417fa8 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/workspaces.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/workspaces.js @@ -20,7 +20,7 @@ RED.workspaces = (function() { var activeWorkspace = 0; var workspaceIndex = 0; - function addWorkspace(ws,skipHistoryEntry) { + function addWorkspace(ws,skipHistoryEntry,targetIndex) { if (ws) { workspace_tabs.addTab(ws); workspace_tabs.resize(); @@ -31,8 +31,8 @@ RED.workspaces = (function() { } while ($("#workspace-tabs a[title='"+RED._('workspace.defaultName',{number:workspaceIndex})+"']").size() !== 0); ws = {type:"tab",id:tabId,disabled: false,info:"",label:RED._('workspace.defaultName',{number:workspaceIndex})}; - RED.nodes.addWorkspace(ws); - workspace_tabs.addTab(ws); + RED.nodes.addWorkspace(ws,targetIndex); + workspace_tabs.addTab(ws,targetIndex); workspace_tabs.activateTab(tabId); if (!skipHistoryEntry) { RED.history.push({t:'add',workspaces:[ws],dirty:RED.nodes.dirty()}); @@ -320,7 +320,7 @@ RED.workspaces = (function() { workspace_tabs.resize(); }); - RED.actions.add("core:add-flow",addWorkspace); + RED.actions.add("core:add-flow",function(opts) { addWorkspace(undefined,undefined,opts?opts.index:undefined)}); RED.actions.add("core:edit-flow",editWorkspace); RED.actions.add("core:remove-flow",removeWorkspace);