Skip to content

Commit d68bd06

Browse files
committed
feat(prompter): show noItemsFoundItem with filterBoxInputSettings
Problem: If filterBoxInputSettings is set, noItemsFoundItem is not shown, even if there are no items in the quickpick. Solution: Pass all `options` to FilterBoxQuickPickPrompter.
1 parent cfc6fa7 commit d68bd06

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/shared/ui/pickerPrompter.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function createQuickPick<T>(
137137

138138
const prompter =
139139
mergedOptions.filterBoxInputSettings !== undefined
140-
? new FilterBoxQuickPickPrompter<T>(picker, mergedOptions.filterBoxInputSettings)
140+
? new FilterBoxQuickPickPrompter<T>(picker, mergedOptions)
141141
: new QuickPickPrompter<T>(picker, mergedOptions)
142142

143143
prompter.loadItems(items)
@@ -578,12 +578,12 @@ export class FilterBoxQuickPickPrompter<T> extends QuickPickPrompter<T> {
578578
}
579579
}
580580

581-
constructor(quickPick: DataQuickPick<T>, private readonly settings: FilterBoxInputSettings<T>) {
581+
constructor(quickPick: DataQuickPick<T>, protected override options: ExtendedQuickPickOptions<T>) {
582582
super(quickPick)
583583

584584
this.transform(selection => {
585585
if ((selection as T | typeof customUserInput) === customUserInput) {
586-
return settings.transform(quickPick.value) ?? selection
586+
return options?.filterBoxInputSettings?.transform(quickPick.value) ?? selection
587587
}
588588
return selection
589589
})
@@ -600,10 +600,13 @@ export class FilterBoxQuickPickPrompter<T> extends QuickPickPrompter<T> {
600600

601601
private addFilterBoxInput(): void {
602602
const picker = this.quickPick as DataQuickPick<T | symbol>
603-
const validator = (input: string) =>
604-
this.settings.validator !== undefined ? this.settings.validator(input) : undefined
603+
const settings = this.options?.filterBoxInputSettings
604+
if (!settings) {
605+
throw Error()
606+
}
607+
const validator = (input: string) => (settings.validator !== undefined ? settings.validator(input) : undefined)
605608
const items = picker.items.filter(item => item.data !== customUserInput)
606-
const { label } = this.settings
609+
const { label } = settings
607610

608611
function update(value: string = '') {
609612
if (value !== '') {

src/test/shared/ui/pickerPrompter.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ describe('FilterBoxQuickPickPrompter', function () {
296296
transform: (resp: string) => Number.parseInt(resp),
297297
validator: (resp: string) => (Number.isNaN(Number.parseInt(resp)) ? 'NaN' : undefined),
298298
}
299+
const options = {
300+
filterBoxInputSettings: filterBoxInputSettings,
301+
}
299302

300303
let picker: TestQuickPick<DataQuickPickItem<number>>
301304
let testPrompter: FilterBoxQuickPickPrompter<number>
@@ -306,7 +309,7 @@ describe('FilterBoxQuickPickPrompter', function () {
306309

307310
beforeEach(function () {
308311
picker = getTestWindow().createQuickPick() as typeof picker
309-
testPrompter = new FilterBoxQuickPickPrompter(picker, filterBoxInputSettings)
312+
testPrompter = new FilterBoxQuickPickPrompter(picker, options)
310313
})
311314

312315
it('adds a new item based off the filter box', async function () {

0 commit comments

Comments
 (0)