diff --git a/src/components/Diff.svelte b/src/components/Diff.svelte index 2183bb88b..dd33742d8 100644 --- a/src/components/Diff.svelte +++ b/src/components/Diff.svelte @@ -326,6 +326,172 @@ } +{#snippet lineDiff(line: Modification, lineIdx: number, hunkIdx: number)} + {@const thread = findLineThread(line)} +
+
{ + if (codeComments?.createComment && !thread) { + selectLine(e, file, "left", line, hunkIdx, lineIdx); + } + }}> + {lineNumber(line, "left")} +
+ +
{ + if (codeComments?.createComment && !thread) { + selectLine(e, file, "right", line, hunkIdx, lineIdx); + } + }}> + {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} + +
+ {#if thread} + {#if thread.root.resolved} + toggleCommentExpand(thread.root.id)} /> + {:else} + toggleCommentExpand(thread.root.id)} /> + {/if} + {/if} +
+
+ + {#if codeComments && thread && !threadExpandedStates[thread.root.id]} +
+
+ {@render commentHeader( + thread.root.location?.path, + rangeAnchorsFromCodeLocation(thread.root.location), + )} + {#if codeComments.changeCommentStatus && roles.isDelegateOrAuthor( codeComments.config.publicKey, codeComments.repoDelegates.map(delegate => delegate.did), thread.root.author.did, )} +
+ {#if thread.root.resolved} +
+ +
+ {:else} +
+ +
+ {/if} +
+ {/if} +
+ { + await codeComments.createComment(body, embeds, thread.root.id); + } + : undefined} + editComment={codeComments.editComment} + canEditComment={partial( + roles.isDelegateOrAuthor, + codeComments.config.publicKey, + codeComments.repoDelegates.map(delegate => delegate.did), + )} /> +
+ {/if} + + {#if codeComments && selection?.hunkIdx === hunkIdx && selection?.lineIdx === lineIdx} +
{ + e.stopPropagation(); + }}> +
+ {@render commentHeader(selection.file, { + start: selection.start, + })} +
+ { + selection = undefined; + }} + focus + placeholder="Leave a comment" + 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; + } + } + }} /> +
+ {/if} +{/snippet} + {#snippet commentHeader(filePath?: string, selectionRange?: SelectionRange)} {#if filePath && selectionRange}
@@ -354,177 +520,8 @@
- {#each hunk.lines as line, lineIdx} - {@const thread = findLineThread(line)} -
-
{ - if (codeComments?.createComment && !thread) { - selectLine(e, file, "left", line, hunkIdx, lineIdx); - } - }}> - {lineNumber(line, "left")} -
- -
{ - if (codeComments?.createComment && !thread) { - selectLine(e, file, "right", line, hunkIdx, lineIdx); - } - }}> - {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} - -
- {#if thread} - {#if thread.root.resolved} - toggleCommentExpand(thread.root.id)} /> - {:else} - toggleCommentExpand(thread.root.id)} /> - {/if} - {/if} -
-
- - {#if codeComments && thread && !threadExpandedStates[thread.root.id]} -
-
- {@render commentHeader( - thread.root.location?.path, - rangeAnchorsFromCodeLocation(thread.root.location), - )} - {#if codeComments.changeCommentStatus && roles.isDelegateOrAuthor( codeComments.config.publicKey, codeComments.repoDelegates.map(delegate => delegate.did), thread.root.author.did, )} -
- {#if thread.root.resolved} -
- -
- {:else} -
- -
- {/if} -
- {/if} -
- { - await codeComments.createComment( - body, - embeds, - thread.root.id, - ); - } - : undefined} - editComment={codeComments.editComment} - canEditComment={partial( - roles.isDelegateOrAuthor, - codeComments.config.publicKey, - codeComments.repoDelegates.map(delegate => delegate.did), - )} /> -
- {/if} - - {#if codeComments && selection && selection.hunkIdx === hunkIdx && selection.lineIdx === lineIdx && selection.codeLocation} -
{ - e.stopPropagation(); - }}> -
- {@render commentHeader(selection.file, { - start: selection.start, - })} -
- { - selection = undefined; - }} - focus - placeholder="Leave a comment" - 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; - } - } - }} /> -
- {/if} + {#each hunk.lines as modification, lineIdx} + {@render lineDiff(modification, lineIdx, hunkIdx)} {/each}
{/each}