Files
kandev/apps/web/lib/diff/walkthrough-reveal.ts
2026-08-05 10:57:24 +01:00

21 lines
765 B
TypeScript

import { setPendingCursorPosition, scrollEditorIfMounted } from "@/hooks/use-file-editors";
export type OpenFileFn = (path: string, repo?: string) => void | Promise<void>;
/**
* Open a file in an editor tab and reveal/center the given line — the walkthrough
* "pointer" to the line being explained. Uses the same pending-cursor mechanism
* as LSP go-to-definition: the position is consumed when the editor mounts (new
* tab), and scrolled live if the tab is already open.
*/
export function revealFileAtLine(
openFile: OpenFileFn,
file: string,
line: number,
repo?: string,
): void {
if (line > 0) setPendingCursorPosition(file, line, 1, repo);
void openFile(file, repo);
if (line > 0) scrollEditorIfMounted(file, null, line, 1, { repo });
}