Skip to content

Commit 4ff70e7

Browse files
committed
Refactor config handlers to ensure prompt field regains focus after quick pick dismissal
1 parent 25d81bc commit 4ff70e7

3 files changed

Lines changed: 29 additions & 21 deletions

File tree

‎apps/editor/src/views/panel/backend/message-handlers/handle-code-completion.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const get_code_completion_config = async (
3131
api_providers_manager: ModelProvidersManager,
3232
show_quick_pick: boolean = false,
3333
context: vscode.ExtensionContext,
34-
config_id?: string,
35-
panel_provider?: PanelProvider
34+
panel_provider: PanelProvider,
35+
config_id?: string
3636
): Promise<{ provider: any; config: any } | undefined> => {
3737
const code_completions_configs =
3838
await api_providers_manager.get_code_completions_tool_configs()
@@ -234,6 +234,9 @@ const get_code_completion_config = async (
234234

235235
quick_pick.onDidHide(() => {
236236
quick_pick.dispose()
237+
if (panel_provider) {
238+
panel_provider.send_message({ command: 'FOCUS_PROMPT_FIELD' })
239+
}
237240
resolve(undefined)
238241
})
239242

@@ -276,16 +279,14 @@ export const handle_code_completion = async (
276279
api_providers_manager,
277280
message.use_quick_pick,
278281
panel_provider.context,
279-
message.config_id,
280-
panel_provider
282+
panel_provider,
283+
message.config_id
281284
)
282285

283286
if (!config_result) {
284287
return
285288
}
286289

287-
panel_provider.send_message({ command: 'FOCUS_PROMPT_FIELD' })
288-
289290
const { provider, config: code_completions_config } = config_result
290291

291292
if (!code_completions_config.provider_name) {

‎apps/editor/src/views/panel/backend/message-handlers/handle-edit-context.ts‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,20 @@ import {
3838
EDIT_FORMAT_INSTRUCTIONS_DIFF
3939
} from '@/constants/edit-format-instructions'
4040

41-
const get_edit_context_config = async (
42-
api_providers_manager: ModelProvidersManager,
43-
show_quick_pick: boolean = false,
44-
context: vscode.ExtensionContext,
45-
panel_provider: PanelProvider,
41+
const get_edit_context_config = async (params: {
42+
api_providers_manager: ModelProvidersManager
43+
show_quick_pick?: boolean
44+
context: vscode.ExtensionContext
45+
panel_provider: PanelProvider
4646
config_id?: string
47-
): Promise<{ provider: Provider; config: ToolConfig } | undefined> => {
47+
}): Promise<{ provider: Provider; config: ToolConfig } | undefined> => {
48+
const {
49+
api_providers_manager,
50+
show_quick_pick,
51+
context,
52+
panel_provider,
53+
config_id
54+
} = params
4855
const edit_context_configs =
4956
await api_providers_manager.get_edit_context_tool_configs()
5057

@@ -245,6 +252,9 @@ const get_edit_context_config = async (
245252

246253
quick_pick.onDidHide(() => {
247254
quick_pick.dispose()
255+
if (panel_provider) {
256+
panel_provider.send_message({ command: 'FOCUS_PROMPT_FIELD' })
257+
}
248258
if (!accepted) {
249259
resolve(undefined)
250260
}
@@ -370,22 +380,18 @@ export const handle_edit_context = async (
370380

371381
// eslint-disable-next-line no-constant-condition
372382
while (true) {
373-
const config_result = await get_edit_context_config(
383+
const config_result = await get_edit_context_config({
374384
api_providers_manager,
375-
should_show_quick_pick,
376-
panel_provider.context,
385+
show_quick_pick: should_show_quick_pick,
386+
context: panel_provider.context,
377387
panel_provider,
378-
current_config_id
379-
)
388+
config_id: current_config_id
389+
})
380390

381391
if (!config_result) {
382392
return
383393
}
384394

385-
if (!message.config_id) {
386-
panel_provider.send_message({ command: 'FOCUS_PROMPT_FIELD' })
387-
}
388-
389395
const { provider, config: edit_context_config } = config_result
390396

391397
let endpoint_url = ''

‎apps/editor/src/views/panel/backend/message-handlers/handle-send-to-browser.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ async function show_preset_quick_pick(params: {
517517
quick_pick.onDidHide(() => {
518518
disposables.forEach((d) => d.dispose())
519519
quick_pick.dispose()
520+
panel_provider.send_message({ command: 'FOCUS_PROMPT_FIELD' })
520521
do_resolve(null)
521522
})
522523

0 commit comments

Comments
 (0)