diff --git a/crates/radicle-tauri/src/commands/repo.rs b/crates/radicle-tauri/src/commands/repo.rs index b01757aea..a740182d9 100644 --- a/crates/radicle-tauri/src/commands/repo.rs +++ b/crates/radicle-tauri/src/commands/repo.rs @@ -105,13 +105,8 @@ pub async fn get_commit_diff( ctx: tauri::State<'_, AppState>, rid: RepoId, sha: git::Oid, - unified: Option, - highlight: Option, ) -> Result { - blocking(ctx, move |ctx| { - ctx.get_commit_diff(rid, sha, unified, highlight) - }) - .await + blocking(ctx, move |ctx| ctx.get_commit_diff(rid, sha)).await } #[tauri::command] diff --git a/crates/radicle-types/bindings/cob/DiffOptions.ts b/crates/radicle-types/bindings/cob/DiffOptions.ts index ef000d073..7c6c53a80 100644 --- a/crates/radicle-types/bindings/cob/DiffOptions.ts +++ b/crates/radicle-types/bindings/cob/DiffOptions.ts @@ -1,8 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type DiffOptions = { - base: string; - head: string; - unified: number | null; - highlight: boolean | null; -}; +export type DiffOptions = { base: string; head: string }; diff --git a/crates/radicle-types/src/cobs/diff.rs b/crates/radicle-types/src/cobs/diff.rs index cb982db56..6f5c282f1 100644 --- a/crates/radicle-types/src/cobs/diff.rs +++ b/crates/radicle-types/src/cobs/diff.rs @@ -10,6 +10,4 @@ pub struct DiffOptions { pub base: git::Oid, #[ts(as = "String")] pub head: git::Oid, - pub unified: Option, - pub highlight: Option, } diff --git a/crates/radicle-types/src/traits/repo.rs b/crates/radicle-types/src/traits/repo.rs index 6606dcf90..fc13ed3e3 100644 --- a/crates/radicle-types/src/traits/repo.rs +++ b/crates/radicle-types/src/traits/repo.rs @@ -19,7 +19,6 @@ use crate::diff::Diff; use crate::error::Error; use crate::repo; use crate::source; -use crate::syntax::{ToPretty, highlighter}; use crate::traits::Profile; #[cfg(windows)] @@ -704,43 +703,30 @@ pub trait Repo: Profile { }) } + /// A manifest of the files a diff touches and their stats — not the lines, + /// which the app gets from `get_diff_text`. Nothing here depends on how much + /// context a hunk carries, so the diff is taken with none: it is thrown away + /// either way, and computing it is work. fn get_diff( &self, rid: identity::RepoId, options: cobs::diff::DiffOptions, ) -> Result { - let unified = options.unified.unwrap_or(5); - let highlight = options.highlight.unwrap_or(true); let profile = self.profile(); let repo = profile.storage.repository(rid)?.backend; - let diff = tree_diff(&repo, Some(options.base), options.head, unified, false)?; + let diff = tree_diff(&repo, Some(options.base), options.head, 0, false)?; let diff = surf::diff::Diff::try_from(diff)?; - if highlight { - return Ok::<_, Error>(diff.pretty(highlighter(), &(), &repo)); - } - Ok::<_, Error>(diff.into()) } - fn get_commit_diff( - &self, - rid: identity::RepoId, - sha: git::Oid, - unified: Option, - highlight: Option, - ) -> Result { - let unified = unified.unwrap_or(5); - let highlight = highlight.unwrap_or(true); + /// As `get_diff`, for a commit against its first parent. + fn get_commit_diff(&self, rid: identity::RepoId, sha: git::Oid) -> Result { let profile = self.profile(); let repo = profile.storage.repository(rid)?.backend; - let diff = tree_diff(&repo, None, sha, unified, false)?; + let diff = tree_diff(&repo, None, sha, 0, false)?; let diff = surf::diff::Diff::try_from(diff)?; - if highlight { - return Ok::<_, Error>(diff.pretty(highlighter(), &(), &repo)); - } - Ok::<_, Error>(diff.into()) } diff --git a/crates/test-http-api/src/api.rs b/crates/test-http-api/src/api.rs index 69f2375a7..abbdde224 100644 --- a/crates/test-http-api/src/api.rs +++ b/crates/test-http-api/src/api.rs @@ -373,20 +373,13 @@ async fn save_diff_handler( struct CommitDiffBody { pub rid: identity::RepoId, pub sha: git::Oid, - pub unified: Option, - pub highlight: Option, } async fn commit_diff_handler( State(ctx): State, - Json(CommitDiffBody { - rid, - sha, - unified, - highlight, - }): Json, + Json(CommitDiffBody { rid, sha }): Json, ) -> impl IntoResponse { - let diff = ctx.get_commit_diff(rid, sha, unified, highlight)?; + let diff = ctx.get_commit_diff(rid, sha)?; Ok::<_, Error>(Json(diff)) } diff --git a/public/index.css b/public/index.css index 029cf649f..4aebea238 100644 --- a/public/index.css +++ b/public/index.css @@ -192,3 +192,43 @@ a { display: none !important; } } + +/* Feeds the app's tokens into `@pierre/diffs`. Its shadow roots read these + custom properties, which inherit across the boundary, so anything hosting a + Pierre diff — `PierreDiff` for a whole revision, `PierreSnippet` for the few + lines a comment is about — carries this class. Instance-specific values + (`--diffs-line-height`, the sticky offsets) stay inline on the element. */ +.global-pierre-surface { + /* Code font and sizing, matching `--txt-code-regular`. The line height is set + on the element itself as a whole-pixel value that mirrors Pierre's + `itemMetrics.lineHeight`, so rendered rows and its model agree. */ + --diffs-font-family: var(--font-family-code); + --diffs-font-size: 0.875rem; + + /* Chrome colours from our design tokens. Syntax token colours still come from + the Shiki theme (github light/dark); these only retint the diff surfaces, + line numbers, and add/delete/modify accents so the frame matches the app + without changing the highlighting look and feel. + + The base *surface* cannot be set here: the Shiki theme writes + `--diffs-light-bg`/`--diffs-dark-bg` directly onto the shadow `:host`, which + beats any value inherited from a light-DOM ancestor. So `--diffs-bg` is + forced to the app's view background in `cardUnsafeCSS` (a higher `@layer`) + instead — every neutral surface and the change-tint mixes derive from it. */ + --diffs-light: var(--color-text-primary); + --diffs-dark: var(--color-text-primary); + /* Line numbers. */ + --diffs-fg-number-override: var(--color-text-tertiary); + /* Add / delete / modify accents feed the line-tint mixes. */ + --diffs-addition-color-override: var(--color-feedback-success-text); + --diffs-deletion-color-override: var(--color-feedback-error-text); + --diffs-modified-color-override: var(--color-text-brand); + /* Mixed into the background of every line a comment refers to. */ + --app-diff-comment-tint: var(--color-surface-brand-secondary); + + /* The app disables selection globally on `html` and opts in per element. + `user-select` inherits across the shadow boundary, so opt the whole Pierre + subtree back in; its own CSS keeps gutters and line numbers unselectable. */ + -webkit-user-select: text; + user-select: text; +} diff --git a/src/components/Changes.svelte b/src/components/Changes.svelte index 0d822560b..c61bb4dfd 100644 --- a/src/components/Changes.svelte +++ b/src/components/Changes.svelte @@ -1,20 +1,27 @@ -
+{#snippet commitsColumn()} + {#if commitList.length > 0} +
+ + {#snippet leftHeader()} +
+ {commitList.length} + {pluralize("commit", commitList.length)} on base + +
+ {/snippet} +
+ {#each commitList as commit} + {@const active = isActiveCommit(commit.id)} + {@const toggle = () => { + if (active) { + // Keep the sole commit selected; there's nothing else to show. + if (commitList.length === 1) return; + selectRevision({ + headId: revision.head, + baseId: revision.base, + }); + } else { + selectRevision({ + headId: commit.id, + baseId: commit.parents[0], + commitId: commit.id, + commit, + }); + } + void scrollToDiff(); + }} + + +
+ + {#if commit.parents.length > 0} + {#await cachedDiffStats(rid, commit.parents[0], commit.id) then commitStats} + + + {commitStats.filesChanged} + +{commitStats.insertions} + -{commitStats.deletions} + + {/await} + {/if} + {#if commit.id === revision.head} + + {/if} + + {#if active && commitList.length > 1} + + + + {/if} +
+ {/each} +
+
+
+ {/if} +{/snippet} + +{#snippet diffHeader()} +
+ {#if chrome} + {@render chrome()} + {/if} +
+{/snippet} + +{#snippet filesHeader()} {#if showRevisionDescription || canEditDescription} {#if editingDescription}
@@ -588,132 +743,67 @@
{/if} {/if} -
-
- {#if commitList.length > 0} - - {#snippet leftHeader()} -
- {commitList.length} - {pluralize("commit", commitList.length)} on base - -
Base
-
- {/snippet} -
- {#each commitList as commit} - {@const active = isActiveCommit(commit.id)} - {@const toggle = () => { - if (active) { - // Keep the sole commit selected; there's nothing else to show. - if (commitList.length === 1) return; - selectRevision({ - headId: revision.head, - baseId: revision.base, - }); - } else { - selectRevision({ - headId: commit.id, - baseId: commit.parents[0], - commitId: commit.id, - commit, - }); - } - void scrollToDiff(); - }} - - -
- - {#if commit.parents.length > 0} - {#await cachedDiffStats(rid, commit.parents[0], commit.id) then stats} - - - {stats.filesChanged} - +{stats.insertions} - -{stats.deletions} - - {/await} - {/if} - {#if commit.id === revision.head} - - {/if} - - {#if active && commitList.length > 1} - - - - {/if} -
- {/each} -
-
+
+
+ {#if diffFailed} + + Failed to load the changes. + + {:else if stats} + {stats.filesChanged} + {pluralize("file", stats.filesChanged)} modified with + + {stats.insertions} + {pluralize("insertion", stats.insertions)} + + and + + {stats.deletions} + {pluralize("deletion", stats.deletions)} + + {:else} + Loading… {/if}
-
- {#await cachedDiffStats(rid, base, head) then stats} -
-
- {stats.filesChanged} - {pluralize("file", stats.filesChanged)} modified with - - {stats.insertions} - {pluralize("insertion", stats.insertions)} - - and - - {stats.deletions} - {pluralize("deletion", stats.deletions)} - -
- {#if stats.filesChanged > 0} - - {/if} -
- {/await} -
- {#if selectedCommitData} -
-
- {selectedCommitData.summary} -
- {#if selectedCommitData.message.trim() !== selectedCommitData.summary.trim()} -
{selectedCommitData.message
-                  .replace(selectedCommitData.summary, "")
-                  .trim()}
- {/if} -
- {/if} - {#await cachedGetDiff(rid, { base, head, unified: 3, highlight: true })} - Loading… - {:then diff} - - {/await} -
-
-
+ +
+ {#if selectedCommitData} +
+
+ {selectedCommitData.summary} +
+ {#if selectedCommitData.message.trim() !== selectedCommitData.summary.trim()} +
{selectedCommitData.message
+              .replace(selectedCommitData.summary, "")
+              .trim()}
+ {/if} +
+ {/if} +
+{/snippet} + + getDiffText(rid, base, head, 3, path)} + {collapsedPaths} + {reviewedPaths} + onToggleReviewed={draftReviewId + ? path => draftReviewStorage.toggleCheckedFile(draftReviewId, path) + : undefined} + {commentCounts} + codeComments={diffCodeComments} + commentCommit={isRevisionDiff ? head : undefined} + header={diffHeader} + overlayLeft={commitsColumn} + {filesHeader} + stickyTop={tabs} /> diff --git a/src/components/Changeset.svelte b/src/components/Changeset.svelte deleted file mode 100644 index 8ec7050ed..000000000 --- a/src/components/Changeset.svelte +++ /dev/null @@ -1,214 +0,0 @@ - - - - -
- {#if stickyFile} - - {/if} -
- - fileDiffPath(file)} - {estimatedItemSize} - autoStartMargin - {onScrollState}> - {#snippet row(file)} -
- setExpanded(file, next)} - {codeComments} - {file} - {head} - {rid} - {draftReviewId} /> -
- {/snippet} -
diff --git a/src/components/Comment.svelte b/src/components/Comment.svelte index e3f1152a2..47e386dd7 100644 --- a/src/components/Comment.svelte +++ b/src/components/Comment.svelte @@ -1,12 +1,8 @@ @@ -143,6 +192,22 @@ transition: opacity 0.1s ease-in-out; will-change: opacity; } + /* Takes no space at rest, rather than fading in place like `.hover-only`: + sitting mid-sentence, a reserved gap between the caption and the timestamp + reads as a hole. */ + .hover-note { + display: none; + align-items: center; + } + .card:is( + :hover, + :has(:focus-visible), + :has(:global([data-expanded])), + .editing + ) + .hover-note { + display: inline-flex; + } .card-body { display: flex; align-items: center; @@ -169,13 +234,15 @@ font: var(--txt-body-m-regular); color: var(--color-text-quaternary); } + .menu { + border: 1px solid var(--color-border-subtle); + border-radius: var(--border-radius-md); + background-color: var(--color-surface-canvas); + padding: 0.25rem; + } -
+
@@ -203,6 +270,9 @@ {#if beforeTimestamp} {@render beforeTimestamp()} {/if} + {#if hoverNote} + {@render hoverNote()} + {/if} {#if timestamp} {utils.formatTimestamp(timestamp)} @@ -219,19 +289,6 @@
{/if}
- {#if id} - - {/if} - {#if editComment} - - - - {/if} - {#if deleteComment && currentUserNid && utils.publicKeyFromDid(author.did) === currentUserNid} - - - - {/if} {#if reactions && reactOnComment} {/if} {@render actions?.()} + {#if menuActions.length > 0} + + {#snippet toggle(onclick)} + + + + {/snippet} + {#snippet popover()} + + {/snippet} + + {/if}
- {#if (body === undefined || body?.trim() === "") && state === "read"} + {#if (body === undefined || body?.trim() === "") && mode === "read"}
No description. @@ -257,7 +339,7 @@
{:else}
- {#if editComment && state !== "read"} + {#if editComment && mode !== "read"}
{ - state = "submit"; + mode = "submit"; try { await editComment(comment, Array.from(embeds.values())); } finally { - state = "read"; + mode = "read"; } }} close={async () => { body = body; await tick(); - state = "read"; + mode = "read"; }} />
{:else} diff --git a/src/components/CommentAnnotation.svelte b/src/components/CommentAnnotation.svelte new file mode 100644 index 000000000..7b0bf4542 --- /dev/null +++ b/src/components/CommentAnnotation.svelte @@ -0,0 +1,189 @@ + + + + +
+ {#each threads as thread (thread.root.id)} + {#if state.comments} + {@const comments = state.comments} + {@const isDraftThread = + comments.draftThreadIds?.includes(thread.root.id) ?? false} + {@const anchor = anchorLabel(thread)} + +
state.onHoverThread(thread.root.id)} + onmouseleave={() => state.onHoverThread(undefined)}> + { + await comments.createComment(body, embeds, thread.root.id); + } + : undefined} + editComment={comments.editComment} + canModifyComment={partial( + roles.isDelegateOrAuthor, + comments.config.publicKey, + comments.repoDelegates.map(delegate => delegate.did), + )} + deleteComment={comments.deleteComment} + changeCommentStatus={isDraftThread + ? undefined + : comments.changeCommentStatus} + canResolve={!isDraftThread && + Boolean(comments.changeCommentStatus) && + (comments.canResolveComment?.(thread.root.id) ?? false)}> + {#snippet hoverNote()} + {#if anchor} + + on + {anchor} + + {/if} + {/snippet} + +
+ {/if} + {/each} + + {#if composer && state.comments && state.commit} + {@const comments = state.comments} + {@const location = locationOf(state.commit, composer)} +
+ state.composerBody, + value => { + state.composerBody = value; + state.onComposerInput(value); + } + } + disallowEmptyBody + rid={comments.rid} + onclose={() => state.onCloseComposer()} + focus + placeholder="Leave a comment" + submitCaption={comments.newCommentCaption} + submitDescription={comments.newCommentDescription} + disableAttachments={comments.disableAttachments} + submit={async (body, embeds) => { + try { + await comments.createComment(body, embeds, undefined, location); + } catch (error) { + console.error("Comment creation failed", error); + } finally { + state.onCloseComposer(); + } + }} + secondarySubmit={comments.addCodeCommentDirect + ? { + caption: comments.addCodeCommentDirectCaption ?? "Just comment", + description: comments.addCodeCommentDirectDescription, + submit: async (body, embeds) => { + try { + await comments.addCodeCommentDirect?.(body, embeds, location); + } catch (error) { + console.error("Comment creation failed", error); + } finally { + state.onCloseComposer(); + } + }, + } + : undefined} /> +
+ {/if} +
diff --git a/src/components/CommentToggleInput.svelte b/src/components/CommentToggleInput.svelte index c6566369f..990db43ee 100644 --- a/src/components/CommentToggleInput.svelte +++ b/src/components/CommentToggleInput.svelte @@ -17,6 +17,9 @@ }; onclose?: () => void; onexpand?: () => void; + // Bindable so a host that outlives this component can keep what was typed — + // the review diff unmounts an off-screen composer. + body?: string; disallowEmptyBody?: boolean; // See `ExtendedTextarea` disableAttachments?: boolean | string; @@ -35,6 +38,7 @@ onexpand, disallowEmptyBody = false, disableAttachments, + body = $bindable(""), }: Props = $props(); /* eslint-enable prefer-const */ @@ -59,6 +63,7 @@ {#if state !== "collapsed"} - import type { CommentOrigin } from "@app/components/Comment.svelte"; - - export interface CodeComments { - changeCommentStatus?: ( - commentId: string, - resolved: boolean, - ) => Promise; - // Whether this thread can be resolved and the current user may do it. - // Decided by the host: the protocol allows the comment author, the review - // author or the revision author, and only the host knows all three. - canResolveComment?: (commentId: string) => boolean; - config: Config; - createComment: ( - body: string, - embeds: Embed[], - replyTo?: string, - location?: CodeLocation, - ) => Promise; - // Defaults to "Comment". - newCommentCaption?: string; - newCommentDescription?: string; - // When provided, the new-code-comment composer shows a second submit option - // in the split-button dropdown that posts a `revision.comment` directly - // (no review wrapping). The primary `createComment` continues to take - // whatever path the host wires (typically: stash into a draft review). - addCodeCommentDirect?: ( - body: string, - embeds: Embed[], - location: CodeLocation, - ) => Promise; - addCodeCommentDirectCaption?: string; - addCodeCommentDirectDescription?: string; - editComment: ( - commentId: string, - body: string, - embeds: Embed[], - ) => Promise; - reactOnComment?: ( - commentId: string, - authors: Author[], - reaction: string, - ) => Promise; - deleteComment?: (commentId: string) => Promise; - // Defaults to `true`. - canReply?: boolean; - // See `ExtendedTextarea`. - disableAttachments?: boolean | string; - // For hosts whose surrounding context already shows the file path. - hideThreadFileHeader?: boolean; - // Unpublished draft roots, which render alongside published threads and so - // have to be told apart. - draftThreadIds?: string[]; - // Root comment id -> where that thread lives, so comments merged from - // several sources stay distinguishable in one diff. - threadOrigins?: Record; - repoDelegates: Author[]; - rid: string; - threads: Thread[]; - } - - - - - - -{#snippet lineDiff(line: Modification, lineIdx: number, hunkIdx: number)} - {@const threads = findLineThreads(line)} - {@const commentSide = line.type === "deletion" ? "left" : "right"} - {@const canComment = Boolean(codeComments?.createComment)} -
- {#if canComment} - - - {/if} -
- {lineNumber(line, "left")} -
- -
- {lineNumber(line, "right")} -
- -
- {#if line.type === "addition"} - + - {:else if line.type === "deletion"} - - - {/if} -
- - {#if line.highlight && line.highlight.items.length > 0} -
- {@html line.highlight.items - .map( - paint => - `${escape(paint.item)}`, - ) - .join("")} -
- {:else if line.line !== ""} -
{line.line}
- {:else} -

- {/if} -
- - {#each threads as thread (thread.root.id)} - {#if codeComments} - {@const isDraftThread = - codeComments.draftThreadIds?.includes(thread.root.id) ?? false} - -
- {#if !codeComments.hideThreadFileHeader} -
- {@render commentHeader( - thread.root.location?.path, - rangeAnchorsFromCodeLocation(thread.root.location), - )} -
- {/if} - { - await codeComments.createComment(body, embeds, thread.root.id); - } - : undefined} - editComment={codeComments.editComment} - canModifyComment={partial( - roles.isDelegateOrAuthor, - codeComments.config.publicKey, - codeComments.repoDelegates.map(delegate => delegate.did), - )} - deleteComment={codeComments.deleteComment} - changeCommentStatus={isDraftThread - ? undefined - : codeComments.changeCommentStatus} - canResolve={!isDraftThread && - Boolean(codeComments.changeCommentStatus) && - (codeComments.canResolveComment?.(thread.root.id) ?? false)} /> -
- {/if} - {/each} - - {#if codeComments && selection?.hunkIdx === hunkIdx && selection?.lineIdx === lineIdx} - -
{ - e.stopPropagation(); - }}> - { - selection = undefined; - }} - focus - placeholder="Leave a comment" - submitCaption={codeComments.newCommentCaption} - submitDescription={codeComments.newCommentDescription} - disableAttachments={codeComments.disableAttachments} - submit={async (body, embeds) => { - if (selection?.codeLocation) { - try { - await codeComments.createComment( - body, - embeds, - undefined, - selection.codeLocation, - ); - } catch (e) { - console.error("Comment creation failed", e); - } finally { - selection = undefined; - } - } - }} - secondarySubmit={codeComments.addCodeCommentDirect - ? { - caption: - codeComments.addCodeCommentDirectCaption ?? "Just comment", - description: codeComments.addCodeCommentDirectDescription, - submit: async (body, embeds) => { - if ( - selection?.codeLocation && - codeComments.addCodeCommentDirect - ) { - try { - await codeComments.addCodeCommentDirect( - body, - embeds, - selection.codeLocation, - ); - } catch (e) { - console.error("Comment creation failed", e); - } finally { - selection = undefined; - } - } - }, - } - : undefined} /> -
- {/if} -{/snippet} - -{#snippet commentHeader(filePath?: string, selectionRange?: SelectionRange)} - {#if filePath && selectionRange} -
- {filePath.split("/").length > 1 ? "…/" : ""}{filePath - .split("/") - .slice(-1)}:{selectionRange.start.side === "left" - ? "L" - : "R"}{selectionRange.start.lineNumber} - {#if selectionRange.end} - -> - {selectionRange.end.side === "left" ? "L" : "R"}{selectionRange.end - .lineNumber} - {/if} -
- {/if} -{/snippet} - -
- {#if file.diff.type === "plain"} - {#each file.diff.hunks as hunk, hunkIdx} -
-
-
-
-
{hunk.header}
-
- -
- {#each hunk.lines as modification, lineIdx} - {@render lineDiff(modification, lineIdx, hunkIdx)} - {/each} -
- {/each} - {/if} -
diff --git a/src/components/DiffFileHeader.svelte b/src/components/DiffFileHeader.svelte index 2eea4fd2b..8e3c3c4f6 100644 --- a/src/components/DiffFileHeader.svelte +++ b/src/components/DiffFileHeader.svelte @@ -102,6 +102,13 @@ white-space: nowrap; flex-shrink: 0; } + .comments { + display: inline-flex; + align-items: center; + gap: 0.25rem; + flex-shrink: 0; + color: var(--color-text-secondary); + } .add { color: var(--color-feedback-success-text); } @@ -147,6 +154,35 @@ {/if} + {#if state.unresolvedComments > 0} + + + {state.unresolvedComments} + + {/if} + {#if state.resolvedComments > 0} + + + {state.resolvedComments} + + {/if} + + {#if state.reviewed !== undefined} + + {/if} + {#if text !== undefined} {/if} diff --git a/src/components/DiffOptionsButton.svelte b/src/components/DiffOptionsButton.svelte index e5a00a4a9..fb05fd82a 100644 --- a/src/components/DiffOptionsButton.svelte +++ b/src/components/DiffOptionsButton.svelte @@ -5,6 +5,17 @@ import Icon from "@app/components/Icon.svelte"; + type DiffStyleOption = { + value: DiffOptions["diffStyle"]; + icon: ComponentProps["name"]; + title: string; + }; + + const diffStyleOptions: DiffStyleOption[] = [ + { value: "unified", icon: "diff-unified", title: "Unified" }, + { value: "split", icon: "diff-split", title: "Split" }, + ]; + type IndicatorOption = { value: DiffOptions["indicators"]; icon: ComponentProps["name"]; @@ -53,7 +64,9 @@ display: flex; flex-direction: column; gap: 0.75rem; - width: 20rem; + /* Wide enough to keep every label on one line next to its buttons; the + widest pairing is "Word diff" against its four options. */ + width: 23rem; padding: 0.75rem 1rem; border: 1px solid var(--color-border-subtle); border-radius: var(--border-radius-md); @@ -109,6 +122,23 @@ {#snippet popover()}
+
+ Diff style +
+ {#each diffStyleOptions as option, index} + + {/each} +
+
Word wrap {@render boolSwitch( diff --git a/src/components/DraftReviewBar.svelte b/src/components/DraftReviewBar.svelte index d2aff7f7e..edac7af1c 100644 --- a/src/components/DraftReviewBar.svelte +++ b/src/components/DraftReviewBar.svelte @@ -8,6 +8,7 @@ import type { DraftReview } from "@app/lib/draftReviewStorage"; import { draftReviewStorage } from "@app/lib/draftReviewStorage"; + import { formatAnchor } from "@app/lib/pierreComments"; import Button from "@app/components/Button.svelte"; import Icon from "@app/components/Icon.svelte"; @@ -177,17 +178,7 @@ } function formatLocation(location: CodeLocation | undefined): string { - if (!location) return ""; - const range = location.new ?? location.old; - if (!range) return location.path; - if (range.type === "lines") { - const start = range.range.start + 1; - const end = range.range.end; - return start === end - ? `${location.path}:${start}` - : `${location.path}:${start}-${end}`; - } - return `${location.path}:${range.line + 1}`; + return location ? formatAnchor(location) : ""; } const verdictLabel = $derived( diff --git a/src/components/FileDiff.svelte b/src/components/FileDiff.svelte deleted file mode 100644 index 8af5a6f15..000000000 --- a/src/components/FileDiff.svelte +++ /dev/null @@ -1,266 +0,0 @@ - - - - -{#snippet emptyPlaceholder()} -
- Empty file -
-{/snippet} - - - {#snippet leftHeader()} - {#if file.status === "moved" || file.status === "copied"} - - - → - - - {:else} - - {/if} - - {#if file.status === "added"} - Added - {:else if file.status === "deleted"} - Deleted - {:else if file.status === "moved"} - Moved - {:else if file.status === "copied"} - Copied - {/if} - {/snippet} - - {#snippet rightHeader()} - {#if file.diff.type === "plain" && file.diff.hunks.length > 0} -
- - +{file.diff.stats.additions} - - - -{file.diff.stats.deletions} - -
- {/if} - {#if commentsOfThisFile && commentsOfThisFile.threads.length > 0} - {#if unresolvedThreads > 0} -
- - {unresolvedThreads} -
- {/if} - {#if resolvedThreads > 0} -
- - {resolvedThreads} -
- {/if} - {/if} - {#if draftReviewId} - - {/if} - {/snippet} - - {#if file.diff.type === "plain"} - {#if file.diff.hunks.length > 0} - - {:else} - {@render emptyPlaceholder()} - {/if} - {:else if file.diff.type === "binary"} - {#await loadBinaryEmbed(file)} -
- Loading binary… -
- {:then embed} - {#if embed.mimeType?.startsWith("image/")} -
- {fileDiffPath(file)} -
- {:else} -
- Binary file -
- {/if} - {:catch} -
- Binary file -
- {/await} - {:else} - {@render emptyPlaceholder()} - {/if} -
diff --git a/src/components/PierreDiff.svelte b/src/components/PierreDiff.svelte index a7540b7fb..38f5d9a52 100644 --- a/src/components/PierreDiff.svelte +++ b/src/components/PierreDiff.svelte @@ -1,58 +1,51 @@ - -
+ class="pierre-diff global-pierre-surface" + style:--diffs-line-height="{lineHeightPx}px" + style:--app-diff-left-inset={overlayLeft + ? `calc(${overlayLeftWidth} + 1.5rem)` + : undefined} + style:--app-sticky-top="{stickyTopHeight}px" + style:--app-diff-reserve={reserveOnHeader ? `${reserveHeight}px` : undefined}> {#if header}
{@render header()}
{/if} + {#if stickyTop} +
+
+ {@render stickyTop()} +
+
+ {/if} + {#if overlayLeft} +
+
+ {@render overlayLeft()} +
+
+ {/if} + {#if filesHeader} +
+
+ {@render filesHeader()} +
+
+ {/if}
diff --git a/src/components/PierreSnippet.svelte b/src/components/PierreSnippet.svelte new file mode 100644 index 000000000..175934020 --- /dev/null +++ b/src/components/PierreSnippet.svelte @@ -0,0 +1,291 @@ + + + + +{#if error} +
{error}
+{/if} +
+
diff --git a/src/components/ReviewCodeThread.svelte b/src/components/ReviewCodeThread.svelte index b57e2f17e..135018a3c 100644 --- a/src/components/ReviewCodeThread.svelte +++ b/src/components/ReviewCodeThread.svelte @@ -1,18 +1,16 @@ @@ -190,10 +93,6 @@ border-radius: var(--border-radius-md); overflow: hidden; } - .wrapper :global(.container) { - padding-top: 0; - padding-bottom: 0; - } .file-header { display: flex; align-items: center; @@ -214,90 +113,45 @@ .thread + .thread { border-top: 1px solid var(--color-border-subtle); } - .hunk-toolbar { - display: flex; - justify-content: flex-end; - padding: 0.25rem 0.5rem 0; - } - .toggle { - display: inline-flex; - align-items: center; - justify-content: center; - background: none; - border: none; - padding: 0.125rem; - border-radius: var(--border-radius-sm); - cursor: pointer; - color: var(--color-text-tertiary); - } - .toggle:hover, - .toggle:focus-visible { - color: var(--color-text-primary); - background-color: var(--color-surface-subtle); - } .fallback { font: var(--txt-body-m-regular); color: var(--color-text-secondary); } -{#await cachedGetDiff(rid, { base, head, unified: 3, highlight: true })} -
Loading code…
-{:then diff} - {@const location0 = threads[0]?.root.location} - {#if path && location0} - {@const file = findFileDiff(diff, location0)} - {#if file} -
-
- {path} -
- {#each threads as thread (thread.root.id)} - {@const location = thread.root.location} - {#if location} - {@const hunk = findHunk(file, location)} - {#if hunk} - {@const codeRange = location.new ?? location.old} - {@const targetSide = location.new ? "new" : "old"} - {@const clampedHunk = - codeRange && codeRange.type === "lines" - ? sliceHunkAroundRange(hunk, codeRange.range, targetSide, 3) - : hunk} - {@const isClamped = clampedHunk !== hunk} - {@const expanded = expandedThreads[thread.root.id] ?? false} - {@const displayHunk = expanded ? hunk : clampedHunk} -
- {#if isClamped} -
- -
- {/if} - -
- {:else} -
Code unavailable for {location.path}
- {/if} - {/if} - {/each} +{#if path} + + {#await cachedGetDiffText(rid, base, head, 3, path)} +
Loading code…
+ {:then filePatch} +
+
+ {path}
- {:else} -
Code unavailable for {path}
- {/if} - {/if} -{/await} + {#each threads as thread (thread.root.id)} + {@const location = thread.root.location} + {#if location} + {@const range = rangeOf(location)} + {@const slice = + range && + sliceForRange(filePatch, range.side, range.start, range.end)} + {#if slice} +
+ +
+ {:else} +
Code unavailable for {location.path}
+ {/if} + {/if} + {/each} +
+ {/await} +{/if} diff --git a/src/components/ReviewPage.svelte b/src/components/ReviewPage.svelte index dcbddd79f..e634d2f7f 100644 --- a/src/components/ReviewPage.svelte +++ b/src/components/ReviewPage.svelte @@ -1,6 +1,5 @@