Skip to content

Commit e8d6123

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

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

extension.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ 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 {
1216
flags: Record<string, string[]>
1317
}
1418

@@ -92,7 +96,14 @@ class CommitEditorPanel {
9296
vscode.window.showErrorMessage(message.text)
9397
return
9498
case 'saveState':
95-
this._context.workspaceState.update('state', message.state)
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 })
96107
return
97108
case 'openSettings':
98109
vscode.commands.executeCommand('commitAssistant.openSettings')
@@ -252,6 +263,12 @@ class CommitEditorPanel {
252263
if (storedState) {
253264
this._panel.webview.postMessage({ command: 'loadState', state: storedState })
254265
}
266+
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+
}
255272
}
256273

257274
private _sendConfig() {

webviews/commit-editor/App.svelte

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@
100100
commitData.selectedFlags = loadedCommitData.selectedFlags || []
101101
}
102102
textContent = state.textContent || ''
103-
flags = state.flags || {}
103+
break
104+
case 'loadFlags':
105+
flags = message.flags || {}
104106
break
105107
case 'loadConfig':
106108
flags = message.config.flags || {}
@@ -151,10 +153,18 @@
151153
JSON.stringify(commitData)
152154
JSON.stringify(flags)
153155
154-
// Post the state to the extension host
156+
// Post the state to the extension host (without flags)
155157
vscode.postMessage({
156158
command: 'saveState',
157-
state: { currentView, commitData, textContent, flags },
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,
158168
})
159169
}
160170
</script>

0 commit comments

Comments
 (0)