From 38f597d7e9ffac4242ecba5d8830aefbdc248c51 Mon Sep 17 00:00:00 2001 From: Yarchik Date: Tue, 16 Jun 2026 21:57:05 +0100 Subject: [PATCH] fix(core): seed multiline prompt with initialValue The multiline prompt accepted `initialValue` but never seeded the editor with it, unlike the text prompt, so passing it had no effect. Forward `initialValue` (falling back to `initialUserInput`) to the base Prompt so the value is present when the prompt opens. Closes #566 --- .changeset/multiline-initial-value.md | 5 ++++ packages/core/src/prompts/multi-line.ts | 8 +++++- packages/core/test/prompts/multi-line.test.ts | 26 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .changeset/multiline-initial-value.md diff --git a/.changeset/multiline-initial-value.md b/.changeset/multiline-initial-value.md new file mode 100644 index 00000000..f4fa3b0f --- /dev/null +++ b/.changeset/multiline-initial-value.md @@ -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. diff --git a/packages/core/src/prompts/multi-line.ts b/packages/core/src/prompts/multi-line.ts index dcec90af..9f176900 100644 --- a/packages/core/src/prompts/multi-line.ts +++ b/packages/core/src/prompts/multi-line.ts @@ -87,7 +87,13 @@ export default class MultiLinePrompt extends Prompt { } constructor(opts: MultiLineOptions) { - super(opts, false); + super( + { + ...opts, + initialUserInput: opts.initialUserInput ?? opts.initialValue, + }, + false + ); this.#showSubmit = opts.showSubmit ?? false; this.on('key', (char, key) => { diff --git a/packages/core/test/prompts/multi-line.test.ts b/packages/core/test/prompts/multi-line.test.ts index 2b92f804..ac1556a4 100644 --- a/packages/core/test/prompts/multi-line.test.ts +++ b/packages/core/test/prompts/multi-line.test.ts @@ -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({