diff --git a/src/common/window.apis.ts b/src/common/window.apis.ts index d01ac076..d3f96ac7 100644 --- a/src/common/window.apis.ts +++ b/src/common/window.apis.ts @@ -255,8 +255,17 @@ export async function showInputBoxWithButtons( inputBox.hide(); } }), - inputBox.onDidAccept(() => { + inputBox.onDidAccept(async () => { if (!deferred.completed) { + let isValid = true; + if (options?.validateInput) { + const validation = await options.validateInput(inputBox.value); + isValid = validation === null || validation === undefined; + if (!isValid) { + inputBox.validationMessage = typeof validation === 'string' ? validation : 'Invalid input'; + return; // Do not resolve, keep the input box open + } + } deferred.resolve(inputBox.value); inputBox.hide(); }