Skip to content

Commit 1d5839e

Browse files
fix(core): submit the typed text when a picker search matches nothing
On a real terminal, typing an organization or repository that matches nothing and pressing Enter exited 3 as cancelled instead of 2 naming the value. readline clears rl.line before it emits the submitted line, so the picker read an empty string. inquirer hands the submitted line to getCurrentValue, and the picker now reads that instead. Proved on a real terminal against dev11: "no-such-org-xyz-9987" at the organization picker exits 2 with 'No organization named "no-such-org-xyz-9987" is available to you.' #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d75233b commit 1d5839e

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎src/core/search-list.test.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface Prompt {
77
pointer: number;
88
rl: { line: string };
99
filterChoices(): void;
10-
getCurrentValue(): unknown;
10+
getCurrentValue(line?: unknown): unknown;
1111
}
1212

1313
const CHOICES = [
@@ -67,10 +67,18 @@ describe('launchSearchList', () => {
6767
expect(prompt.getCurrentValue()).toBe('Other');
6868
});
6969

70-
it('submits the typed text rather than the first choice when the text matches nothing', () => {
70+
it('submits the submitted line rather than the first choice when the typed text matches nothing', () => {
7171
const prompt = typed(open({}), 'no-such-framework-9987');
72+
prompt.rl.line = '';
7273

73-
expect(prompt.getCurrentValue()).toBe('no-such-framework-9987');
74+
expect(prompt.getCurrentValue('no-such-framework-9987')).toBe('no-such-framework-9987');
75+
});
76+
77+
it('reads nothing as the value when the typed text matches nothing and no line was submitted', () => {
78+
const prompt = typed(open({}), 'no-such-framework-9987');
79+
prompt.rl.line = '';
80+
81+
expect(prompt.getCurrentValue()).toBe('');
7482
});
7583
});
7684

‎src/core/search-list.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface SearchListPrompt {
1010
pointer: number;
1111
list: SearchChoice[];
1212
filterList: SearchChoice[];
13-
getCurrentValue(): unknown;
13+
getCurrentValue(line?: unknown): unknown;
1414
}
1515

1616
export type SearchListClass = new (...params: never[]) => SearchListPrompt;
@@ -34,8 +34,8 @@ export function launchSearchList(SearchList: SearchListClass): SearchListClass {
3434
this.pointer = startingPointer(this.list, this.opt.default);
3535
}
3636

37-
getCurrentValue(): unknown {
38-
return this.filterList.length > 0 ? this.filterList[this.pointer].value : this.rl.line;
37+
getCurrentValue(line?: unknown): unknown {
38+
return this.filterList.length > 0 ? this.filterList[this.pointer].value : String(line ?? '');
3939
}
4040
};
4141
}

0 commit comments

Comments
 (0)