44import type { RenderElement } from 'claude-code'
55
66import Limits from '../../limits'
7+ import Detail from '../detail'
78import type { Kit } from '../kit'
9+ import Layout from '../layout'
810import Sections from '../sections'
911import Plan from './plan'
10- import type { BodyLayout , Segment } from './types'
12+ import type { BodyLayout , HunkSegment , Segment , WindowCut } from './types'
1113
1214/**
1315 * The rows of the docked body its window shows from a row down: each
1416 * segment drawn from the row the window cuts it at, until the window fills.
1517 *
16- * A hunk cut by the window's top draws from the line holding that row on;
17- * rows past its foot are the pane 's to clip, so a few more are drawn than
18- * fit (SCROLL_MARGIN_ROWS) lest a miscounted wrap leave it short .
18+ * A hunk draws only its lines in view, and past MAX_BODY_CHARS of hunk
19+ * text the rest waits for a scroll ( the tree 's cap); rows past the foot
20+ * are the pane's to clip, so SCROLL_MARGIN_ROWS more are drawn than fit .
1921 *
2022 * @param kit the elements, the handlers, the width
2123 * @param layout the body laid out
@@ -27,16 +29,33 @@ export function drawWindow(
2729 layout : BodyLayout ,
2830 top : number ,
2931) : RenderElement [ ] {
30- const { Box, Text } = kit . ui
32+ const { Box, Text, Code } = kit . ui
3133 const drawn : RenderElement [ ] = [ ]
3234 const wanted = layout . visibleRows + Limits . SCROLL_MARGIN_ROWS
3335 const at = Math . max ( 0 , Math . min ( top , layout . maxTop ) )
3436 const onPress = kit . actions . togglePreSession
3537
3638 let start = 0
3739 let filled = 0
40+ let chars = 0
3841
39- function elementOf ( segment : Segment , skip : number ) : RenderElement {
42+ function codeOf ( segment : HunkSegment , cut : WindowCut ) : RenderElement {
43+ const source = Detail . hunkSourceOf ( Plan . hunkWindowOf ( segment , cut ) )
44+ const path = Layout . sanitizeName ( segment . path )
45+ chars += source . length
46+
47+ const isOver = chars > Detail . MAX_BODY_CHARS
48+
49+ return isOver ? (
50+ < Text dimColor italic >
51+ …
52+ </ Text >
53+ ) : (
54+ < Code source = { source } format = "diff" path = { path } />
55+ )
56+ }
57+
58+ function elementOf ( segment : Segment , cut : WindowCut ) : RenderElement {
4059 switch ( segment . kind ) {
4160 case 'rule' :
4261 return Sections . divider ( kit )
@@ -45,7 +64,7 @@ export function drawWindow(
4564 case 'name' :
4665 return Sections . nameRow ( kit , segment . name )
4766 case 'hunk' :
48- return Plan . hunkCodeOf ( kit , segment , skip )
67+ return codeOf ( segment , cut )
4968 case 'note' :
5069 return (
5170 < Text dimColor italic wrap = "wrap" >
@@ -74,7 +93,7 @@ export function drawWindow(
7493 if ( isShown ) {
7594 const skip = Math . max ( 0 , at - start )
7695
77- drawn . push ( elementOf ( segment , skip ) )
96+ drawn . push ( elementOf ( segment , { skip, take : wanted - filled } ) )
7897 filled += rows - skip
7998 }
8099
0 commit comments