Skip to content

Commit 0f4f2df

Browse files
fix(web): a guide excerpt keeps its selected lines when the diff reloads
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 364b893 commit 0f4f2df

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎apps/web/src/components/pullRequest/guide/GuideExcerpt.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ export function GuideExcerpt({
138138
loadDiffFiles: FileDiffContentsLoader;
139139
onOpenFile: (path: string) => void;
140140
}) {
141+
// Kept here, not in ExcerptDiff, so a selection survives the diff reloading for a new head.
142+
const [draft, setDraft] = useState<ExcerptDraft | null>(null);
141143
const slice = excerptSlice(file, excerpt);
142144

143145
return (
@@ -152,6 +154,8 @@ export function GuideExcerpt({
152154
excerpt={excerpt}
153155
file={file}
154156
slice={slice}
157+
draft={draft}
158+
setDraft={setDraft}
155159
loadDiffFiles={loadDiffFiles}
156160
notes={notes}
157161
commenting={commenting}
@@ -176,11 +180,13 @@ export function GuideExcerpt({
176180
);
177181
}
178182

179-
// Owns the comment draft so draft edits re-render the diff without re-slicing the patch.
183+
// Split out so draft changes re-render the diff without re-slicing the patch.
180184
function ExcerptDiff({
181185
excerpt,
182186
file,
183187
slice,
188+
draft,
189+
setDraft,
184190
loadDiffFiles,
185191
notes,
186192
commenting,
@@ -189,12 +195,13 @@ function ExcerptDiff({
189195
excerpt: PullRequestReviewGuideExcerpt;
190196
file: FileDiffMetadata;
191197
slice: ExcerptSlice;
198+
draft: ExcerptDraft | null;
199+
setDraft: (draft: ExcerptDraft | null) => void;
192200
loadDiffFiles: FileDiffContentsLoader;
193201
notes: ReadonlyArray<ExcerptNoteMarker>;
194202
commenting: ExcerptCommenting | null;
195203
onOpenFile: (path: string) => void;
196204
}) {
197-
const [draft, setDraft] = useState<ExcerptDraft | null>(null);
198205
const { resolvedTheme } = useTheme();
199206
const loadExcerptFiles = excerptLoader(excerpt, slice.rows, loadDiffFiles);
200207

0 commit comments

Comments
 (0)