Improve review tool viewed diffs.

This commit is contained in:
Greyson Parrelli
2026-08-27 11:47:26 -04:00
parent 1223499369
commit 11ebe07e4f
7 changed files with 746 additions and 80 deletions
+9 -1
View File
@@ -106,16 +106,24 @@ export function isOutdated(c: Comment, anchors: DiffAnchors | null): boolean {
// changeKeyIndex maps "side:line" -> react-diff-view change key for one file's
// hunks, so threads and composers can be attached as line widgets. Built from
// the hunks actually being rendered (expansion included), unlike buildAnchors.
//
// `newOnly` is for the since-viewed diff, whose old side is a snapshot of the
// file held in this browser rather than the base ref. Those line numbers are
// real, but they number a revision no comment was ever written against, so they
// must not be offered as anchors — indexing them would hang a thread meant for
// base line 40 off whatever line 40 of the snapshot happens to be.
export function changeKeyIndex(
hunks: readonly { changes: ChangeData[] }[],
newOnly = false,
): Record<string, string> {
const map: Record<string, string> = {};
for (const hunk of hunks) {
for (const change of hunk.changes) {
const key = getChangeKey(change);
const nl = lineFor(change, 'new');
const ol = lineFor(change, 'old');
if (nl != null) map[`new:${nl}`] = key;
if (newOnly) continue;
const ol = lineFor(change, 'old');
if (ol != null) map[`old:${ol}`] = key;
}
}