Render a fixed-width inline span sequence for one diff cell.
(
spans: RenderSpan[],
width: number,
fallbackColor: string,
fallbackBg: string,
keyPrefix: string,
horizontalOffset = 0,
selectionTheme?: AppTheme,
selectionColRange?: { start: number; end: number },
)
| 120 | |
| 121 | /** Render a fixed-width inline span sequence for one diff cell. */ |
| 122 | function renderInlineSpans( |
| 123 | spans: RenderSpan[], |
| 124 | width: number, |
| 125 | fallbackColor: string, |
| 126 | fallbackBg: string, |
| 127 | keyPrefix: string, |
| 128 | horizontalOffset = 0, |
| 129 | selectionTheme?: AppTheme, |
| 130 | selectionColRange?: { start: number; end: number }, |
| 131 | ) { |
| 132 | const { spans: trimmed, usedWidth } = sliceSpansWindow( |
| 133 | sanitizeTerminalSpans(spans), |
| 134 | horizontalOffset, |
| 135 | width, |
| 136 | ); |
| 137 | const needsBlending = selectionTheme && selectionColRange; |
| 138 | |
| 139 | // Build the final element list by splitting spans at selection boundaries so the highlight |
| 140 | // applies at character-level precision rather than whole-token granularity. |
| 141 | const elements: ReactNode[] = []; |
| 142 | let colPos = 0; |
| 143 | let elementIndex = 0; |
| 144 | |
| 145 | for (const span of trimmed) { |
| 146 | const spanWidth = measureTextWidth(span.text); |
| 147 | const spanStart = colPos; |
| 148 | const spanEnd = colPos + spanWidth; |
| 149 | colPos = spanEnd; |
| 150 | |
| 151 | if ( |
| 152 | !needsBlending || |
| 153 | spanEnd <= selectionColRange.start || |
| 154 | spanStart >= selectionColRange.end |
| 155 | ) { |
| 156 | // Span is entirely outside the selection — render with original styling. |
| 157 | elements.push( |
| 158 | <span |
| 159 | key={`${keyPrefix}:${elementIndex++}`} |
| 160 | fg={span.fg ?? fallbackColor} |
| 161 | bg={span.bg ?? fallbackBg} |
| 162 | > |
| 163 | {span.text} |
| 164 | </span>, |
| 165 | ); |
| 166 | continue; |
| 167 | } |
| 168 | |
| 169 | // Compute the split offsets within this span's text. |
| 170 | const localSelStart = Math.max(0, selectionColRange.start - spanStart); |
| 171 | const localSelEnd = Math.min(spanWidth, selectionColRange.end - spanStart); |
| 172 | |
| 173 | if (localSelStart >= localSelEnd) { |
| 174 | // No overlap after clamping — render original. |
| 175 | elements.push( |
| 176 | <span |
| 177 | key={`${keyPrefix}:${elementIndex++}`} |
| 178 | fg={span.fg ?? fallbackColor} |
| 179 | bg={span.bg ?? fallbackBg} |
no test coverage detected