Skip to content

fix(core): draw the autocomplete text cursor at the typing position - #649

Open
kuldeepsinh19 wants to merge 1 commit into
bombshell-dev:mainfrom
kuldeepsinh19:fix/autocomplete-text-cursor
Open

kuldeepsinh19 wants to merge 1 commit into
bombshell-dev:mainfrom
kuldeepsinh19:fix/autocomplete-text-cursor

Conversation

@kuldeepsinh19

Copy link
Copy Markdown
Contributor

What does this PR do?

AutocompletePrompt has two cursors: _cursor (the caret inside the search text, tracked from readline) and cursor (the index of the focused option). userInputWithCursor checks _cursor to decide whether the caret is at the end, but then slices the text with cursor, the option index.

So as soon as the caret is not at the end of the input, the highlight is drawn in the wrong place:

  • type ap, press Left: the highlight sits on a (focused option index 0) while the caret is on p, and the next key is inserted before p;
  • arrowing down the list moves the highlight along the search text;
  • when the focused option index is past the end of the text, no cursor is drawn at all.

This affects autocomplete, autocompleteMultiselect and path, since they all render userInputWithCursor.

The fix slices with _cursor, the same value the line above already checks. Nothing else changes.

  • The new @clack/prompts test types ap, presses Left and snapshots the frames. On main (0cd3e40) the frame after Left is <inverse>a</inverse>p; with this branch it is a<inverse>p</inverse>. The test fails against a core build without the fix.
  • The two new @clack/core tests follow the existing userInputWithCursor tests in text.test.ts. Like those, they only tell the difference when colors are on (FORCE_COLOR=1), which is why the snapshot test in @clack/prompts is there too.
  • Node 22.11.0 on Windows: pnpm types, pnpm deps and pnpm exec biome check pass, and all 184 core tests pass. In @clack/prompts 607 tests pass; 34 tests in note.test.ts and path.test.ts fail on my Windows machine both on main and on this branch, so they are not related to this change.

I did not open an issue first because the change is three tokens and the test shows the bug directly. Happy to file one if you prefer.

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

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Nov 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7cfbe69

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

This PR includes changesets to release 2 packages
Name Type
@clack/core Patch
@clack/prompts 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

pkg-pr-new Bot commented Nov 29, 2026

Copy link
Copy Markdown

commit: 7cfbe69

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.

1 participant