Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/multiline-initial-value.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clack/core": patch
---

Fix `multiline` prompt ignoring `initialValue`. The editor is now seeded with `initialValue` (falling back to `initialUserInput`) when the prompt opens, matching the `text` prompt.
8 changes: 7 additions & 1 deletion packages/core/src/prompts/multi-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ export default class MultiLinePrompt extends Prompt<string> {
}

constructor(opts: MultiLineOptions) {
super(opts, false);
super(
{
...opts,
initialUserInput: opts.initialUserInput ?? opts.initialValue,
},
false
);
this.#showSubmit = opts.showSubmit ?? false;

this.on('key', (char, key) => {
Expand Down
26 changes: 26 additions & 0 deletions packages/core/test/prompts/multi-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ describe('MultiLinePrompt', () => {
expect(result).to.equal('x');
});

test('seeds initialValue into the editor', () => {
const instance = new MultiLinePrompt({
input,
output,
render: () => 'foo',
initialValue: 'first line\nsecond line',
});
instance.prompt();
expect(instance.userInput).to.equal('first line\nsecond line');
expect(instance.value).to.equal('first line\nsecond line');
});

test('submits initialValue when not edited', async () => {
const instance = new MultiLinePrompt({
input,
output,
render: () => 'foo',
initialValue: 'untouched',
});
const resultPromise = instance.prompt();
input.emit('keypress', '', { name: 'return' });
input.emit('keypress', '', { name: 'return' });
const result = await resultPromise;
expect(result).to.equal('untouched');
});

describe('cursor', () => {
test('can get cursor', () => {
const instance = new MultiLinePrompt({
Expand Down
Loading