fix: focus "Done" option after completing provider manager actions (#718)

When returning to the provider manager menu after completing an action
(add, edit, delete, set active, etc.), the cursor now lands on "Done"
instead of the first option ("Add provider"). This prevents accidental
re-entry into the same action if the user presses Enter quickly.

On initial /provider invocation, the cursor still starts on the first
option ("Add provider") as expected.

Co-authored-by: Ali Alakbarli <ali.alakbarli@users.noreply.github.com>
This commit is contained in:
emsanakhchivan
2026-04-16 17:39:13 +04:00
committed by GitHub
parent d32a2a1329
commit d6f5130c20

View File

@@ -361,6 +361,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
const [cursorOffset, setCursorOffset] = React.useState(0) const [cursorOffset, setCursorOffset] = React.useState(0)
const [statusMessage, setStatusMessage] = React.useState<string | undefined>() const [statusMessage, setStatusMessage] = React.useState<string | undefined>()
const [errorMessage, setErrorMessage] = React.useState<string | undefined>() const [errorMessage, setErrorMessage] = React.useState<string | undefined>()
const [menuFocusValue, setMenuFocusValue] = React.useState<string | undefined>()
const [hasStoredCodexOAuthCredentials, setHasStoredCodexOAuthCredentials] = const [hasStoredCodexOAuthCredentials, setHasStoredCodexOAuthCredentials] =
React.useState(false) React.useState(false)
const [storedCodexOAuthProfileId, setStoredCodexOAuthProfileId] = const [storedCodexOAuthProfileId, setStoredCodexOAuthProfileId] =
@@ -576,7 +577,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
const githubError = activateGithubProvider() const githubError = activateGithubProvider()
if (githubError) { if (githubError) {
setErrorMessage(`Could not activate GitHub provider: ${githubError}`) setErrorMessage(`Could not activate GitHub provider: ${githubError}`)
setScreen('menu') returnToMenu()
return return
} }
@@ -586,14 +587,14 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
mainLoopModel: GITHUB_PROVIDER_DEFAULT_MODEL, mainLoopModel: GITHUB_PROVIDER_DEFAULT_MODEL,
})) }))
setStatusMessage(`Active provider: ${GITHUB_PROVIDER_LABEL}`) setStatusMessage(`Active provider: ${GITHUB_PROVIDER_LABEL}`)
setScreen('menu') returnToMenu()
return return
} }
const active = setActiveProviderProfile(profileId) const active = setActiveProviderProfile(profileId)
if (!active) { if (!active) {
setErrorMessage('Could not change active provider.') setErrorMessage('Could not change active provider.')
setScreen('menu') returnToMenu()
return return
} }
@@ -635,16 +636,21 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
? `Active provider: ${active.name}. Warning: could not clear startup provider override (${settingsOverrideError}).` ? `Active provider: ${active.name}. Warning: could not clear startup provider override (${settingsOverrideError}).`
: `Active provider: ${active.name}`, : `Active provider: ${active.name}`,
) )
setScreen('menu') returnToMenu()
} catch (error) { } catch (error) {
refreshProfiles() refreshProfiles()
setStatusMessage(undefined) setStatusMessage(undefined)
const detail = error instanceof Error ? error.message : String(error) const detail = error instanceof Error ? error.message : String(error)
setErrorMessage(`Could not finish activating ${providerLabel}: ${detail}`) setErrorMessage(`Could not finish activating ${providerLabel}: ${detail}`)
setScreen('menu') returnToMenu()
} }
} }
function returnToMenu(): void {
setMenuFocusValue('done')
setScreen('menu')
}
function closeWithCancelled(message: string): void { function closeWithCancelled(message: string): void {
onDone({ action: 'cancelled', message }) onDone({ action: 'cancelled', message })
} }
@@ -822,7 +828,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
setEditingProfileId(null) setEditingProfileId(null)
setFormStepIndex(0) setFormStepIndex(0)
setErrorMessage(undefined) setErrorMessage(undefined)
setScreen('menu') returnToMenu()
} }
function renderOllamaSelection(): React.ReactNode { function renderOllamaSelection(): React.ReactNode {
@@ -945,7 +951,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
return return
} }
setScreen('menu') returnToMenu()
} }
useKeybinding('confirm:no', handleBackFromForm, { useKeybinding('confirm:no', handleBackFromForm, {
@@ -1078,7 +1084,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
closeWithCancelled('Provider setup skipped') closeWithCancelled('Provider setup skipped')
return return
} }
setScreen('menu') returnToMenu()
}} }}
visibleOptionCount={Math.min(13, options.length)} visibleOptionCount={Math.min(13, options.length)}
/> />
@@ -1278,6 +1284,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
} }
}} }}
onCancel={() => closeWithCancelled('Provider manager closed')} onCancel={() => closeWithCancelled('Provider manager closed')}
defaultFocusValue={menuFocusValue}
visibleOptionCount={options.length} visibleOptionCount={options.length}
/> />
</Box> </Box>
@@ -1325,8 +1332,8 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
description: 'Return to provider manager', description: 'Return to provider manager',
}, },
]} ]}
onChange={() => setScreen('menu')} onChange={() => returnToMenu()}
onCancel={() => setScreen('menu')} onCancel={() => returnToMenu()}
visibleOptionCount={1} visibleOptionCount={1}
/> />
</Box> </Box>
@@ -1341,7 +1348,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
<Select <Select
options={selectOptions} options={selectOptions}
onChange={onSelect} onChange={onSelect}
onCancel={() => setScreen('menu')} onCancel={() => returnToMenu()}
visibleOptionCount={Math.min(10, Math.max(2, selectOptions.length))} visibleOptionCount={Math.min(10, Math.max(2, selectOptions.length))}
/> />
</Box> </Box>
@@ -1382,7 +1389,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
setErrorMessage( setErrorMessage(
'Codex OAuth login finished, but the provider profile could not be saved.', 'Codex OAuth login finished, but the provider profile could not be saved.',
) )
setScreen('menu') returnToMenu()
return return
} }
@@ -1394,7 +1401,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
setErrorMessage( setErrorMessage(
'Codex OAuth login finished, but the provider could not be set as the startup provider.', 'Codex OAuth login finished, but the provider could not be set as the startup provider.',
) )
setScreen('menu') returnToMenu()
return return
} }
@@ -1428,7 +1435,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
setStatusMessage(message) setStatusMessage(message)
setErrorMessage(undefined) setErrorMessage(undefined)
setScreen('menu') returnToMenu()
}} }}
/> />
) )
@@ -1468,7 +1475,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
refreshProfiles() refreshProfiles()
setStatusMessage('GitHub provider deleted') setStatusMessage('GitHub provider deleted')
} }
setScreen('menu') returnToMenu()
return return
} }
@@ -1503,7 +1510,7 @@ export function ProviderManager({ mode, onDone }: Props): React.ReactNode {
: 'Provider deleted', : 'Provider deleted',
) )
} }
setScreen('menu') returnToMenu()
}, },
{ includeGithub: true }, { includeGithub: true },
) )