diff --git a/desktop/src/components/Changes.svelte b/desktop/src/components/Changes.svelte index 1a82f9bf1..953c9b3b6 100644 --- a/desktop/src/components/Changes.svelte +++ b/desktop/src/components/Changes.svelte @@ -77,6 +77,10 @@ // The revision and commit the patch is marked merged at, if any. merge?: { revision: string; commit: string }; onViewRevision?: (revisionId: string) => void; + // The commit to diff the revision's head against instead of its base, such + // as the previous revision's head. Read when the tab opens and cleared here + // once the diff on screen is anything else: another revision or a commit. + compareFrom?: string; } /* eslint-disable prefer-const */ @@ -101,6 +105,7 @@ revisions = [], merge, onViewRevision, + compareFrom = $bindable(), }: Props = $props(); /* eslint-enable prefer-const */ @@ -112,7 +117,7 @@ // Parent reuses this component across patch revisions; a sibling $effect // resets base and head when patchId changes. // svelte-ignore state_referenced_locally - let base = $state(revision.base); + let base = $state(compareFrom ?? revision.base); // svelte-ignore state_referenced_locally let head = $state(revision.head); @@ -133,6 +138,7 @@ selectedCommitData = undefined; editingDescription = false; base = nextBase; + compareFrom = undefined; head = nextHead; }); }); @@ -152,6 +158,7 @@ }) { head = headId; base = baseId; + compareFrom = undefined; selectedCommit = commitId; selectedCommitData = commit; filesExpanded = showFiles; @@ -334,8 +341,11 @@ // list alone decides it: when the head is a strict ancestor of the base, the // tree diff between them is the base's newer commits in reverse, not the // patch's changes. + // A comparison is another range: an empty revision still differs from the + // one before it. const emptyRevision = $derived( - commitListRange === `${revision.base}..${revision.head}` && + compareFrom === undefined && + commitListRange === `${revision.base}..${revision.head}` && commitList.length === 0, ); const earlierRevision = $derived( @@ -352,7 +362,8 @@ `${revision.base}..${revision.head}`, selectedCommit, ); - if (only) { + // A comparison is a range of its own, which selecting the commit would end. + if (only && compareFrom === undefined) { selectRevision({ headId: revision.head, baseId: revision.base, @@ -409,6 +420,13 @@ diffView?.scrollToFilesTop(); } + /// Go back to the revision's own changes, which ends a comparison. Driven + /// from the tab bar, which the patch view renders. + export function showRevisionChanges() { + selectRevision({ headId: revision.head, baseId: revision.base }); + void scrollToDiff(); + } + /// Collapse or expand every file. Driven from the tab bar, which the patch /// view renders. export function setAllFilesCollapsed(collapsed: boolean) { @@ -461,7 +479,8 @@ useShortcuts( { shortcut: "previousCommit", - enabled: () => commitList.length > 1, + // The commits column is hidden during a comparison. + enabled: () => commitList.length > 1 && compareFrom === undefined, run: () => { const current = commitList.findIndex(c => c.id === selectedCommit); selectCommitAt(stepCommitIndex(current, commitList.length, -1)); @@ -469,7 +488,8 @@ }, { shortcut: "nextCommit", - enabled: () => commitList.length > 1, + // The commits column is hidden during a comparison. + enabled: () => commitList.length > 1 && compareFrom === undefined, run: () => { const current = commitList.findIndex(c => c.id === selectedCommit); selectCommitAt(stepCommitIndex(current, commitList.length, 1)); @@ -980,6 +1000,8 @@ codeComments={diffCodeComments} commentCommit={isRevisionDiff ? head : undefined} header={diffHeader} - overlayLeft={emptyRevision ? undefined : commitsColumn} + overlayLeft={emptyRevision || compareFrom !== undefined + ? undefined + : commitsColumn} {filesHeader} stickyTop={tabs} /> diff --git a/desktop/src/components/PatchActivityItem.svelte b/desktop/src/components/PatchActivityItem.svelte index caac5b0d3..002dd16db 100644 --- a/desktop/src/components/PatchActivityItem.svelte +++ b/desktop/src/components/PatchActivityItem.svelte @@ -7,6 +7,8 @@ + + + + + {#snippet toggle(onclick)} + + {/snippet} + + {#snippet popover()} +
+ + {#snippet item(entry)} + {#if entry === "base"} + compare()}> + + Compare to base: + {formatOid(base)} + + + {:else if previous} + + // An empty previous revision's head is this one's base. + compare(previous.head === base ? undefined : previous.head)}> + + Compare to previous revision: + + {formatOid(previous.id)} + + + + {/if} + {/snippet} + +
+ {/snippet} +
diff --git a/desktop/src/views/repo/Patch.svelte b/desktop/src/views/repo/Patch.svelte index c587b13cf..c441d0316 100644 --- a/desktop/src/views/repo/Patch.svelte +++ b/desktop/src/views/repo/Patch.svelte @@ -38,6 +38,7 @@ absoluteTimestamp, authorForNodeId, didFromPublicKey, + formatOid, formatTimestamp, patchStatusLabel, publicKeyFromDid, @@ -186,6 +187,11 @@ // When opening a specific revision's changes from the timeline, the target // survives the view switch (the reset effect below honours it once). let pendingRevisionId: string | undefined; + let pendingCompareFrom: string | undefined; + // The commit the Changes tab diffs the selected revision's head against, when + // it is not the base: the previous revision's head, from the compare menu. + // Set here only on the way into the tab; the tab ends the comparison itself. + let compareFrom: string | undefined = $state(); // Warm the Changes-tab data for the selected revision in the background, so // opening the tab is instant instead of showing a fetch delay. Both halves of @@ -442,7 +448,9 @@ if (patchView !== lastPatchView) { lastPatchView = patchView; selectedRevisionId = pendingRevisionId ?? revisions.slice(-1)[0].id; + compareFrom = pendingCompareFrom; pendingRevisionId = undefined; + pendingCompareFrom = undefined; } }); @@ -964,6 +972,10 @@ selectedRevision.id, config.publicKey, ); + // A review is written on the revision's own changes. + if (compareFrom !== undefined) { + revisionComponent?.showRevisionChanges(); + } setView("changes"); }} title={hasOwnPublishedReviewOnSelected @@ -1151,7 +1163,18 @@ Back to latest revision {/if} - {#if orderedRevisions.length > 1} + {#if compareFrom !== undefined} + + {:else if orderedRevisions.length > 1} { - pendingRevisionId = revisionId; + onViewChanges={(revisionId, from) => { + // Only a view switch takes the pending pair, so one set on the + // Changes tab would wait for a later, unrelated switch. + if (patchView !== "changes") { + pendingRevisionId = revisionId; + pendingCompareFrom = from; + } selectedRevisionId = revisionId; + compareFrom = from; setView("changes"); }} merge={patch.state.status === "merged" ? patch.state : undefined} chrome={patchHeader} {tabs} + bind:compareFrom bind:showingRevisionDiff bind:filesExpanded bind:commentPosition />