Improve review tool viewed diffs.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user