mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-06 05:57:38 -04:00
To act on the line the user is pointing at in a diff view — to stage it, to open it in an editor, to keep the cursor on it while the diff is regenerated — we need to know which file it belongs to and where it sits in that file. Only the diff the view was rendered from knows that, and by the time it's on screen all we have is text. So parse it back: the view's contents are (usually) a unified diff, and running them through the patch parser recovers each row's file, kind and line numbers. "Usually" is why this goes behind a seam, and why it answers "I don't know" rather than guessing: a diff renderer is free to restructure what it prints, and a wrong answer here means acting on the wrong line of the wrong file. Parsing a whole buffer is a separate entry point from parsing a single line, because a caller resolving every row of a large diff must not re-parse a file's section once per line of it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>