Skip to content

Commit c68c14d

Browse files
committed
Move empty context check to quick pick accept handler to prevent redundant validation
1 parent b63093b commit c68c14d

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

‎apps/editor/src/commands/apply-context-command/sources/json-file-source.ts‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,22 @@ export const handle_json_file_source = async (
237237
}
238238
})
239239

240-
quick_pick.onDidAccept(() => {
240+
quick_pick.onDidAccept(async () => {
241241
const item = quick_pick.selectedItems[0]
242+
243+
if (item.label === LABEL_SAVE_NEW_CONTEXT) {
244+
const checked_files = workspace_provider.get_checked_files()
245+
if (checked_files.length == 0) {
246+
active_dialog_count++
247+
await vscode.window.showWarningMessage(
248+
dictionary.warning_message.NOTHING_IN_CONTEXT_TO_SAVE
249+
)
250+
active_dialog_count--
251+
quick_pick.show()
252+
return
253+
}
254+
}
255+
242256
quick_pick.hide()
243257
resolve_once(item)
244258
})
@@ -259,6 +273,7 @@ export const handle_json_file_source = async (
259273

260274
quick_pick.dispose()
261275

276+
if (!selection) return
262277
if (selection == 'back') return 'back'
263278
if (selection == 'exit') return
264279
if (selection == 'retry') continue
@@ -400,14 +415,6 @@ export const handle_json_file_source = async (
400415

401416
if (selection.label === LABEL_SAVE_NEW_CONTEXT) {
402417
const checked_files = workspace_provider.get_checked_files()
403-
if (checked_files.length == 0) {
404-
active_dialog_count++
405-
await vscode.window.showWarningMessage(
406-
dictionary.warning_message.NOTHING_IN_CONTEXT_TO_SAVE
407-
)
408-
active_dialog_count--
409-
continue
410-
}
411418

412419
active_dialog_count++
413420
const name = await ask_for_new_context_name(true)

0 commit comments

Comments
 (0)