diff --git a/src/lib/prompts/prompt-types.ts b/src/lib/prompts/prompt-types.ts index cfefccb..e8bb78e 100644 --- a/src/lib/prompts/prompt-types.ts +++ b/src/lib/prompts/prompt-types.ts @@ -4,7 +4,7 @@ */ import * as vscode from 'vscode'; import * as configuration from '../configuration'; -import createSimpleQuickPick from './quick-pick'; +import createSimpleQuickPick, { confirmButton } from './quick-pick'; import localize from '../localize'; import * as output from '../output'; @@ -93,9 +93,7 @@ function createInputBox({ if (value) { input.value = value; } - if (buttons) { - input.buttons = buttons; - } + input.buttons = [...(buttons ?? []), confirmButton]; input.onDidChangeValue(function () { try { input.validationMessage = validate(input.value); @@ -118,6 +116,20 @@ function createInputBox({ } }); input.onDidTriggerButton(function (e) { + if (e === confirmButton) { + try { + input.validationMessage = validate(input.value); + if (input.validationMessage) { + return; + } + resolve({ value: input.value, activeItems: [] }); + input.dispose(); + } catch (e) { + output.error(`step.${input.step}`, e); + reject(e); + } + } + if (e === vscode.QuickInputButtons.Back) { reject({ button: e, diff --git a/src/lib/prompts/quick-pick.ts b/src/lib/prompts/quick-pick.ts index 08ab5bd..4f0f740 100644 --- a/src/lib/prompts/quick-pick.ts +++ b/src/lib/prompts/quick-pick.ts @@ -4,6 +4,11 @@ */ import * as vscode from 'vscode'; +export const confirmButton: vscode.QuickInputButton = { + iconPath: new vscode.ThemeIcon('arrow-right'), + tooltip: 'confirm', +}; + export default function createQuickPick({ placeholder, items = [], @@ -29,6 +34,7 @@ export default function createQuickPick({ picker.totalSteps = totalSteps; picker.buttons = buttons; picker.show(); + picker.buttons = [...buttons, confirmButton]; picker.onDidAccept(function () { if (picker.activeItems.length) { resolve({ @@ -39,6 +45,21 @@ export default function createQuickPick({ } }); picker.onDidTriggerButton(function (e) { + if (e === confirmButton) { + if (picker.activeItems.length) { + resolve({ + value: picker.value, + activeItems: picker.activeItems as T[], + }); + } else { + resolve({ + value: picker.value, + activeItems: [picker.items[0]] as T[], + }); + } + picker.dispose(); + } + if (e === vscode.QuickInputButtons.Back) { reject({ button: e,