in src/shared/multiStepInputFlowController.ts [98:169]
public async showInputBox<P extends InputBoxParameters>({
title,
step,
totalSteps,
value,
prompt,
validate,
buttons,
ignoreFocusOut,
shouldResume,
}: P) {
const disposables: Disposable[] = []
try {
return await new Promise<string | (P extends { buttons: (infer I)[] } ? I : never)>((resolve, reject) => {
const input = window.createInputBox()
input.title = title
input.step = step
input.totalSteps = totalSteps
input.value = value || ''
input.prompt = prompt
input.buttons = [...(this.steps.length > 1 ? [QuickInputButtons.Back] : []), ...(buttons || [])]
input.ignoreFocusOut = ignoreFocusOut ? ignoreFocusOut : false
let validating = validate('')
disposables.push(
input.onDidTriggerButton(async item => {
if (item === QuickInputButtons.Back) {
reject(InputFlowAction.back)
} else if (typeof (item as any).onClick === 'function') {
;(item as any).onClick()
reject(InputFlowAction.resume)
} else {
resolve(item as any)
}
}),
input.onDidAccept(async () => {
input.enabled = false
input.busy = true
const validation = await validate(input.value)
if (!validation) {
resolve(input.value)
} else {
input.validationMessage = validation
}
input.enabled = true
input.busy = false
}),
input.onDidChangeValue(async text => {
const current = validate(text)
validating = current
const validationMessage = await current
if (current === validating) {
input.validationMessage = validationMessage
}
}),
input.onDidHide(() => {
;(async () => {
reject(
shouldResume && (await shouldResume()) ? InputFlowAction.resume : InputFlowAction.cancel
)
})().catch(reject)
})
)
if (this.current) {
this.current.dispose()
}
this.current = input
this.current.show()
})
} finally {
disposables.forEach(d => d.dispose() as void)
}
}