Skip to content

feat(tui): use measureElement for PickerMenu pagination#252

Merged
kelsonpw merged 1 commit intomainfrom
feat/tui-pickermenu-measureelement
Apr 26, 2026
Merged

feat(tui): use measureElement for PickerMenu pagination#252
kelsonpw merged 1 commit intomainfrom
feat/tui-pickermenu-measureelement

Conversation

@kelsonpw
Copy link
Copy Markdown
Collaborator

@kelsonpw kelsonpw commented Apr 25, 2026

Summary

Audit task #13 follow-up. Replaces PickerMenu's hardcoded PICKER_CHROME_ROWS = 16 heuristic with Ink's measureElement(), so pagination math reflects the actually-rendered header height instead of a fixed guess.

Why

On narrow or resized terminals, PromptLabel can wrap to multiple rows. The old heuristic always assumed 16 chrome rows, which caused off-by-one cropping — the focused option could scroll off-screen because we over-counted the available area.

The new path measures the picker's header <Box> after layout and re-derives visibleCount on each render. The hardcoded constant is retained as a first-frame fallback for the initial paint before measureElement has a layout to read.

The pagination math is extracted into a pure computeVisibleCount(termRows, measuredHeader, totalOptionRows) helper and unit tested.

Non-goals

Files NOT touched

To keep this PR mergeable alongside other in-flight work:

  • No changes under src/ui/tui/screens/, src/ui/tui/components/, src/ui/tui/hooks/, src/ui/tui/store.ts, src/ui/tui/router.ts
  • No changes to bin.ts, src/commands/*
  • No drive-by reformatting; the diff is PickerMenu.tsx plus a new co-located test

Test plan

  • pnpm tsc --noEmit — clean
  • pnpm test — 1245 passing (8 new computeVisibleCount tests)
  • pnpm lint — clean
  • pnpm build + smoke test (node ./dist/bin.js --help) — passes
  • Manual: resize terminal narrow enough that the prompt message wraps; confirm focused option no longer scrolls off-screen
  • Manual: /region slash command picker on a tall terminal still shows full list without scroll indicators when it fits

🤖 Generated with Claude Code


Note

Low Risk
Low risk: scoped to TUI picker pagination math and layout measurement, with a conservative first-frame fallback and added unit coverage. Main risk is minor UI regressions (off-by-one scrolling) on unusual terminal sizes/wrapping behavior.

Overview
PickerMenu pagination now measures real layout height instead of relying on a fixed chrome-row constant. PickerMenu wraps the header in a ref’d Box and uses Ink’s measureElement to derive how many option rows fit, retaining the old constant as a first-frame fallback.

Extracts the visible-row calculation into a pure computeVisibleCount() helper (including minimum visible rows and footer reserve) and adds vitest unit tests covering fallback, wrapped-header, and clamping scenarios.

Reviewed by Cursor Bugbot for commit 96fba2c. Bugbot is set up for automated code reviews on this repo. Configure here.

Replace the hardcoded PICKER_CHROME_ROWS=16 constant with Ink's
measureElement() so pagination math reflects the actually-rendered
header height. On narrow or resized terminals the PromptLabel can
wrap, which the old heuristic ignored — leading to off-by-one
cropping or the focused row scrolling off-screen.

The hardcoded constant is retained as a first-frame fallback before
Ink's first layout pass completes. After that we re-measure on
every render so wrapping changes propagate on the next paint.

The pagination math is extracted into a pure computeVisibleCount()
helper and unit tested.

Audit task #13.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kelsonpw kelsonpw requested a review from a team as a code owner April 25, 2026 19:37
@github-actions
Copy link
Copy Markdown
Contributor

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci django
  • /wizard-ci fastapi
  • /wizard-ci flask
  • /wizard-ci javascript-node
  • /wizard-ci javascript-web
  • /wizard-ci next-js
  • /wizard-ci python
  • /wizard-ci react-router
  • /wizard-ci vue

Test an individual app:

  • /wizard-ci django/django3-saas
  • /wizard-ci fastapi/fastapi3-ai-saas
  • /wizard-ci flask/flask3-social-media
Show more apps
  • /wizard-ci javascript-node/express-todo
  • /wizard-ci javascript-node/fastify-blog
  • /wizard-ci javascript-node/hono-links
  • /wizard-ci javascript-node/koa-notes
  • /wizard-ci javascript-node/native-http-contacts
  • /wizard-ci javascript-web/saas-dashboard
  • /wizard-ci next-js/15-app-router-saas
  • /wizard-ci next-js/15-app-router-todo
  • /wizard-ci next-js/15-pages-router-saas
  • /wizard-ci next-js/15-pages-router-todo
  • /wizard-ci python/meeting-summarizer
  • /wizard-ci react-router/react-router-v7-project
  • /wizard-ci react-router/rrv7-starter
  • /wizard-ci react-router/saas-template
  • /wizard-ci react-router/shopper
  • /wizard-ci vue/movies

Results will be posted here when complete.

@kelsonpw kelsonpw merged commit c4c3ae1 into main Apr 26, 2026
13 checks passed
@kelsonpw kelsonpw deleted the feat/tui-pickermenu-measureelement branch April 26, 2026 00:35
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