Skip to content

Commit 1de480b

Browse files
roomote[bot]MuriloFProomotedaniel-lxs
authored
fix: improve save button activation in prompts settings (#5780) (#8267)
Co-authored-by: MuriloFP <[email protected]> Co-authored-by: Roo Code <[email protected]> Co-authored-by: daniel-lxs <[email protected]>
1 parent 7ba8e33 commit 1de480b

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

webview-ui/src/components/modes/ModesView.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ const ModesView = ({ onDone }: ModesViewProps) => {
849849
})()}
850850
onChange={(e) => {
851851
const value =
852-
(e as unknown as CustomEvent)?.detail?.target?.value ||
852+
(e as unknown as CustomEvent)?.detail?.target?.value ??
853853
((e as any).target as HTMLTextAreaElement).value
854854
const customMode = findModeBySlug(visualMode, customModes)
855855
if (customMode) {
@@ -904,7 +904,7 @@ const ModesView = ({ onDone }: ModesViewProps) => {
904904
})()}
905905
onChange={(e) => {
906906
const value =
907-
(e as unknown as CustomEvent)?.detail?.target?.value ||
907+
(e as unknown as CustomEvent)?.detail?.target?.value ??
908908
((e as any).target as HTMLTextAreaElement).value
909909
const customMode = findModeBySlug(visualMode, customModes)
910910
if (customMode) {
@@ -959,7 +959,7 @@ const ModesView = ({ onDone }: ModesViewProps) => {
959959
})()}
960960
onChange={(e) => {
961961
const value =
962-
(e as unknown as CustomEvent)?.detail?.target?.value ||
962+
(e as unknown as CustomEvent)?.detail?.target?.value ??
963963
((e as any).target as HTMLTextAreaElement).value
964964
const customMode = findModeBySlug(visualMode, customModes)
965965
if (customMode) {
@@ -1118,14 +1118,15 @@ const ModesView = ({ onDone }: ModesViewProps) => {
11181118
})()}
11191119
onChange={(e) => {
11201120
const value =
1121-
(e as unknown as CustomEvent)?.detail?.target?.value ||
1121+
(e as unknown as CustomEvent)?.detail?.target?.value ??
11221122
((e as any).target as HTMLTextAreaElement).value
11231123
const customMode = findModeBySlug(visualMode, customModes)
11241124
if (customMode) {
11251125
// For custom modes, update the JSON file
11261126
updateCustomMode(visualMode, {
11271127
...customMode,
1128-
customInstructions: value.trim() || undefined,
1128+
// Preserve empty string; only treat null/undefined as unset
1129+
customInstructions: value ?? undefined,
11291130
source: customMode.source || "global",
11301131
})
11311132
} else {
@@ -1335,12 +1336,12 @@ const ModesView = ({ onDone }: ModesViewProps) => {
13351336
value={customInstructions || ""}
13361337
onChange={(e) => {
13371338
const value =
1338-
(e as unknown as CustomEvent)?.detail?.target?.value ||
1339+
(e as unknown as CustomEvent)?.detail?.target?.value ??
13391340
((e as any).target as HTMLTextAreaElement).value
1340-
setCustomInstructions(value || undefined)
1341+
setCustomInstructions(value ?? undefined)
13411342
vscode.postMessage({
13421343
type: "customInstructions",
1343-
text: value.trim() || undefined,
1344+
text: value ?? undefined,
13441345
})
13451346
}}
13461347
rows={4}

webview-ui/src/components/modes/__tests__/ModesView.spec.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,13 @@ describe("PromptsView", () => {
223223
const changeEvent = new Event("change", { bubbles: true })
224224
fireEvent(textarea, changeEvent)
225225

226-
// The component calls setCustomInstructions with value || undefined
227-
// Since empty string is falsy, it should be undefined
228-
expect(setCustomInstructions).toHaveBeenCalledWith(undefined)
226+
// The component calls setCustomInstructions with value ?? undefined
227+
// With nullish coalescing, empty string is preserved (not treated as nullish)
228+
expect(setCustomInstructions).toHaveBeenCalledWith("")
229+
// The postMessage call will have multiple calls, we need to check the right one
229230
expect(vscode.postMessage).toHaveBeenCalledWith({
230231
type: "customInstructions",
231-
text: undefined,
232+
text: "", // empty string is now preserved with ?? operator
232233
})
233234
})
234235

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,31 @@ const PromptsSettings = ({
6969
}, [])
7070

7171
const updateSupportPrompt = (type: SupportPromptType, value: string | undefined) => {
72+
// Don't trim during editing to preserve intentional whitespace
73+
// Use nullish coalescing to preserve empty strings
74+
const finalValue = value ?? undefined
75+
7276
if (type === "CONDENSE") {
73-
setCustomCondensingPrompt(value || supportPrompt.default.CONDENSE)
77+
setCustomCondensingPrompt(finalValue ?? supportPrompt.default.CONDENSE)
7478
vscode.postMessage({
7579
type: "updateCondensingPrompt",
76-
text: value || supportPrompt.default.CONDENSE,
80+
text: finalValue ?? supportPrompt.default.CONDENSE,
7781
})
82+
// Also update the customSupportPrompts to trigger change detection
83+
const updatedPrompts = { ...customSupportPrompts }
84+
if (finalValue === undefined) {
85+
delete updatedPrompts[type]
86+
} else {
87+
updatedPrompts[type] = finalValue
88+
}
89+
setCustomSupportPrompts(updatedPrompts)
7890
} else {
79-
const updatedPrompts = { ...customSupportPrompts, [type]: value }
91+
const updatedPrompts = { ...customSupportPrompts }
92+
if (finalValue === undefined) {
93+
delete updatedPrompts[type]
94+
} else {
95+
updatedPrompts[type] = finalValue
96+
}
8097
setCustomSupportPrompts(updatedPrompts)
8198
}
8299
}
@@ -88,6 +105,10 @@ const PromptsSettings = ({
88105
type: "updateCondensingPrompt",
89106
text: supportPrompt.default.CONDENSE,
90107
})
108+
// Also update the customSupportPrompts to trigger change detection
109+
const updatedPrompts = { ...customSupportPrompts }
110+
delete updatedPrompts[type]
111+
setCustomSupportPrompts(updatedPrompts)
91112
} else {
92113
const updatedPrompts = { ...customSupportPrompts }
93114
delete updatedPrompts[type]
@@ -97,7 +118,8 @@ const PromptsSettings = ({
97118

98119
const getSupportPromptValue = (type: SupportPromptType): string => {
99120
if (type === "CONDENSE") {
100-
return customCondensingPrompt || supportPrompt.default.CONDENSE
121+
// Preserve empty string - only fall back to default when value is nullish
122+
return customCondensingPrompt ?? supportPrompt.default.CONDENSE
101123
}
102124
return supportPrompt.get(customSupportPrompts, type)
103125
}
@@ -158,12 +180,11 @@ const PromptsSettings = ({
158180
<VSCodeTextArea
159181
resize="vertical"
160182
value={getSupportPromptValue(activeSupportOption)}
161-
onChange={(e) => {
183+
onInput={(e) => {
162184
const value =
163-
(e as unknown as CustomEvent)?.detail?.target?.value ||
185+
(e as unknown as CustomEvent)?.detail?.target?.value ??
164186
((e as any).target as HTMLTextAreaElement).value
165-
const trimmedValue = value.trim()
166-
updateSupportPrompt(activeSupportOption, trimmedValue || undefined)
187+
updateSupportPrompt(activeSupportOption, value)
167188
}}
168189
rows={6}
169190
className="w-full"

0 commit comments

Comments
 (0)