Repository navigation
Expand file tree
/
Copy pathpullRequestDiffDebug.ts
More file actions
64 lines (61 loc) · 2.29 KB
/
Copy pathpullRequestDiffDebug.ts
File metadata and controls
64 lines (61 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import type { RefObject } from "react";
import {
isNativeReviewDiffDrawEvent,
type NativeReviewDiffViewHandle,
type NativeReviewDiffViewProps,
} from "../diffs/nativeReviewDiffSurface";
export function pullRequestDiffInitialPosition(
targetFileId: string | undefined,
focusIndex: number,
): Pick<NativeReviewDiffViewProps, "initialRowIndex" | "initialFileId"> {
// Explicit empty values also clear a previous destination on a reused native view.
return {
initialRowIndex: focusIndex >= 0 ? Math.max(0, focusIndex - 3) : -1,
initialFileId: focusIndex >= 0 ? "" : (targetFileId ?? ""),
};
}
export function handlePullRequestDiffDebugEvent(
event: Parameters<NonNullable<NativeReviewDiffViewProps["onDebug"]>>[0],
input: {
readonly rowCount: number;
readonly targetFileId: string | undefined;
readonly focusIndex: number;
readonly isIos: boolean;
readonly nativeView: RefObject<NativeReviewDiffViewHandle | null>;
readonly jumpStarted: () => boolean;
readonly setJumpStarted: (started: boolean) => void;
readonly onDebug: NonNullable<NativeReviewDiffViewProps["onDebug"]>;
readonly loadMore: () => void;
},
) {
const drawn = isNativeReviewDiffDrawEvent(event.nativeEvent);
// Delivery outcomes and content mounts must reach the bridge even before rows decode.
if (!drawn) input.onDebug(event);
const decoded =
event.nativeEvent.message === "rows-decoded" && event.nativeEvent.rows === input.rowCount;
if (!drawn && !decoded) return;
// Filtering replaces the native row payload asynchronously. Old draw events
// must not consume the file jump or highlight the new payload's row indices.
if (
typeof event.nativeEvent.totalRows === "number" &&
event.nativeEvent.totalRows !== input.rowCount
)
return;
if (drawn) input.onDebug(event);
if (
input.targetFileId &&
!input.jumpStarted() &&
input.nativeView.current &&
(!input.isIos || decoded)
) {
input.setJumpStarted(true);
if (input.focusIndex >= 0) return;
void input.nativeView.current.scrollToFile(input.targetFileId, false).catch(() => {
input.setJumpStarted(false);
});
return;
}
if (!drawn) return;
const lastRow = event.nativeEvent.lastRowIndex;
if (typeof lastRow === "number" && lastRow >= input.rowCount - 40) input.loadMore();
}