@@ -53,24 +53,94 @@ export class SidePanel extends AbstractPanel {
5353 // Toggle content
5454 this . on ( 'menuicons' , 'toggleContent' , ( name ) => {
5555 if ( ! this . plugins [ name ] ) return
56+
57+ // If panel is hidden, always show it when any icon is clicked
58+ if ( this . isHidden ) {
59+ this . isHidden = false
60+
61+ // Immediately remove d-none class for instant visual feedback
62+ const sidePanel = document . querySelector ( '#side-panel' )
63+ sidePanel ?. classList . remove ( 'd-none' )
64+
65+ // Update localStorage before showing content
66+ const panelStates = JSON . parse ( window . localStorage . getItem ( 'panelStates' ) || '{}' )
67+ if ( ! panelStates . leftSidePanel ) panelStates . leftSidePanel = { }
68+ panelStates . leftSidePanel . isHidden = false
69+ panelStates . leftSidePanel . pluginProfile = this . plugins [ name ] ?. profile
70+ window . localStorage . setItem ( 'panelStates' , JSON . stringify ( panelStates ) )
71+
72+ this . showContent ( name )
73+ this . emit ( 'leftSidePanelShown' )
74+ this . events . emit ( 'leftSidePanelShown' )
75+ return
76+ }
77+
78+ // Panel is visible - check if plugin is active
5679 if ( this . plugins [ name ] . active ) {
57- // TODO: Only keep `this.emit` (issue#2210)
58- this . emit ( 'toggle' , name )
59- this . events . emit ( 'toggle' , name )
80+ // Plugin is active, so toggling will hide the panel
81+ this . isHidden = true
82+
83+ // Immediately add d-none class for instant visual feedback
84+ const sidePanel = document . querySelector ( '#side-panel' )
85+ sidePanel ?. classList . add ( 'd-none' )
86+
87+ // Update localStorage
88+ const panelStates = JSON . parse ( window . localStorage . getItem ( 'panelStates' ) || '{}' )
89+ panelStates . leftSidePanel = {
90+ isHidden : true ,
91+ pluginProfile : this . plugins [ name ] ?. profile
92+ }
93+ window . localStorage . setItem ( 'panelStates' , JSON . stringify ( panelStates ) )
94+
95+ // Emit explicit panel state events for proper synchronization
96+ this . emit ( 'leftSidePanelHidden' )
97+ this . events . emit ( 'leftSidePanelHidden' )
6098 return
6199 }
100+
101+ // Plugin is not active, show it
102+ const panelStates = JSON . parse ( window . localStorage . getItem ( 'panelStates' ) || '{}' )
103+ if ( ! panelStates . leftSidePanel ) panelStates . leftSidePanel = { }
104+ panelStates . leftSidePanel . isHidden = false
105+ panelStates . leftSidePanel . pluginProfile = this . plugins [ name ] ?. profile
106+ window . localStorage . setItem ( 'panelStates' , JSON . stringify ( panelStates ) )
107+
62108 this . showContent ( name )
63- // TODO: Only keep `this.emit` (issue#2210)
64- this . emit ( 'showing' , name )
65- this . events . emit ( 'showing' , name )
109+ this . emit ( 'leftSidePanelShown' )
110+ this . events . emit ( 'leftSidePanelShown' )
66111 } )
67112 // Force opening
68113 this . on ( 'menuicons' , 'showContent' , ( name ) => {
69114 if ( ! this . plugins [ name ] ) return
70- this . showContent ( name )
71- // TODO: Only keep `this.emit` (issue#2210)
72- this . emit ( 'showing' , name )
73- this . events . emit ( 'showing' , name )
115+
116+ // Read the saved state from localStorage to check if panel should stay hidden
117+ const panelStates = JSON . parse ( window . localStorage . getItem ( 'panelStates' ) || '{}' )
118+ const savedIsHidden = panelStates . leftSidePanel ?. isHidden
119+
120+ // If panel is currently hidden AND it was intentionally hidden (saved in localStorage),
121+ // just load content without showing the panel (this happens during initialization)
122+ if ( this . isHidden && savedIsHidden === true ) {
123+ this . showContent ( name )
124+ return
125+ }
126+
127+ // Otherwise, force show the panel if it's hidden
128+ if ( this . isHidden ) {
129+ this . isHidden = false
130+
131+ // Update localStorage
132+ if ( ! panelStates . leftSidePanel ) panelStates . leftSidePanel = { }
133+ panelStates . leftSidePanel . isHidden = false
134+ panelStates . leftSidePanel . pluginProfile = this . plugins [ name ] ?. profile
135+ window . localStorage . setItem ( 'panelStates' , JSON . stringify ( panelStates ) )
136+
137+ this . showContent ( name )
138+ this . emit ( 'leftSidePanelShown' )
139+ this . events . emit ( 'leftSidePanelShown' )
140+ } else {
141+ // Panel is already visible, just switch content
142+ this . showContent ( name )
143+ }
74144 } )
75145 }
76146
0 commit comments