GeezerVison is showing github.com — fix(web,mobile): mixed add/delete review selections no longer show ba… · pingdotgg/t3code@b61af8a
File treeExpand file treeCollapse file tree Open diff view settings mobile/src/features/review
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/review/ReviewCommentComposerSheet.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -100,7 +100,7 @@ export function ReviewCommentComposerSheet(props: ReviewCommentComposerSheetProp | 100 | 100 | ? firstNumber !== null | 101 | 101 | ? gt("Line {line}", { line: firstNumber }) | 102 | 102 | : gt("File comment") | 103 | | - : firstNumber !== null && lastNumber !== null | | 103 | + : firstNumber !== null && lastNumber !== null && firstNumber < lastNumber | 104 | 104 | ? gt("Lines {first}-{last}", { first: firstNumber, last: lastNumber }) | 105 | 105 | : gt("{count, plural, one {{count} lines selected} other {{count} lines selected}}", { | 106 | 106 | count: selectedLines.length, | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/review/reviewCommentSelection.test.ts +35Lines changed: 35 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | clearReviewCommentTarget, | 9 | 9 | completeReviewCommentRange, | 10 | 10 | formatReviewCommentContext, | | 11 | + formatReviewSelectedRangeLabel, | 11 | 12 | getReviewCommentSelection, | 12 | 13 | reviewCommentSelectionScope, | 13 | 14 | selectReviewCommentSelection, | @@ -224,6 +225,40 @@ describe("review comment serialization", () => { | 224 | 225 | }); | 225 | 226 | }); | 226 | 227 |
| | 228 | +describe("review selected range label", () => { | | 229 | + it("falls back to line count when unified endpoints decrease across old and new numbers", () => { | | 230 | + expect( | | 231 | + formatReviewSelectedRangeLabel({ | | 232 | + ...makeTarget(), | | 233 | + lines: [ | | 234 | + { | | 235 | + kind: "line", | | 236 | + id: "line-1", | | 237 | + change: "context", | | 238 | + oldLineNumber: 10, | | 239 | + newLineNumber: 13, | | 240 | + content: "line 10 of the original file", | | 241 | + additionTokenIndex: null, | | 242 | + deletionTokenIndex: null, | | 243 | + comparison: null, | | 244 | + }, | | 245 | + { | | 246 | + kind: "line", | | 247 | + id: "line-2", | | 248 | + change: "delete", | | 249 | + oldLineNumber: 11, | | 250 | + newLineNumber: null, | | 251 | + content: "line 11 of the original file", | | 252 | + additionTokenIndex: null, | | 253 | + deletionTokenIndex: 0, | | 254 | + comparison: null, | | 255 | + }, | | 256 | + ], | | 257 | + }), | | 258 | + ).toBe("2 lines"); | | 259 | + }); | | 260 | +}); | | 261 | + | 227 | 262 | describe("review comment selection store", () => { | 228 | 263 | const changes = { id: "git:branch-range", content: "hash-1" }; | 229 | 264 | const scope = reviewCommentSelectionScope(1, "env:thread", changes)!; | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/review/reviewCommentSelection.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -212,7 +212,7 @@ export function formatReviewSelectedRangeLabel(target: ReviewCommentTarget): str | 212 | 212 | const firstNumber = getReviewUnifiedLineNumber(firstLine); | 213 | 213 | const lastNumber = getReviewUnifiedLineNumber(lastLine); | 214 | 214 |
| 215 | | - if (firstNumber === null || lastNumber === null) { | | 215 | + if (firstNumber === null || lastNumber === null || firstNumber > lastNumber) { | 216 | 216 | return lines.length === 1 ? "line" : `${lines.length} lines`; | 217 | 217 | } | 218 | 218 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/reviewCommentContext.test.ts +45Lines changed: 45 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -85,6 +85,51 @@ describe("review comment context parsing", () => { | 85 | 85 | expect(new Set(ids).size).toBe(ids.length); | 86 | 86 | }); | 87 | 87 |
| | 88 | + it("falls back to a line-count label when mixed diff-side line numbers decrease", () => { | | 89 | + const [fileDiff] = parsePatchFiles( | | 90 | + [ | | 91 | + "diff --git a/notes.txt b/notes.txt", | | 92 | + "--- a/notes.txt", | | 93 | + "+++ b/notes.txt", | | 94 | + "@@ -1,3 +1,6 @@", | | 95 | + "+added A", | | 96 | + "+added B", | | 97 | + "+added C", | | 98 | + " line 1", | | 99 | + " line 2", | | 100 | + " line 3", | | 101 | + "@@ -8,4 +11,3 @@", | | 102 | + " line 8", | | 103 | + " line 9", | | 104 | + " line 10", | | 105 | + "-line 11", | | 106 | + ].join("\n"), | | 107 | + { cacheKeyPrefix: "review-comment-test" }, | | 108 | + )[0]!.files; | | 109 | + | | 110 | + const comment = buildDiffReviewComment({ | | 111 | + id: "comment-inverted", | | 112 | + sectionId: "turn:2", | | 113 | + sectionTitle: "Turn 2", | | 114 | + filePath: "notes.txt", | | 115 | + fileDiff: fileDiff!, | | 116 | + range: { | | 117 | + start: 13, | | 118 | + side: "additions", | | 119 | + end: 11, | | 120 | + endSide: "deletions", | | 121 | + }, | | 122 | + text: "Check this deletion.", | | 123 | + }); | | 124 | + | | 125 | + expect(comment).toEqual( | | 126 | + expect.objectContaining({ | | 127 | + rangeLabel: "2 lines", | | 128 | + diff: "@@ -10,2 +13,1 @@\n line 10\n-line 11", | | 129 | + }), | | 130 | + ); | | 131 | + }); | | 132 | + | 88 | 133 | it("keeps a selection's trailing blank line and whitespace in the rendered excerpt", () => { | 89 | 134 | const fileDiff = parsePatchFiles( | 90 | 135 | [ | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/reviewCommentContext.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -440,7 +440,7 @@ function formatDiffReviewRangeLabel(lines: ReadonlyArray<DiffReviewLine>): strin | 440 | 440 | if (!firstLine || !lastLine) return "line"; | 441 | 441 | const firstNumber = firstLine.newLineNumber ?? firstLine.oldLineNumber; | 442 | 442 | const lastNumber = lastLine.newLineNumber ?? lastLine.oldLineNumber; | 443 | | - if (firstNumber === null || lastNumber === null) { | | 443 | + if (firstNumber === null || lastNumber === null || firstNumber > lastNumber) { | 444 | 444 | return lines.length === 1 ? "line" : `${lines.length} lines`; | 445 | 445 | } | 446 | 446 |
| |
|