From 01e057b5d6d5a727ad135d088b437333066fd445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Thu, 13 Aug 2026 16:27:22 +0200 Subject: [PATCH] Show only commented files in the review view Even out the page's vertical rhythm while there: one gap owns the spacing between blocks, so it holds whichever blocks a review has. --- src/components/Discussion.svelte | 20 +++++++-- src/components/PierreDiff.svelte | 70 ++++++++++++++++++++++++++------ src/components/ReviewPage.svelte | 62 ++++++++++++++++------------ 3 files changed, 110 insertions(+), 42 deletions(-) diff --git a/src/components/Discussion.svelte b/src/components/Discussion.svelte index bcd083bfe..215a56514 100644 --- a/src/components/Discussion.svelte +++ b/src/components/Discussion.svelte @@ -52,6 +52,9 @@ deleteComment?: (commentId: string) => Promise; rid: string; activityItems?: ActivityItem[]; + /// Drops the outer margin, for a host that owns the spacing between its own + /// blocks. The default keeps the spacing the timeline pages rely on. + flush?: boolean; renderActivity?: Snippet<[A, { hideAuthor: boolean }]>; authorOf?: (data: A) => Author | undefined; afterActivity?: Snippet; @@ -69,6 +72,7 @@ deleteComment, rid, activityItems, + flush = false, renderActivity, authorOf, afterActivity, @@ -203,13 +207,19 @@ -
+
-
+
0}> {#each runs as run, runIndex (runIndex)} {#if run.kind === "thread"} ; + // Restricts the diff to these files (by new-side path). + includePaths?: ReadonlySet; // Files (by new-side path) marked reviewed. Providing this shows the // reviewed toggle in every file header; leave unset to hide it. reviewedPaths?: ReadonlySet; @@ -147,6 +149,7 @@ stickyTop = undefined, filesHeader = undefined, collapsedPaths = undefined, + includePaths = undefined, reviewedPaths = undefined, onToggleReviewed = undefined, commentCounts = undefined, @@ -331,9 +334,19 @@ } const lineHeightPx = $derived(codeLineHeight(fontSettings.size)); let view = $state.raw | undefined>(undefined); - // The parsed files, kept so `scrollToFile` can map a path to its diff item. + // Everything the patch parsed to, kept so `includePaths` can be re-applied + // without re-parsing. + let allFiles = $state.raw([]); + // The files actually on screen, which is what `scrollToFile` and the comment + // layer walk. let parsedFiles = $state.raw([]); + function visibleFiles(files: FileDiffMetadata[]): FileDiffMetadata[] { + return includePaths + ? files.filter(file => includePaths.has(file.name)) + : files; + } + // Scroll to a logical position in the scroll content, where 0 is the top of // the `header`. Pierre reuses a paged scroll scaffold, so the logical position // is not the container's `scrollTop` and has to go through `scrollTo`. @@ -359,8 +372,9 @@ let pendingScroll: { path: string; anchor?: CommentAnchor } | undefined; function applyScroll(target: { path: string; anchor?: CommentAnchor }): void { - const index = parsedFiles.findIndex(file => file.name === target.path); - if (index < 0) { + const id = target.path; + const item = view?.getItem(id); + if (!item) { // The patch is parsed off the main thread, so a caller that switches the // diff and immediately scrolls arrives before there are any items. Hold // the target and apply it once they exist. @@ -368,8 +382,6 @@ return; } pendingScroll = undefined; - const id = String(index); - const item = view?.getItem(id); // A collapsed file has no line to arrive at (a lockfile or one already // marked reviewed starts that way), so open it first. if (item?.type === "diff" && item.collapsed === true) { @@ -415,8 +427,8 @@ if (!instance) { return; } - for (let index = 0; index < parsedFiles.length; index++) { - const item = instance.getItem(String(index)); + for (const file of parsedFiles) { + const item = instance.getItem(file.name); if (item) { instance.updateItem({ ...item, @@ -883,8 +895,8 @@ function buildItems( files: FileDiffMetadata[], ): CodeViewItem[] { - return files.map((fileDiff, index) => ({ - id: String(index), + return files.map(fileDiff => ({ + id: fileDiff.name, type: "diff", fileDiff, collapsed: collapsedPaths?.has(fileDiff.name) === true, @@ -1049,8 +1061,8 @@ } untrack(() => { let changed = false; - for (let index = 0; index < parsedFiles.length; index++) { - const item = instance.getItem(String(index)); + for (const file of parsedFiles) { + const item = instance.getItem(file.name); if (item?.type !== "diff") { continue; } @@ -1074,6 +1086,32 @@ }); }); + // `includePaths` is a live filter: deleting the last comment on a file should + // take the file with it, not leave it behind until the next reload. Compared + // by name rather than by set identity, since the host rebuilds the set on + // every reload whether or not its contents moved. + $effect(() => { + void includePaths; + const instance = view; + if (!instance) { + return; + } + untrack(() => { + if (allFiles.length === 0) { + return; + } + const shown = visibleFiles(allFiles); + const before = parsedFiles.map(file => file.name).join("\u0000"); + const after = shown.map(file => file.name).join("\u0000"); + if (before === after) { + return; + } + parsedFiles = shown; + instance.setItems(buildItems(shown)); + instance.render(true); + }); + }); + // Structural rebuild: only when the patch text or the container changes. // // Everything past those two reads is untracked, and has to stay that way. The @@ -1115,8 +1153,10 @@ if (cancelled) { return; } - parsedFiles = files; - instance.setItems(buildItems(files)); + allFiles = files; + const shown = visibleFiles(files); + parsedFiles = shown; + instance.setItems(buildItems(shown)); instance.render(true); if (pendingScroll !== undefined) { applyScroll(pendingScroll); @@ -1131,6 +1171,10 @@ return () => { cancelled = true; view = undefined; + // Cleared so the `includePaths` filter cannot fire against the outgoing + // patch's files while the next one is still parsing. + allFiles = []; + parsedFiles = []; pendingSlotItems = undefined; unmountHeaders(); unmountAnnotations(); diff --git a/src/components/ReviewPage.svelte b/src/components/ReviewPage.svelte index 61cb88434..9d635f8cb 100644 --- a/src/components/ReviewPage.svelte +++ b/src/components/ReviewPage.svelte @@ -388,8 +388,9 @@ return origins; }); - // File paths that carry review comments; those files start expanded, the - // rest of the changed files render collapsed. + // The files this review says something about. The diff below is restricted to + // these: a review is a record of what someone had to say, and a file they said + // nothing about is context they can already read on the Changes tab. const commentedPaths = $derived(new Set(fileGroups.map(g => g.path))); @@ -461,19 +462,6 @@ ), ); - // Only the files this review says something about are worth opening; the rest - // are context, and so are the lockfiles either way. - const collapsedPaths = $derived.by(() => { - // eslint-disable-next-line svelte/prefer-svelte-reactivity -- rebuilt fresh each derivation - const paths = new Set(fileMeta.ignored); - for (const path of fileMeta.statuses.keys()) { - if (!commentedPaths.has(path)) { - paths.add(path); - } - } - return paths; - }); - const commentCounts = $derived( commentCountsByPath( reviewCodeComments.threads, @@ -506,7 +494,6 @@ align-items: center; gap: 0.5rem; flex-wrap: wrap; - margin-bottom: 0.75rem; } .back { background-color: var(--color-surface-canvas); @@ -530,7 +517,6 @@ align-items: center; flex-wrap: wrap; gap: 0.5rem; - margin-bottom: 1.5rem; color: var(--color-text-secondary); font: var(--txt-body-m-regular); } @@ -565,8 +551,9 @@ position: relative; border: 1px solid var(--color-border-subtle); border-radius: var(--border-radius-md); - padding: 0.75rem 1rem; - margin-bottom: 1.5rem; + /* Matches the reply box and `Comment`'s own body inset, so the summary text + and the comment placeholder start on the same line. */ + padding: 0.75rem; font: var(--txt-body-m-regular); } .summary-empty { @@ -584,9 +571,7 @@ .summary-edit:focus-visible { opacity: 1; } - .summary-editor { - margin-bottom: 1.5rem; - } + .action-icon { background: none; border: 1px solid transparent; @@ -649,10 +634,28 @@ } /* The chrome is full width inside the diff's scroll content, so it carries its own horizontal padding — the same as the patch view's own header. */ + /* One rhythm for the whole review header: every block below is a direct child + and carries no vertical margin of its own, so the spacing stays even + whichever blocks a given review actually has. */ .chrome { display: flex; flex-direction: column; - padding: 1rem 1rem 0; + gap: 1.5rem; + /* The bottom padding is the same step as the gap: it is what separates the + last block from the first file, now that nothing in here carries a margin + of its own. */ + padding: 1rem 1rem 1.5rem; + } + /* Where the file list would be. Without it the page just stops after the + discussion, which reads as something having failed to load. Indented past + the cards' border to start on the same line as the text inside them, rather + than level with their edges. */ + .no-line-comments { + /* Just short of where the cards' text starts (their border plus padding). + Optically that reads as aligned: this line has no box around it, so the + mathematical offset looks a touch too far right. */ + padding-left: 0.75rem; + color: var(--color-text-tertiary); } .timestamp { color: var(--color-text-quaternary); @@ -818,7 +821,7 @@
{#if editingSummary} -
+
+ reactOnComment={codeActions.reactOnComment} + flush /> + + {#if loadedDiff && commentedPaths.size === 0} +
+ This review has no line comments. +
+ {/if}
{/snippet} @@ -879,7 +889,7 @@ ? path => getDiffText(rid, reviewedRevision.base, reviewedRevision.head, 3, path) : undefined} - {collapsedPaths} + includePaths={commentedPaths} {commentCounts} codeComments={reviewCodeComments} commentCommit={reviewedRevision?.head}