Skip to content

Commit 7044441

Browse files
committed
update to height based on all available height module fix overflow
1 parent 03c0f25 commit 7044441

6 files changed

Lines changed: 88 additions & 74 deletions

File tree

package-lock.json

Lines changed: 27 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/src/ui/components/AskUserDialog.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
useEffect,
1313
useReducer,
1414
useContext,
15+
useState,
1516
} from 'react';
1617
import { Box, Text } from 'ink';
1718
import { theme } from '../semantic-colors.js';
@@ -782,38 +783,39 @@ const ChoiceQuestionView: React.FC<ChoiceQuestionViewProps> = ({
782783
}
783784
}, [customOptionText, isCustomOptionSelected, question.multiSelect]);
784785

786+
const [actualQuestionHeight, setActualQuestionHeight] = useState(0);
787+
785788
const HEADER_HEIGHT = progressHeader ? 2 : 0;
786789
const TITLE_MARGIN = 1;
787790
const FOOTER_HEIGHT = 2; // DialogFooter + margin
788791
const overhead = HEADER_HEIGHT + TITLE_MARGIN + FOOTER_HEIGHT;
792+
789793
const listHeight = availableHeight
790794
? Math.max(1, availableHeight - overhead)
791795
: undefined;
792-
const maxQuestionHeight =
793-
question.unconstrainedHeight && listHeight
794-
? // When unconstrained, give the question a majority of the vertical space (e.g., 70%).
795-
// The options list will take the remaining space and scroll if necessary.
796-
// This is more robust than calculating based on `selectionItems.length`,
797-
// which can incorrectly shrink the question if there are many options.
798-
Math.max(5, Math.floor(listHeight * 0.7))
799-
: 15;
800-
const questionHeight =
796+
797+
// Modulo the fixed overflow (overhead + 4 lines reserved for list), use all remaining height.
798+
const maxQuestionHeight = listHeight ? Math.max(5, listHeight - 4) : 15;
799+
800+
const questionHeightLimit =
801801
listHeight && !isAlternateBuffer
802-
? Math.min(maxQuestionHeight, Math.max(1, listHeight - DIALOG_PADDING))
802+
? Math.min(maxQuestionHeight, listHeight)
803803
: undefined;
804+
804805
const maxItemsToShow =
805-
listHeight && questionHeight
806-
? Math.max(1, Math.floor((listHeight - questionHeight) / 2))
806+
listHeight && actualQuestionHeight
807+
? Math.max(1, Math.floor((listHeight - actualQuestionHeight) / 2))
807808
: selectionItems.length;
808809

809810
return (
810811
<Box flexDirection="column">
811812
{progressHeader}
812813
<Box marginBottom={TITLE_MARGIN}>
813814
<MaxSizedBox
814-
maxHeight={questionHeight}
815+
maxHeight={questionHeightLimit}
815816
maxWidth={availableWidth}
816817
overflowDirection="bottom"
818+
onHeightChange={setActualQuestionHeight}
817819
>
818820
<Box flexDirection="column">
819821
<MarkdownDisplay

packages/cli/src/ui/components/ToolConfirmationQueue.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,10 @@ describe('ToolConfirmationQueue', () => {
282282
// hideToolIdentity is true for ask_user -> subtracts 4 instead of 6
283283
// availableContentHeight = 19 - 4 = 15
284284
// ToolConfirmationMessage handlesOwnUI=true -> returns full 15
285-
// AskUserDialog allocates questionHeight = Math.min(maxQuestionHeight, Math.max(5, listHeight - DIALOG_PADDING)).
286-
// maxQuestionHeight = floor(15 * 0.7) = 10.
287-
// 10 lines is enough for the 6-line question + padding.
285+
// AskUserDialog allocates questionHeight = availableHeight - overhead - minListHeight.
286+
// listHeight = 15 - overhead (Header:0, Margin:1, Footer:2) = 12.
287+
// maxQuestionHeight = listHeight - 4 = 8.
288+
// 8 lines is enough for the 6-line question.
288289
await waitFor(() => {
289290
expect(lastFrame()).toContain('Line 6');
290291
expect(lastFrame()).not.toContain('lines hidden');

0 commit comments

Comments
 (0)