@@ -78,6 +78,8 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
7878
7979 const [ saveStatus , setSaveStatus ] = useState < "idle" | "saving" | "saved" | "error" > ( "idle" )
8080 const [ saveError , setSaveError ] = useState < string | null > ( null )
81+ const [ isSaving , setIsSaving ] = useState ( false )
82+ const [ justSaved , setJustSaved ] = useState ( false )
8183
8284 // Default settings template
8385 const getDefaultSettings = ( ) : LocalCodeIndexSettings => ( {
@@ -158,15 +160,23 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
158160 } else if ( event . data . type === "codeIndexSettingsSaved" ) {
159161 if ( event . data . success ) {
160162 setSaveStatus ( "saved" )
161- // Don't update initial settings here - wait for the secret status response
162- // Request updated secret status after save
163- vscode . postMessage ( { type : "requestCodeIndexSecretStatus" } )
163+ setIsSaving ( false )
164+ setJustSaved ( true )
165+
166+ // Delay secret status request to allow backend to stabilize
167+ setTimeout ( ( ) => {
168+ vscode . postMessage ( { type : "requestCodeIndexSecretStatus" } )
169+ setJustSaved ( false )
170+ } , 1000 )
171+
164172 // Reset status after 3 seconds
165173 setTimeout ( ( ) => {
166174 setSaveStatus ( "idle" )
167175 } , 3000 )
168176 } else {
169177 setSaveStatus ( "error" )
178+ setIsSaving ( false )
179+ setJustSaved ( false )
170180 setSaveError ( event . data . error || t ( "settings:codeIndex.saveError" ) )
171181 // Clear error message after 5 seconds
172182 setTimeout ( ( ) => {
@@ -192,24 +202,27 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
192202 const updateWithSecrets = ( prev : LocalCodeIndexSettings ) : LocalCodeIndexSettings => {
193203 const updated = { ...prev }
194204
195- // Only update to placeholder if the field is currently empty or already a placeholder
196- // This preserves user input when they're actively editing
197- if ( ! prev . codeIndexOpenAiKey || prev . codeIndexOpenAiKey === SECRET_PLACEHOLDER ) {
198- updated . codeIndexOpenAiKey = secretStatus . hasOpenAiKey ? SECRET_PLACEHOLDER : ""
199- }
200- if ( ! prev . codeIndexQdrantApiKey || prev . codeIndexQdrantApiKey === SECRET_PLACEHOLDER ) {
201- updated . codeIndexQdrantApiKey = secretStatus . hasQdrantApiKey ? SECRET_PLACEHOLDER : ""
202- }
203- if (
204- ! prev . codebaseIndexOpenAiCompatibleApiKey ||
205- prev . codebaseIndexOpenAiCompatibleApiKey === SECRET_PLACEHOLDER
206- ) {
207- updated . codebaseIndexOpenAiCompatibleApiKey = secretStatus . hasOpenAiCompatibleApiKey
208- ? SECRET_PLACEHOLDER
209- : ""
210- }
211- if ( ! prev . codebaseIndexGeminiApiKey || prev . codebaseIndexGeminiApiKey === SECRET_PLACEHOLDER ) {
212- updated . codebaseIndexGeminiApiKey = secretStatus . hasGeminiApiKey ? SECRET_PLACEHOLDER : ""
205+ // Preserve user input during save operations
206+ if ( ! isSaving && ! justSaved ) {
207+ // Only update to placeholder if the field is currently empty or already a placeholder
208+ // This preserves user input when they're actively editing
209+ if ( ! prev . codeIndexOpenAiKey || prev . codeIndexOpenAiKey === SECRET_PLACEHOLDER ) {
210+ updated . codeIndexOpenAiKey = secretStatus . hasOpenAiKey ? SECRET_PLACEHOLDER : ""
211+ }
212+ if ( ! prev . codeIndexQdrantApiKey || prev . codeIndexQdrantApiKey === SECRET_PLACEHOLDER ) {
213+ updated . codeIndexQdrantApiKey = secretStatus . hasQdrantApiKey ? SECRET_PLACEHOLDER : ""
214+ }
215+ if (
216+ ! prev . codebaseIndexOpenAiCompatibleApiKey ||
217+ prev . codebaseIndexOpenAiCompatibleApiKey === SECRET_PLACEHOLDER
218+ ) {
219+ updated . codebaseIndexOpenAiCompatibleApiKey = secretStatus . hasOpenAiCompatibleApiKey
220+ ? SECRET_PLACEHOLDER
221+ : ""
222+ }
223+ if ( ! prev . codebaseIndexGeminiApiKey || prev . codebaseIndexGeminiApiKey === SECRET_PLACEHOLDER ) {
224+ updated . codebaseIndexGeminiApiKey = secretStatus . hasGeminiApiKey ? SECRET_PLACEHOLDER : ""
225+ }
213226 }
214227
215228 return updated
@@ -222,7 +235,7 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
222235
223236 window . addEventListener ( "message" , handleMessage )
224237 return ( ) => window . removeEventListener ( "message" , handleMessage )
225- } , [ ] )
238+ } , [ isSaving , justSaved ] )
226239
227240 // Generic comparison function that detects changes between initial and current settings
228241 const hasUnsavedChanges = useMemo ( ( ) => {
@@ -258,6 +271,8 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
258271 }
259272
260273 const handleSaveSettings = ( ) => {
274+ setIsSaving ( true )
275+ setJustSaved ( false )
261276 setSaveStatus ( "saving" )
262277 setSaveError ( null )
263278
0 commit comments