diff --git a/desktop/src/components/Changes.svelte b/desktop/src/components/Changes.svelte index 953c9b3b6..9ad432a0c 100644 --- a/desktop/src/components/Changes.svelte +++ b/desktop/src/components/Changes.svelte @@ -77,9 +77,11 @@ // 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. + // The commit to diff the revision's head against when the tab opens, + // instead of its base. + initialCompareFrom?: string; + // Output: the commit the diff on screen compares the revision's head + // against, while that is not its base. compareFrom?: string; } @@ -105,6 +107,7 @@ revisions = [], merge, onViewRevision, + initialCompareFrom, compareFrom = $bindable(), }: Props = $props(); /* eslint-enable prefer-const */ @@ -117,7 +120,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(compareFrom ?? revision.base); + let base = $state(initialCompareFrom ?? revision.base); // svelte-ignore state_referenced_locally let head = $state(revision.head); @@ -138,7 +141,6 @@ selectedCommitData = undefined; editingDescription = false; base = nextBase; - compareFrom = undefined; head = nextHead; }); }); @@ -158,7 +160,6 @@ }) { head = headId; base = baseId; - compareFrom = undefined; selectedCommit = commitId; selectedCommitData = commit; filesExpanded = showFiles; @@ -177,6 +178,21 @@ } }); + // A comparison is the revision's head diffed against another commit than its + // base, which only `compare` sets up. + const comparedFrom = $derived( + selectedCommit === undefined && + head === revision.head && + base !== revision.base + ? base + : undefined, + ); + $effect(() => { + if (compareFrom !== comparedFrom) { + compareFrom = comparedFrom; + } + }); + // A `CodeLocation` records the commit a comment was written against but not // the base it was diffed from, and placement matches on path and line alone, // so a narrowed view carries no comment layer at all. @@ -344,7 +360,7 @@ // A comparison is another range: an empty revision still differs from the // one before it. const emptyRevision = $derived( - compareFrom === undefined && + comparedFrom === undefined && commitListRange === `${revision.base}..${revision.head}` && commitList.length === 0, ); @@ -363,7 +379,7 @@ selectedCommit, ); // A comparison is a range of its own, which selecting the commit would end. - if (only && compareFrom === undefined) { + if (only && comparedFrom === undefined) { selectRevision({ headId: revision.head, baseId: revision.base, @@ -420,10 +436,11 @@ 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 }); + /// Diff the revision's head against `from`, or against its base when absent, + /// which ends a comparison. Driven from the patch view's tab bar and revision + /// picker. + export function compare(from?: string) { + selectRevision({ headId: revision.head, baseId: from ?? revision.base }); void scrollToDiff(); } @@ -479,8 +496,7 @@ useShortcuts( { shortcut: "previousCommit", - // The commits column is hidden during a comparison. - enabled: () => commitList.length > 1 && compareFrom === undefined, + enabled: () => commitList.length > 1 && comparedFrom === undefined, run: () => { const current = commitList.findIndex(c => c.id === selectedCommit); selectCommitAt(stepCommitIndex(current, commitList.length, -1)); @@ -488,8 +504,7 @@ }, { shortcut: "nextCommit", - // The commits column is hidden during a comparison. - enabled: () => commitList.length > 1 && compareFrom === undefined, + enabled: () => commitList.length > 1 && comparedFrom === undefined, run: () => { const current = commitList.findIndex(c => c.id === selectedCommit); selectCommitAt(stepCommitIndex(current, commitList.length, 1)); @@ -1000,7 +1015,7 @@ codeComments={diffCodeComments} commentCommit={isRevisionDiff ? head : undefined} header={diffHeader} - overlayLeft={emptyRevision || compareFrom !== undefined + overlayLeft={emptyRevision || comparedFrom !== undefined ? undefined : commitsColumn} {filesHeader} diff --git a/desktop/src/components/ContextMenu.svelte b/desktop/src/components/ContextMenu.svelte index aaf42afac..03d2a4e57 100644 --- a/desktop/src/components/ContextMenu.svelte +++ b/desktop/src/components/ContextMenu.svelte @@ -34,9 +34,11 @@ target?: HTMLElement; onclose: () => void; children: Snippet; + // Raises the menu above a popover it is opened from. + styleZIndex?: string; } - const { x, y, target, onclose, children }: Props = $props(); + const { x, y, target, onclose, children, styleZIndex }: Props = $props(); const getViewport = getScrollViewport(); @@ -214,6 +216,7 @@ use:portal bind:this={menuEl} class="menu" + style:z-index={styleZIndex} role="menu" tabindex="-1" onclick={onMenuClick} diff --git a/desktop/src/components/DropdownListItem.svelte b/desktop/src/components/DropdownListItem.svelte index 32f6613f0..a7e20bd39 100644 --- a/desktop/src/components/DropdownListItem.svelte +++ b/desktop/src/components/DropdownListItem.svelte @@ -5,6 +5,7 @@ children: Snippet; selected: boolean; onclick?: () => void; + oncontextmenu?: (event: MouseEvent) => void; disabled?: boolean; title?: string; styleGap?: string; @@ -14,6 +15,7 @@ const { onclick, + oncontextmenu, children, selected, disabled = false, @@ -76,6 +78,7 @@ return; } onclick(); - }}> + }} + {oncontextmenu}> {@render children()} diff --git a/desktop/src/components/Revision.svelte b/desktop/src/components/Revision.svelte index 1deb7f6d4..a01212b47 100644 --- a/desktop/src/components/Revision.svelte +++ b/desktop/src/components/Revision.svelte @@ -36,6 +36,7 @@ } from "@app/lib/invoke"; import type { PatchActivityData } from "@app/lib/patchTimeline"; import { patchTimeline } from "@app/lib/patchTimeline"; + import { revisionRange } from "@app/lib/revisionCompare"; import { groupCommitsByAuthor, isCommitListDescription, @@ -112,8 +113,11 @@ // Opens the Changes tab on a revision; `compareFrom` diffs its head against // that commit instead of its base. onViewChanges?: (revisionId: string, compareFrom?: string) => void; - // The commit the Changes tab diffs the revision's head against, when it is - // not the base. Cleared here once the diff on screen is another range. + // The commit the Changes tab diffs the revision's head against when it + // opens, instead of its base. + initialCompareFrom?: string; + // Output: the commit the Changes tab diffs the revision's head against, + // while that is not its base. compareFrom?: string; // The revision and commit the patch is marked merged at, if any. merge?: { revision: string; commit: string }; @@ -145,6 +149,7 @@ hiddenCommentSources = [], filesExpanded = $bindable(true), onViewChanges, + initialCompareFrom, compareFrom = $bindable(), merge, chrome, @@ -160,9 +165,10 @@ changes?.setAllFilesCollapsed(collapsed); } - /// Forwarded to the Changes tab so the tab bar can end a comparison. - export function showRevisionChanges() { - changes?.showRevisionChanges(); + /// Forwarded to the Changes tab so the tab bar and revision picker can start + /// or end a comparison. + export function compare(from?: string) { + changes?.compare(from); } /// Forwarded to the Changes tab so the tab bar's stepper can walk the comments @@ -186,21 +192,17 @@ const latestRevisionId = $derived(revisions.at(-1)?.id); const firstRevisionId = $derived(revisions[0]?.id); - // What each revision's compare menu offers, by revision id: its own base and - // the revision before it. Empty when there is no Changes tab to open them in. - const compareMenus = $derived( - Object.fromEntries( - (onViewChanges ? revisions : []).map((rev, index) => [ - rev.id, - { - base: rev.base, - head: rev.head, - previous: revisions[index - 1], - onCompare: (from?: string) => onViewChanges?.(rev.id, from), - }, - ]), - ), - ); + // What a revision's compare menu offers: its own base and the revision + // before it. Nothing when there is no Changes tab to open them in. + function compareMenu(revId: string) { + const range = onViewChanges && revisionRange(revisions, revId); + return ( + range && { + ...range, + onCompare: (from?: string) => onViewChanges?.(revId, from), + } + ); + } const targetBranch = $derived( patchTargetBranch === undefined @@ -1182,7 +1184,7 @@ onOpenChanges={onViewChanges ? () => onViewChanges?.(revId) : undefined} - compare={compareMenus[revId]} + compare={compareMenu(revId)} {expanded} hideAuthor={opts.hideAuthor} bodyExternal @@ -1436,7 +1438,7 @@ onOpenChanges={onViewChanges ? () => onViewChanges?.(revId) : undefined} - compare={compareMenus[revId]} /> + compare={compareMenu(revId)} /> {:else} onViewChanges?.(revId) : undefined} - compare={compareMenus[revId]} /> + compare={compareMenu(revId)} /> {/if} {:else if data.op.type === "review"} {@const opId = data.op.id} @@ -1539,7 +1541,7 @@ firstRevision openedAsDraft={data.openedAsDraft} hideAuthor={opts.hideAuthor} - compare={compareMenus[data.op.id]} /> + compare={compareMenu(data.op.id)} /> {:else if data.kind === "olderRevisions"}
+ import type { RevisionRange } from "@app/lib/revisionCompare"; + import { compareRange, previousOption } from "@app/lib/revisionCompare"; + import { formatOid } from "@app/lib/utils"; + + import ContextMenu from "@app/components/ContextMenu.svelte"; + + interface Props extends RevisionRange { + x: number; + y: number; + target?: HTMLElement; + // Called with the commit to diff `head` against, or with nothing for the + // revision's own base. + onCompare: (from?: string) => void; + onclose: () => void; + } + + const { x, y, target, base, head, previous, onCompare, onclose }: Props = + $props(); + + const prev = $derived(previousOption({ base, head, previous })); + + + + + + + + {#if prev} + + {/if} + diff --git a/desktop/src/components/RevisionCompareMenu.svelte b/desktop/src/components/RevisionCompareMenu.svelte index 760964808..8425d618b 100644 --- a/desktop/src/components/RevisionCompareMenu.svelte +++ b/desktop/src/components/RevisionCompareMenu.svelte @@ -1,4 +1,6 @@