@@ -9,11 +9,7 @@ interface WebviewState {
99 currentView : 'form' | 'text' | 'flags'
1010 commitData : any
1111 textContent : string
12- }
13-
14- // Define the shape of the global flags state
15- interface GlobalFlagsState {
16- flags : Record < string , string [ ] >
12+ flags ?: Record < string , string [ ] >
1713}
1814
1915// New interfaces for our settings structure
@@ -96,14 +92,12 @@ class CommitEditorPanel {
9692 vscode . window . showErrorMessage ( message . text )
9793 return
9894 case 'saveState' :
99- this . _context . workspaceState . update ( 'state' , {
100- currentView : message . state . currentView ,
101- commitData : message . state . commitData ,
102- textContent : message . state . textContent ,
103- } )
104- return
105- case 'saveFlags' :
106- this . _context . globalState . update ( 'flags' , { flags : message . flags } )
95+ // Save flags to global state
96+ if ( message . state . flags ) {
97+ this . _context . globalState . update ( 'flags' , message . state . flags )
98+ }
99+ // Save other state to workspace state
100+ this . _context . workspaceState . update ( 'state' , message . state )
107101 return
108102 case 'openSettings' :
109103 vscode . commands . executeCommand ( 'commitAssistant.openSettings' )
@@ -258,17 +252,25 @@ class CommitEditorPanel {
258252
259253 this . _sendConfig ( )
260254
261- // Send stored state to the webview
255+ // Load state from workspace and global storage
262256 const storedState = this . _context . workspaceState . get < WebviewState > ( 'state' )
263- if ( storedState ) {
264- this . _panel . webview . postMessage ( { command : 'loadState' , state : storedState } )
265- }
257+ const globalFlags = this . _context . globalState . get < Record < string , string [ ] > > ( 'flags' )
266258
267- // Send stored flags to the webview
268- const storedFlags = this . _context . globalState . get < GlobalFlagsState > ( 'flags' )
269- if ( storedFlags ) {
270- this . _panel . webview . postMessage ( { command : 'loadFlags' , flags : storedFlags . flags } )
271- }
259+ // Merge workspace state with global flags
260+ const mergedState = storedState
261+ ? {
262+ ...storedState ,
263+ flags : globalFlags || storedState . flags || { } ,
264+ }
265+ : {
266+ currentView : 'form' ,
267+ commitData : { } ,
268+ textContent : '' ,
269+ flags : globalFlags || { } ,
270+ }
271+
272+ // Send merged state to the webview
273+ this . _panel . webview . postMessage ( { command : 'loadState' , state : mergedState } )
272274 }
273275
274276 private _sendConfig ( ) {
0 commit comments