Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-reply-range-rails.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hunkdiff": patch
---

Stop drawing duplicate right-side range connectors on threaded reply cards.
33 changes: 33 additions & 0 deletions packages/hunk/src/ui/diff/reviewRenderPlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,39 @@ describe("review render plan", () => {
expect(inlineNotes.map((row) => row.rangeGuideConnection)).toEqual(["continue", "continue"]);
});

test("connects only the root card of a reply thread to the external range rail", () => {
const theme = resolveTheme("github-dark-default", null);
const file = createDiffFile(
"thread",
"thread.ts",
"export const alpha = 1;\n",
"export const alpha = 2;\nexport const beta = 3;\n",
);
const rows = buildSplitRows(file, null, theme);
const notes = [
createVisibleAgentNote(file.metadata.hunks, {
id: "root",
annotation: { newRange: [2, 2], summary: "Root note" },
thread: { noteId: "root", depth: 0, hasNextSibling: false },
}),
createVisibleAgentNote(file.metadata.hunks, {
id: "child",
annotation: { newRange: [2, 2], summary: "Child reply" },
thread: { noteId: "child", parentId: "root", depth: 1, hasNextSibling: false },
}),
];
const plannedRows = buildReviewRenderPlan({
fileId: file.id,
rows,
showHunkHeaders: true,
visibleAgentNotes: notes,
});
const inlineNotes = plannedRows.filter((row) => row.kind === "inline-note");

expect(inlineNotes).toHaveLength(2);
expect(inlineNotes.map((row) => row.rangeGuideConnection)).toEqual(["terminate", undefined]);
});

test("connects a deletion-only anchor row directly into its inline note", () => {
const theme = resolveTheme("github-dark-default", null);
const file = createDiffFile(
Expand Down
24 changes: 19 additions & 5 deletions packages/hunk/src/ui/diff/reviewRenderPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,18 @@ export function buildReviewRenderPlan({
);

const anchoredNotes = placementsByAnchor.get(row.key) ?? [];
let remainingRootNotes = anchoredNotes.reduce(
(count, placement) => count + ((placement.note.thread?.depth ?? 0) === 0 ? 1 : 0),
0,
);

anchoredNotes.forEach((placement) => {
const isThreadReply = (placement.note.thread?.depth ?? 0) > 0;
if (!isThreadReply) {
remainingRootNotes -= 1;
}
const hasLaterRootNote = remainingRootNotes > 0;

plannedRows.push({
kind: "inline-note",
key: `inline-note:${placement.note.id}:${row.key}:${placement.noteIndex}`,
Expand All @@ -506,11 +517,14 @@ export function buildReviewRenderPlan({
anchorSide: placement.anchorSide,
noteCount: placement.noteCount,
noteIndex: placement.noteIndex,
rangeGuideConnection: !noteGuideSideByRowKey.has(row.key)
? undefined
: placement.noteIndex < placement.noteCount - 1 || rangeGuideContinuationRows.has(row.key)
? "continue"
: "terminate",
// Replies already connect through the thread gutter on the left. Keep the
// external range rail on root cards so the thread has only one range connection.
rangeGuideConnection:
isThreadReply || !noteGuideSideByRowKey.has(row.key)
? undefined
: hasLaterRootNote || rangeGuideContinuationRows.has(row.key)
? "continue"
: "terminate",
});
});
}
Expand Down
Loading