Skip to content

Commit 358a76b

Browse files
committed
fix: remove immediate trim in onChange to ensure proper state updates
- Move trimming logic into updateSupportPrompt function - This ensures the onChange event triggers immediately on any input - Empty strings are converted to undefined only when storing
1 parent 7eae039 commit 358a76b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,21 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom
5656
}, [])
5757

5858
const updateSupportPrompt = (type: SupportPromptType, value: string | undefined) => {
59+
// Trim the value when storing, but keep empty strings
60+
const trimmedValue = value?.trim()
61+
const finalValue = trimmedValue === "" ? undefined : trimmedValue
62+
5963
if (type === "CONDENSE") {
60-
setCustomCondensingPrompt(value || supportPrompt.default.CONDENSE)
64+
setCustomCondensingPrompt(finalValue || supportPrompt.default.CONDENSE)
6165
vscode.postMessage({
6266
type: "updateCondensingPrompt",
63-
text: value || supportPrompt.default.CONDENSE,
67+
text: finalValue || supportPrompt.default.CONDENSE,
6468
})
6569
// Also update the customSupportPrompts to trigger change detection
66-
const updatedPrompts = { ...customSupportPrompts, [type]: value }
70+
const updatedPrompts = { ...customSupportPrompts, [type]: finalValue }
6771
setCustomSupportPrompts(updatedPrompts)
6872
} else {
69-
const updatedPrompts = { ...customSupportPrompts, [type]: value }
73+
const updatedPrompts = { ...customSupportPrompts, [type]: finalValue }
7074
setCustomSupportPrompts(updatedPrompts)
7175
}
7276
}
@@ -156,8 +160,7 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom
156160
const value =
157161
(e as unknown as CustomEvent)?.detail?.target?.value ??
158162
((e as any).target as HTMLTextAreaElement).value
159-
const trimmedValue = value.trim()
160-
updateSupportPrompt(activeSupportOption, trimmedValue || undefined)
163+
updateSupportPrompt(activeSupportOption, value)
161164
}}
162165
rows={6}
163166
className="w-full"

0 commit comments

Comments
 (0)