({
layoutContent,
cursorProbe,
cols,
maxHeight,
minHeight = 1,
}: {
layoutContent: string
cursorProbe: string
cols: number
maxHeight: number
minHeight?: number
})
| 111 | } |
| 112 | |
| 113 | export function computeInputLayoutMetrics({ |
| 114 | layoutContent, |
| 115 | cursorProbe, |
| 116 | cols, |
| 117 | maxHeight, |
| 118 | minHeight = 1, |
| 119 | }: { |
| 120 | layoutContent: string |
| 121 | cursorProbe: string |
| 122 | cols: number |
| 123 | maxHeight: number |
| 124 | minHeight?: number |
| 125 | }): { heightLines: number; gutterEnabled: boolean } { |
| 126 | const safeMaxHeight = Math.max(1, maxHeight) |
| 127 | const effectiveMinHeight = Math.max( |
| 128 | 1, |
| 129 | Math.min(minHeight ?? 1, safeMaxHeight), |
| 130 | ) |
| 131 | const totalLines = measureLines(layoutContent, cols) |
| 132 | const cursorLines = measureLines(cursorProbe, cols) |
| 133 | |
| 134 | // Add bottom gutter when cursor is on line 2 of exactly 2 lines |
| 135 | const gutterEnabled = |
| 136 | totalLines === 2 && cursorLines === 2 && totalLines + 1 <= safeMaxHeight |
| 137 | |
| 138 | const rawHeight = Math.min( |
| 139 | totalLines + (gutterEnabled ? 1 : 0), |
| 140 | safeMaxHeight, |
| 141 | ) |
| 142 | |
| 143 | const heightLines = Math.max(effectiveMinHeight, rawHeight) |
| 144 | |
| 145 | return { |
| 146 | heightLines, |
| 147 | gutterEnabled, |
| 148 | } |
| 149 | } |
no test coverage detected