1- import { useMemo } from "react" ;
1+ import { useCallback , useMemo } from "react" ;
22import type { DiffFile , LayoutMode } from "../../core/types" ;
33import { AgentInlineNote , AgentInlineNoteGuideCap } from "../components/panes/AgentInlineNote" ;
44import type { VisibleAgentNote } from "../lib/agentAnnotations" ;
@@ -7,12 +7,13 @@ import { reviewRowId } from "../lib/ids";
77import type { AppTheme } from "../themes" ;
88import { findMaxLineNumber , findMaxLineNumberInRows } from "./codeColumns" ;
99import { expandCollapsedRows , type FileSourceStatus } from "./expandCollapsedRows" ;
10- import { buildSplitRows , buildStackRows } from "./pierre" ;
10+ import { buildSplitRows , buildStackRows , spansForHighlightedSourceLine } from "./pierre" ;
1111import { plannedReviewRowVisible } from "./plannedReviewRows" ;
1212import { buildReviewRenderPlan } from "./reviewRenderPlan" ;
1313import { resolveVisiblePlannedRowWindow , type VisibleBodyBounds } from "./rowWindowing" ;
1414import { diffMessage , DiffRowView , fitText } from "./renderRows" ;
1515import { useHighlightedDiff } from "./useHighlightedDiff" ;
16+ import { useHighlightedSource } from "./useHighlightedSource" ;
1617
1718const EMPTY_ANNOTATED_HUNK_INDICES = new Set < number > ( ) ;
1819const EMPTY_VISIBLE_AGENT_NOTES : VisibleAgentNote [ ] = [ ] ;
@@ -65,6 +66,23 @@ export function PierreDiffView({
6566 appearance : theme . appearance ,
6667 shouldLoadHighlight,
6768 } ) ;
69+ const sourceTextForHighlight =
70+ sourceStatus ?. kind === "loaded" && expandedGapKeys . size > 0 ? sourceStatus . text : undefined ;
71+ const resolvedHighlightedSource = useHighlightedSource ( {
72+ file,
73+ text : sourceTextForHighlight ,
74+ appearance : theme . appearance ,
75+ shouldLoadHighlight : shouldLoadHighlight && expandedGapKeys . size > 0 ,
76+ } ) ;
77+ const sourceLineSpans = useCallback (
78+ ( line : string | undefined , sourceLineNumber : number ) =>
79+ spansForHighlightedSourceLine (
80+ line ,
81+ resolvedHighlightedSource ?. lines [ sourceLineNumber ] ,
82+ theme ,
83+ ) ,
84+ [ resolvedHighlightedSource , theme ] ,
85+ ) ;
6886
6987 const rows = useMemo (
7088 ( ) =>
@@ -86,10 +104,11 @@ export function PierreDiffView({
86104 expandCollapsedRows ( rows , {
87105 layout,
88106 expandedKeys : expandedGapKeys ,
107+ sourceLineSpans,
89108 sourceStatus,
90109 side : expansionSide ,
91110 } ) ,
92- [ rows , layout , expandedGapKeys , sourceStatus , expansionSide ] ,
111+ [ rows , layout , expandedGapKeys , sourceLineSpans , sourceStatus , expansionSide ] ,
93112 ) ;
94113 const plannedRows = useMemo (
95114 ( ) =>
0 commit comments