@@ -8,26 +8,33 @@ export type { ShellOutputEntry } from './shell-output-line';
88
99type ShellIOListProps = {
1010 output : ShellOutputEntry [ ] ;
11- InputPrompt : JSX . Element ;
11+ renderInputPrompt : ( ) => JSX . Element ;
1212 setScrollRef : ( ref : HTMLDivElement ) => void ;
13+ __TEST_OVERSCAN_COUNT ?: number ;
14+ __TEST_LIST_HEIGHT ?: number ;
1315} ;
1416
15- export const ShellIOList = ( {
17+ export const ShellOutput = ( {
1618 output,
17- InputPrompt ,
19+ renderInputPrompt ,
1820 setScrollRef,
21+ __TEST_OVERSCAN_COUNT ,
22+ __TEST_LIST_HEIGHT ,
1923} : ShellIOListProps ) => {
2024 const listRef : VirtualListRef = useRef ( ) ;
2125
2226 useEffect ( ( ) => {
23- if ( listRef . current ) {
24- listRef . current . resetAfterIndex ( 0 ) ;
25- setTimeout ( ( ) => {
26- // After output changes, scroll to the end (which is
27- // prompt input)
28- listRef . current . scrollToItem ( output . length , 'end' ) ;
29- } , 100 ) ;
27+ if ( ! listRef . current ) {
28+ return ;
3029 }
30+ ( window as any ) . listRef = listRef . current ;
31+ listRef . current . resetAfterIndex ( 0 ) ;
32+ const timeout = setTimeout ( ( ) => {
33+ // After output changes, scroll to the end (which is
34+ // prompt input)
35+ listRef . current . scrollToItem ( output . length , 'end' ) ;
36+ } , 100 ) ;
37+ return ( ) => clearTimeout ( timeout ) ;
3138 } , [ output , listRef ] ) ;
3239
3340 // Adding prompt to the input list so that its also rendered
@@ -38,21 +45,25 @@ export const ShellIOList = ({
3845 < VirtualList
3946 dataTestId = "shell-output-virtual-list"
4047 items = { items }
41- overScanCount = { 20 }
48+ overScanCount = { __TEST_OVERSCAN_COUNT ?? 1 }
4249 listRef = { listRef }
4350 scrollableContainerRef = { setScrollRef }
4451 renderItem = { ( item , ref ) => {
52+ if ( item . type === 'inputPrompt' ) {
53+ return (
54+ < div ref = { ref } data-testid = "shell-input-prompt" >
55+ { renderInputPrompt ( ) }
56+ </ div >
57+ ) ;
58+ }
4559 return (
46- < div ref = { ref } >
47- { item . type === 'inputPrompt' ? (
48- InputPrompt
49- ) : (
50- < ShellOutputLine entry = { item as ShellOutputEntry } />
51- ) }
60+ < div ref = { ref } data-testid = "shell-output-line" >
61+ < ShellOutputLine entry = { item as ShellOutputEntry } />
5262 </ div >
5363 ) ;
5464 } }
5565 estimateItemInitialHeight = { ( ) => 24 }
66+ __TEST_LIST_HEIGHT = { __TEST_LIST_HEIGHT }
5667 />
5768 ) ;
5869} ;
0 commit comments