diff --git a/packages/node_modules/@node-red/editor-client/src/js/red.js b/packages/node_modules/@node-red/editor-client/src/js/red.js index 99cb8375b..7a4dcc674 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/red.js +++ b/packages/node_modules/@node-red/editor-client/src/js/red.js @@ -250,10 +250,12 @@ var RED = (function() { RED.nodes.import(nodes.flows); RED.nodes.dirty(false); RED.view.redraw(true); + let activeWorkspace = 0; if (/^#(flow|node|group)\/.+$/.test(currentHash)) { const hashParts = currentHash.split('/') const showEditDialog = hashParts.length > 2 && hashParts[2] === 'edit' if (hashParts[0] === '#flow') { + activeWorkspace = hashParts[1]; RED.workspaces.show(hashParts[1], true); if (showEditDialog) { RED.workspaces.edit() @@ -283,6 +285,25 @@ var RED = (function() { } } if (RED.workspaces.count() > 0) { + const tabOrder = JSON.parse(RED.settings.getLocal("tabOrder") || "[]"); + + if (tabOrder.length) { + // Checks that the last session order contains all current flows + // Otherwise, ignore the reorder + const currentOrder = RED.nodes.getWorkspaceOrder(); + const orderNotUpToDate = currentOrder.some((t) => !tabOrder.includes(t)); + if (!orderNotUpToDate) { + for (const tab of tabOrder) { + // Add missing tabs + RED.workspaces.show(tab, true); + } + // Restore the order from the last session + RED.workspaces.order(tabOrder); + // Select the active workspace again because adding missing tab has changed it + RED.workspaces.show(activeWorkspace, true); + } + } + const hiddenTabs = JSON.parse(RED.settings.getLocal("hiddenTabs")||"{}"); const workspaces = RED.nodes.getWorkspaceOrder(); if (RED.workspaces.active() === 0) { 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 78e1399cd..cf1bf20c8 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 @@ -413,6 +413,13 @@ RED.workspaces = (function() { if (workspaceTabCount === 1) { showWorkspace(); } + + // Save the new state of tab order in the local storage + const tabOrder = JSON.parse(RED.settings.getLocal("tabOrder") || "[]"); + if (!tabOrder.includes(tab.id)) { + tabOrder.push(tab.id); + RED.settings.setLocal("tabOrder", JSON.stringify(tabOrder)); + } }, onremove: function(tab) { if (tab.type === "tab") { @@ -425,6 +432,14 @@ RED.workspaces = (function() { if (workspaceTabCount === 0) { hideWorkspace(); } + + // Save the new state of tab order in the local storage + const tabOrder = JSON.parse(RED.settings.getLocal("tabOrder") || "[]"); + const index = tabOrder.indexOf(tab.id); + if (index > -1) { + tabOrder.splice(index, 1); + RED.settings.setLocal("tabOrder", JSON.stringify(tabOrder)); + } }, onreorder: function(oldOrder, newOrder) { RED.history.push({ @@ -443,6 +458,9 @@ RED.workspaces = (function() { RED.nodes.dirty(true); setWorkspaceOrder(newOrder); } + + // Save the new state of tab order in the local storage + RED.settings.setLocal("tabOrder", JSON.stringify(newOrder)); }, onselect: function(selectedTabs) { RED.view.select(false) @@ -829,6 +847,8 @@ RED.workspaces = (function() { RED.events.emit("flows:reorder",newOrder); } workspace_tabs.order(order); + // Save the new state of tab order in the local storage + RED.settings.setLocal("tabOrder", JSON.stringify(order)); return newOrder }