Skip to content

Commit e42b6fa

Browse files
committed
fix: restore "Preview System Prompt" button in Prompts settings tab
- Added system prompt preview functionality to PromptsSettings component - Added dialog for displaying the system prompt content - Added message handlers for systemPrompt events - Added translation for preview description - Fixes #7328
1 parent b1f2d39 commit e42b6fa

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

webview-ui/src/components/settings/PromptsSettings.tsx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const PromptsSettings = ({
4343
setCustomCondensingPrompt,
4444
includeTaskHistoryInEnhance: contextIncludeTaskHistoryInEnhance,
4545
setIncludeTaskHistoryInEnhance: contextSetIncludeTaskHistoryInEnhance,
46+
mode,
4647
} = useExtensionState()
4748

4849
// Use props if provided, otherwise fall back to context
@@ -52,6 +53,9 @@ const PromptsSettings = ({
5253
const [testPrompt, setTestPrompt] = useState("")
5354
const [isEnhancing, setIsEnhancing] = useState(false)
5455
const [activeSupportOption, setActiveSupportOption] = useState<SupportPromptType>("ENHANCE")
56+
const [isDialogOpen, setIsDialogOpen] = useState(false)
57+
const [selectedPromptContent, setSelectedPromptContent] = useState("")
58+
const [selectedPromptTitle, setSelectedPromptTitle] = useState("")
5559

5660
useEffect(() => {
5761
const handler = (event: MessageEvent) => {
@@ -61,6 +65,12 @@ const PromptsSettings = ({
6165
setTestPrompt(message.text)
6266
}
6367
setIsEnhancing(false)
68+
} else if (message.type === "systemPrompt") {
69+
if (message.text) {
70+
setSelectedPromptContent(message.text)
71+
setSelectedPromptTitle(`System Prompt (${message.mode} mode)`)
72+
setIsDialogOpen(true)
73+
}
6474
}
6575
}
6676

@@ -122,6 +132,43 @@ const PromptsSettings = ({
122132
</SectionHeader>
123133

124134
<Section>
135+
{/* System Prompt Preview Section */}
136+
<div className="mb-4">
137+
<div className="flex gap-2">
138+
<Button
139+
variant="default"
140+
onClick={() => {
141+
vscode.postMessage({
142+
type: "getSystemPrompt",
143+
mode: mode,
144+
})
145+
}}
146+
data-testid="preview-prompt-button">
147+
{t("prompts:systemPrompt.preview")}
148+
</Button>
149+
<StandardTooltip content={t("prompts:systemPrompt.copy")}>
150+
<Button
151+
variant="ghost"
152+
size="icon"
153+
onClick={() => {
154+
vscode.postMessage({
155+
type: "copySystemPrompt",
156+
mode: mode,
157+
})
158+
}}
159+
data-testid="copy-prompt-button">
160+
<span className="codicon codicon-copy"></span>
161+
</Button>
162+
</StandardTooltip>
163+
</div>
164+
<div className="text-sm text-vscode-descriptionForeground mt-1">
165+
{t("prompts:systemPrompt.previewDescription")}
166+
</div>
167+
</div>
168+
169+
<div className="border-t border-vscode-input-border my-4"></div>
170+
171+
{/* Support Prompts Section */}
125172
<div>
126173
<Select
127174
value={activeSupportOption}
@@ -281,6 +328,34 @@ const PromptsSettings = ({
281328
)}
282329
</div>
283330
</Section>
331+
332+
{/* System Prompt Preview Dialog */}
333+
{isDialogOpen && (
334+
<div className="fixed inset-0 flex justify-end bg-black/50 z-[1000]">
335+
<div className="w-[calc(100vw-100px)] h-full bg-vscode-editor-background shadow-md flex flex-col relative">
336+
<div className="flex-1 p-5 overflow-y-auto min-h-0">
337+
<Button
338+
variant="ghost"
339+
size="icon"
340+
onClick={() => setIsDialogOpen(false)}
341+
className="absolute top-5 right-5">
342+
<span className="codicon codicon-close"></span>
343+
</Button>
344+
<h2 className="mb-4">
345+
{selectedPromptTitle || t("prompts:systemPrompt.title", { modeName: mode })}
346+
</h2>
347+
<pre className="p-2 whitespace-pre-wrap break-words font-mono text-vscode-editor-font-size text-vscode-editor-foreground bg-vscode-editor-background border border-vscode-editor-lineHighlightBorder rounded overflow-y-auto">
348+
{selectedPromptContent}
349+
</pre>
350+
</div>
351+
<div className="flex justify-end p-3 px-5 border-t border-vscode-editor-lineHighlightBorder bg-vscode-editor-background">
352+
<Button variant="secondary" onClick={() => setIsDialogOpen(false)}>
353+
{t("prompts:createModeDialog.close")}
354+
</Button>
355+
</div>
356+
</div>
357+
</div>
358+
)}
284359
</div>
285360
)
286361
}

webview-ui/src/i18n/locales/en/prompts.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@
8181
"systemPrompt": {
8282
"preview": "Preview System Prompt",
8383
"copy": "Copy system prompt to clipboard",
84-
"title": "System Prompt ({{modeName}} mode)"
84+
"title": "System Prompt ({{modeName}} mode)",
85+
"previewDescription": "View the complete system prompt that will be sent to the AI model for the current mode"
8586
},
8687
"supportPrompts": {
8788
"title": "Support Prompts",

0 commit comments

Comments
 (0)