The best way to control Claude Code, Codex and more from any computer or phone

main
ts 26 lines 1.18 KB
Raw
1 // The changed-files sheet hands its pick to the diff screen beneath it. Picking the file the
2 // screen already shows still jumps back to it, which a route param that did not change could not
3 // say. A screen that is not mounted yet opens at its `path` param instead.
4 type Listener = (path: string) => void;
5 const listeners = new Map<string, Set<Listener>>();
6
7 // The sheet pops to the nearest file diff (`StackActions.popTo`), so only that screen jumps; an
8 // earlier diff of the same pull request further down the stack keeps its file and selection.
9 export function requestPullRequestFileJump(
10 routes: ReadonlyArray<{ readonly key: string; readonly name: string }>,
11 path: string,
12 ): void {
13 const target = routes.findLast((route) => route.name === "PullRequestFile");
14 if (!target) return;
15 for (const listener of listeners.get(target.key) ?? []) listener(path);
16 }
17
18 export function subscribePullRequestFileJump(routeKey: string, listener: Listener): () => void {
19 let scoped = listeners.get(routeKey);
20 if (!scoped) listeners.set(routeKey, (scoped = new Set()));
21 scoped.add(listener);
22 return () => {
23 scoped.delete(listener);
24 if (scoped.size === 0) listeners.delete(routeKey);
25 };
26 }