@@ -12,6 +12,7 @@ import {
1212 useEffect ,
1313 useReducer ,
1414 useContext ,
15+ useState ,
1516} from 'react' ;
1617import { Box , Text } from 'ink' ;
1718import { 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
0 commit comments