Skip to content

Commit f5b89f8

Browse files
author
sunzhongyi
committed
feat: 修改 flags 为全局存储
1 parent e8d6123 commit f5b89f8

File tree

2 files changed

+27
-35
lines changed

2 files changed

+27
-35
lines changed

extension.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {

webviews/commit-editor/App.svelte

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@
100100
commitData.selectedFlags = loadedCommitData.selectedFlags || []
101101
}
102102
textContent = state.textContent || ''
103-
break
104-
case 'loadFlags':
105-
flags = message.flags || {}
103+
flags = state.flags || {}
106104
break
107105
case 'loadConfig':
108106
flags = message.config.flags || {}
@@ -153,18 +151,10 @@
153151
JSON.stringify(commitData)
154152
JSON.stringify(flags)
155153
156-
// Post the state to the extension host (without flags)
154+
// Post the state to the extension host
157155
vscode.postMessage({
158156
command: 'saveState',
159-
state: { currentView, commitData, textContent },
160-
})
161-
}
162-
163-
// Separate reactive block for flags to save them globally
164-
$: if (flags) {
165-
vscode.postMessage({
166-
command: 'saveFlags',
167-
flags: flags,
157+
state: { currentView, commitData, textContent, flags },
168158
})
169159
}
170160
</script>

0 commit comments

Comments
 (0)