Restore tab order from last session

pull/5322/head
GogoVega 2025-10-23 14:06:58 +02:00
parent 32831cb3b4
commit f380744483
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B
2 changed files with 41 additions and 0 deletions

View File

@ -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) {

View File

@ -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
}