From e427af7ed252edf633ceab890c8dc1bf3b762160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Tue, 6 May 2025 12:28:30 +0200 Subject: [PATCH] Fix bug where adding comment on opposite line would error When adding a comment to the side that doesn't have changes we force the comment to be added to the opposite side. E.g. adding a comment on the right-hand-side for a deletion will force the comment to be added to the left-hand-side. --- src/components/Diff.svelte | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/Diff.svelte b/src/components/Diff.svelte index 75d79c41b..93e1fe888 100644 --- a/src/components/Diff.svelte +++ b/src/components/Diff.svelte @@ -141,32 +141,34 @@ e.preventDefault(); e.stopPropagation(); + const commentAnchor = determineSelectedAnchor(side, line); + selection = { file: filePath(file, side), - start: determineSelectedAnchor(side, line), - end: determineSelectedAnchor(side, line), + start: commentAnchor, + end: commentAnchor, hunkIdx: hunkIdx, lineIdx: lineIdx, codeLocation: { commit: head, path: filePath(file, side), old: - side === "left" + commentAnchor.side === "left" ? { type: "lines", range: { - start: lineNumber(line, "left") as number, - end: (lineNumber(line, "left") as number) + 1, + start: commentAnchor.lineNumber, + end: commentAnchor.lineNumber + 1, }, } : null, new: - side === "right" + commentAnchor.side === "right" ? { type: "lines", range: { - start: lineNumber(line, "right") as number, - end: (lineNumber(line, "right") as number) + 1, + start: commentAnchor.lineNumber, + end: commentAnchor.lineNumber + 1, }, } : null,