From f913f9c56f1185df511258464124c817f94cfa61 Mon Sep 17 00:00:00 2001 From: MuriloFP Date: Mon, 21 Jul 2025 14:01:49 -0300 Subject: [PATCH 1/3] fix: resolve save button activation in prompts settings (#5780) - Replace logical OR (||) with nullish coalescing (??) in onChange handlers - Fixes issue where empty strings were treated as falsy, preventing proper event handling - Applied fix to PromptsSettings.tsx and 5 similar instances in ModesView.tsx - Ensures Save button activates immediately when editing prompt text --- webview-ui/src/components/modes/ModesView.tsx | 10 +++++----- webview-ui/src/components/settings/PromptsSettings.tsx | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/webview-ui/src/components/modes/ModesView.tsx b/webview-ui/src/components/modes/ModesView.tsx index 170d03b0e4..16cef65e1f 100644 --- a/webview-ui/src/components/modes/ModesView.tsx +++ b/webview-ui/src/components/modes/ModesView.tsx @@ -833,7 +833,7 @@ const ModesView = ({ onDone }: ModesViewProps) => { })()} onChange={(e) => { const value = - (e as unknown as CustomEvent)?.detail?.target?.value || + (e as unknown as CustomEvent)?.detail?.target?.value ?? ((e as any).target as HTMLTextAreaElement).value const customMode = findModeBySlug(visualMode, customModes) if (customMode) { @@ -888,7 +888,7 @@ const ModesView = ({ onDone }: ModesViewProps) => { })()} onChange={(e) => { const value = - (e as unknown as CustomEvent)?.detail?.target?.value || + (e as unknown as CustomEvent)?.detail?.target?.value ?? ((e as any).target as HTMLTextAreaElement).value const customMode = findModeBySlug(visualMode, customModes) if (customMode) { @@ -943,7 +943,7 @@ const ModesView = ({ onDone }: ModesViewProps) => { })()} onChange={(e) => { const value = - (e as unknown as CustomEvent)?.detail?.target?.value || + (e as unknown as CustomEvent)?.detail?.target?.value ?? ((e as any).target as HTMLTextAreaElement).value const customMode = findModeBySlug(visualMode, customModes) if (customMode) { @@ -1102,7 +1102,7 @@ const ModesView = ({ onDone }: ModesViewProps) => { })()} onChange={(e) => { const value = - (e as unknown as CustomEvent)?.detail?.target?.value || + (e as unknown as CustomEvent)?.detail?.target?.value ?? ((e as any).target as HTMLTextAreaElement).value const customMode = findModeBySlug(visualMode, customModes) if (customMode) { @@ -1307,7 +1307,7 @@ const ModesView = ({ onDone }: ModesViewProps) => { value={customInstructions || ""} onChange={(e) => { const value = - (e as unknown as CustomEvent)?.detail?.target?.value || + (e as unknown as CustomEvent)?.detail?.target?.value ?? ((e as any).target as HTMLTextAreaElement).value setCustomInstructions(value || undefined) vscode.postMessage({ diff --git a/webview-ui/src/components/settings/PromptsSettings.tsx b/webview-ui/src/components/settings/PromptsSettings.tsx index a71132d62b..3b2b5b2dfb 100644 --- a/webview-ui/src/components/settings/PromptsSettings.tsx +++ b/webview-ui/src/components/settings/PromptsSettings.tsx @@ -147,7 +147,7 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom value={getSupportPromptValue(activeSupportOption)} onChange={(e) => { const value = - (e as unknown as CustomEvent)?.detail?.target?.value || + (e as unknown as CustomEvent)?.detail?.target?.value ?? ((e as any).target as HTMLTextAreaElement).value const trimmedValue = value.trim() updateSupportPrompt(activeSupportOption, trimmedValue || undefined) From 7eae039367d4950a6dac793ceb7b1d9fc60c4d46 Mon Sep 17 00:00:00 2001 From: MuriloFP Date: Mon, 21 Jul 2025 14:14:37 -0300 Subject: [PATCH 2/3] fix: ensure change detection triggers for all prompt types - Update CONDENSE prompt handling to also call setCustomSupportPrompts - This ensures the parent SettingsView component detects changes - Fixes issue where Save button remained disabled when editing prompts --- webview-ui/src/components/settings/PromptsSettings.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/webview-ui/src/components/settings/PromptsSettings.tsx b/webview-ui/src/components/settings/PromptsSettings.tsx index 3b2b5b2dfb..5dd4e561ff 100644 --- a/webview-ui/src/components/settings/PromptsSettings.tsx +++ b/webview-ui/src/components/settings/PromptsSettings.tsx @@ -62,6 +62,9 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom type: "updateCondensingPrompt", text: value || supportPrompt.default.CONDENSE, }) + // Also update the customSupportPrompts to trigger change detection + const updatedPrompts = { ...customSupportPrompts, [type]: value } + setCustomSupportPrompts(updatedPrompts) } else { const updatedPrompts = { ...customSupportPrompts, [type]: value } setCustomSupportPrompts(updatedPrompts) @@ -75,6 +78,10 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom type: "updateCondensingPrompt", text: supportPrompt.default.CONDENSE, }) + // Also update the customSupportPrompts to trigger change detection + const updatedPrompts = { ...customSupportPrompts } + delete updatedPrompts[type] + setCustomSupportPrompts(updatedPrompts) } else { const updatedPrompts = { ...customSupportPrompts } delete updatedPrompts[type] From 358a76be6c7bca705ba8c341a2faff3560a7ae44 Mon Sep 17 00:00:00 2001 From: MuriloFP Date: Mon, 21 Jul 2025 14:20:44 -0300 Subject: [PATCH 3/3] 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 --- .../src/components/settings/PromptsSettings.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/webview-ui/src/components/settings/PromptsSettings.tsx b/webview-ui/src/components/settings/PromptsSettings.tsx index 5dd4e561ff..c4b9e632d5 100644 --- a/webview-ui/src/components/settings/PromptsSettings.tsx +++ b/webview-ui/src/components/settings/PromptsSettings.tsx @@ -56,17 +56,21 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom }, []) const updateSupportPrompt = (type: SupportPromptType, value: string | undefined) => { + // Trim the value when storing, but keep empty strings + const trimmedValue = value?.trim() + const finalValue = trimmedValue === "" ? undefined : trimmedValue + if (type === "CONDENSE") { - setCustomCondensingPrompt(value || supportPrompt.default.CONDENSE) + setCustomCondensingPrompt(finalValue || supportPrompt.default.CONDENSE) vscode.postMessage({ type: "updateCondensingPrompt", - text: value || supportPrompt.default.CONDENSE, + text: finalValue || supportPrompt.default.CONDENSE, }) // Also update the customSupportPrompts to trigger change detection - const updatedPrompts = { ...customSupportPrompts, [type]: value } + const updatedPrompts = { ...customSupportPrompts, [type]: finalValue } setCustomSupportPrompts(updatedPrompts) } else { - const updatedPrompts = { ...customSupportPrompts, [type]: value } + const updatedPrompts = { ...customSupportPrompts, [type]: finalValue } setCustomSupportPrompts(updatedPrompts) } } @@ -156,8 +160,7 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom const value = (e as unknown as CustomEvent)?.detail?.target?.value ?? ((e as any).target as HTMLTextAreaElement).value - const trimmedValue = value.trim() - updateSupportPrompt(activeSupportOption, trimmedValue || undefined) + updateSupportPrompt(activeSupportOption, value) }} rows={6} className="w-full"