Skip to content

fix: spaces and uppercase characters in multiline input#534

Merged
43081j merged 4 commits into
bombshell-dev:mainfrom
MattStypa:multiline-fix
May 12, 2026
Merged

fix: spaces and uppercase characters in multiline input#534
43081j merged 4 commits into
bombshell-dev:mainfrom
MattStypa:multiline-fix

Conversation

@MattStypa
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes multiline prompt typing so spaces and uppercase characters are inserted correctly.

See #529 for details.

Changes

  • Use a local arrow-key action set in multi-line prompt handling.
  • Fix character insertion to preserve spaces and shifted uppercase input.
  • Add regression tests for space insertion and shift-uppercase typing.

Closes #529

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 9, 2026

🦋 Changeset detected

Latest commit: 19255e0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@clack/prompts Patch
@clack/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 9, 2026

commit: 19255e0

Comment thread packages/core/src/prompts/multi-line.ts Outdated
Comment on lines +6 to +9
const actions = ['up', 'down', 'left', 'right'];
type Action = (typeof actions)[number];
const actionSet = new Set(actions);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be added to utils/settings as arrowKeys

Comment thread packages/core/src/prompts/multi-line.ts Outdated
Comment on lines +124 to +125
const casedChar = key.shift ? char.toUpperCase() : char;
this.#insertAtCursor(casedChar ?? '');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this might break a couple of real cases:

  • paste: terminals usually send pasted text as a stream of keypresses with shift: false per char. since the base Prompt.onKeypress already lowercased char, we'd never re-uppercase here, pasted mixed case ends up all lowercase.
  • capslock without shift: some emulators send the upper-cased char with shift: false too, same deal.
    the real root cause is that Prompt.onKeypress lowercases char before emitting 'key'.

probably cleaner to just insert from key.sequence (the raw bytes, original case) and skip the shift dance entirely

wdyt @43081j ? 👀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based this on existing code here:

const casedKey = caseSensitive && keyInfo.shift ? key.toUpperCase() : key;

But I see how that use-case is different.

Let me take a closer look.

@MattStypa
Copy link
Copy Markdown
Contributor Author

@gameroman, @dreyfus92

Thank you for your feedback. The PR has been updated.

Please let me know if changing how prompt.ts emits key events is not the right solution in your opinion.

@43081j
Copy link
Copy Markdown
Collaborator

43081j commented May 9, 2026

i'm not sure about this as it touches more than it needs to.

cursor events purposely can be any Action, arrow keys don't hold any meaning here other than being some defaults. i.e. we don't need a concept of "arrow keys" or a new settings entry, as they are indeed just "actions".

i think the only changes you need are:

  1. the key handler should pass char as-is (no lowercasing)
  2. select-key refactor to account for this
  3. update select-key test since it had the wrong casing already

you have all these so i think it looks good if we drop the arrow key stuff

@gameroman
Copy link
Copy Markdown
Contributor

cursor events purposely can be any Action, arrow keys don't hold any meaning here other than being some defaults. i.e. we don't need a concept of "arrow keys" or a new settings entry, as they are indeed just "actions".

Do you mean they don't need to be in the settings file or don't need special handling?

Looking at the code, CursorAction is probably a better name for them instead of ArrowKeyAction

@43081j
Copy link
Copy Markdown
Collaborator

43081j commented May 9, 2026

im saying none of the changes around "arrow keys" are needed to fix this bug

@MattStypa
Copy link
Copy Markdown
Contributor Author

im saying none of the changes around "arrow keys" are needed to fix this bug

@43081j Im curious what your suggestion to fix the space key issue is.

At the moment, the multi-line key handler checks keys against settings.actions (which includes space) and returns early.

see here

There are a many valid ways to address this. Initially, I scoped the set of cursor keys to multi-line.ts (see here).

@43081j
Copy link
Copy Markdown
Collaborator

43081j commented May 11, 2026

i think that is a bug in the multi-line prompt.

if (key?.name && settings.actions.has(key.name as Action)) {
this.#handleCursor(key.name as Action);
return;
}

here we check that the key is an "action" key, and treat it as a cursor action if it is.

but the multi-line prompt doesn't control its cursor actions based on the actions keys. it is hard coded to use the arrow keys here:

case 'up':
this._cursor = findTextCursor(this._cursor, 0, -1, text);
return;
case 'down':
this._cursor = findTextCursor(this._cursor, 0, 1, text);
return;
case 'left':
this._cursor = findTextCursor(this._cursor, -1, 0, text);
return;
case 'right':
this._cursor = findTextCursor(this._cursor, 1, 0, text);
return;

the settings can't override that.

so its basically a bug i think - that we shouldn't be checking settings.actions. we should just have a hard coded check for if it is an arrow key or not.

so you were on the right track, but not as a change to the core settings or types. this is just a separate, one-off hard coded set of keys a user can't configure (specific to the multi-line prompt).

@MattStypa
Copy link
Copy Markdown
Contributor Author

@43081j updated

@43081j 43081j merged commit 3dcb31a into bombshell-dev:main May 12, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Can't type spaces or uppercase letters into a multiline prompt

4 participants