in ui/src/userInput/showInputBox.ts [15:64]
export async function showInputBox(context: IInternalActionContext, options: types.AzExtInputBoxOptions): Promise<string> {
const disposables: Disposable[] = [];
try {
const inputBox: InputBox = createInputBox(context, options);
disposables.push(inputBox);
let latestValidation: Promise<string | undefined | null> = options.validateInput ? Promise.resolve(options.validateInput(inputBox.value)) : Promise.resolve('');
return await new Promise<string>((resolve, reject): void => {
disposables.push(
inputBox.onDidChangeValue(async text => {
if (options.validateInput) {
const validation: Promise<string | undefined | null> = Promise.resolve(options.validateInput(text));
latestValidation = validation;
const message: string | undefined | null = await validation;
if (validation === latestValidation) {
inputBox.validationMessage = message || '';
}
}
}),
inputBox.onDidAccept(async () => {
// Run final validation and resolve if value passes
inputBox.enabled = false;
inputBox.busy = true;
const message: string | undefined | null = await latestValidation;
if (!message) {
resolve(inputBox.value);
} else {
inputBox.validationMessage = message;
}
inputBox.enabled = true;
inputBox.busy = false;
}),
inputBox.onDidTriggerButton(async btn => {
if (btn === QuickInputButtons.Back) {
reject(new GoBackError());
} else if (btn === AzExtQuickInputButtons.LearnMore) {
await openUrl(nonNullProp(options, 'learnMoreLink'));
context.telemetry.properties.learnMoreStep = context.telemetry.properties.lastStep;
}
}),
inputBox.onDidHide(() => {
reject(new UserCancelledError());
})
);
inputBox.show();
});
} finally {
disposables.forEach(d => { d.dispose(); });
}
}