MCPcopy Create free account
hub / github.com/modem-dev/hunk / makeStackCell

Function makeStackCell

src/ui/diff/pierre.ts:489–521  ·  view source on GitHub ↗

Build the normalized render model for one stack-view cell.

(
  kind: StackLineCell["kind"],
  oldLineNumber: number | undefined,
  newLineNumber: number | undefined,
  rawLine: string | undefined,
  highlightedLine: HastNode | undefined,
  theme: AppTheme,
  moveKind?: DiffLineMoveKind,
)

Source from the content-addressed store, hash-verified

487
488/** Build the normalized render model for one stack-view cell. */
489function makeStackCell(
490 kind: StackLineCell["kind"],
491 oldLineNumber: number | undefined,
492 newLineNumber: number | undefined,
493 rawLine: string | undefined,
494 highlightedLine: HastNode | undefined,
495 theme: AppTheme,
496 moveKind?: DiffLineMoveKind,
497) {
498 // Same lazy-fallback strategy as split cells: only normalize the raw source line when we really
499 // need the plain-text fallback, not when highlighted spans are already ready to reuse.
500 let spans: RenderSpan[];
501 if (highlightedLine === undefined) {
502 const fallbackText = cleanDiffLine(rawLine);
503 spans = fallbackText.length > 0 ? [{ text: fallbackText }] : [];
504 } else {
505 spans = flattenHighlightedLine(highlightedLine, theme, wordDiffHighlightBg(kind, theme));
506
507 if (spans.length === 0) {
508 const fallbackText = cleanDiffLine(rawLine);
509 spans = fallbackText.length > 0 ? [{ text: fallbackText }] : [];
510 }
511 }
512
513 return {
514 kind,
515 sign: kind === "addition" ? "+" : kind === "deletion" ? "-" : " ",
516 oldLineNumber,
517 newLineNumber,
518 moveKind,
519 spans,
520 } satisfies StackLineCell;
521}
522
523/** Describe one collapsed unchanged region in the diff stream. */
524function collapsedRowText(lines: number) {

Callers 1

buildStackRowsFunction · 0.85

Calls 3

cleanDiffLineFunction · 0.85
flattenHighlightedLineFunction · 0.85
wordDiffHighlightBgFunction · 0.85

Tested by

no test coverage detected