Skip to content

Commit e1eddb2

Browse files
authored
Merge pull request #5605 from node-red/3431-store-sidebar-widths
[3431] feature: Store sidebar width between editor sessions
2 parents 615b799 + 2dddc59 commit e1eddb2

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

  • packages/node_modules/@node-red/editor-client/src/js/ui

packages/node_modules/@node-red/editor-client/src/js/ui/sidebar.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,21 @@ RED.sidebar = (function() {
5757
const state = {
5858
primary: { top: { tabs: [] }, bottom: { tabs: [] } },
5959
secondary: { top: { tabs: [] }, bottom: { tabs: [] } },
60-
v: sidebarLayoutVersion
60+
v: sidebarLayoutVersion,
61+
dimensions: {
62+
// Store split as px for reliable restore before render in init()
63+
// since container height may not be available until after render
64+
primary: {
65+
width: sidebars.primary.container ? sidebars.primary.container.width() : sidebars.primary.defaultWidth,
66+
splitPx: sidebars.primary.sections.top.container.outerHeight() || (sidebars.primary.container ? sidebars.primary.container.height() * sidebars.primary.defaultTopHeight : 300)
67+
},
68+
secondary: {
69+
width: sidebars.secondary.container ? sidebars.secondary.container.width() : sidebars.secondary.defaultWidth,
70+
splitPx: sidebars.secondary.sections.top.container.outerHeight() || (sidebars.secondary.container ? sidebars.secondary.container.height() * sidebars.secondary.defaultTopHeight : 300)
71+
}
72+
}
6173
}
74+
6275
function getTabButtons(tabBar) {
6376
const result = []
6477
tabBar.children('button').each(function() {
@@ -585,6 +598,7 @@ RED.sidebar = (function() {
585598
sidebar.tabBar.css('min-width', sidebar.container.width() - 5)
586599
}
587600
RED.events.emit("sidebar:resize");
601+
exportSidebarState();
588602
}
589603
});
590604
return separator
@@ -748,6 +762,7 @@ RED.sidebar = (function() {
748762
sidebar.resizeSidebar()
749763
},
750764
stop:function(event,ui) {
765+
exportSidebarState();
751766
}
752767
});
753768

@@ -841,6 +856,25 @@ RED.sidebar = (function() {
841856
sidebars.primary.tabBars.bottom.active = lastSessionSelectedTabs?.primary?.bottom?.active
842857
sidebars.secondary.tabBars.top.active = lastSessionSelectedTabs?.secondary?.top?.active
843858
sidebars.secondary.tabBars.bottom.active = lastSessionSelectedTabs?.secondary?.bottom?.active
859+
860+
// Restore sidebar widths and splitPx if present
861+
if (lastSessionSelectedTabs?.dimensions) {
862+
if (lastSessionSelectedTabs.dimensions.primary?.width) {
863+
sidebars.primary.container.width(lastSessionSelectedTabs.dimensions.primary.width)
864+
}
865+
if (lastSessionSelectedTabs.dimensions.secondary?.width) {
866+
sidebars.secondary.container.width(lastSessionSelectedTabs.dimensions.secondary.width)
867+
}
868+
869+
if (lastSessionSelectedTabs.dimensions.primary?.splitPx) {
870+
sidebars.primary.sections.top.container.outerHeight(lastSessionSelectedTabs.dimensions.primary.splitPx);
871+
sidebars.primary.sections.top.height = lastSessionSelectedTabs.dimensions.primary.splitPx;
872+
}
873+
if (lastSessionSelectedTabs.dimensions.secondary?.splitPx) {
874+
sidebars.secondary.sections.top.container.outerHeight(lastSessionSelectedTabs.dimensions.secondary.splitPx);
875+
sidebars.secondary.sections.top.height = lastSessionSelectedTabs.dimensions.secondary.splitPx;
876+
}
877+
}
844878
}
845879

846880
return {

0 commit comments

Comments
 (0)