Skip to content

Commit

Permalink
refactor: prevent edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Mist3rBru committed Nov 10, 2023
1 parent 360afeb commit f33a56f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/prompts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ interface LimitOptionsParams<TOption> {
const limitOptions = <TOption>(params: LimitOptionsParams<TOption>): string[] => {
const { cursor, options, style } = params;

const paramMaxItems = params.maxItems ?? Infinity;
const outputMaxItems = Math.max(process.stdout.rows - 4, 0);
// We clamp to minimum 5 because anything less doesn't make sense UX wise
const maxItems =
params.maxItems === undefined ? process.stdout.rows - 4 : Math.max(params.maxItems, 5);
const maxItems = Math.min(outputMaxItems, Math.max(paramMaxItems, 5));
let slidingWindowLocation = 0;

if (cursor >= slidingWindowLocation + maxItems - 3) {
Expand Down

0 comments on commit f33a56f

Please sign in to comment.