jesseduffield.lazygit/pkg/gui
Stefan Haller cf8e5fd27e Recover diff-line identity by parsing the buffer, behind a swappable seam
The focused main view's click/enter/e/G handlers all need the same thing: given
a rendered diff row, the patch-space line it corresponds to. Until now that came
solely from delta's lazygit-edit:// hyperlinks, which only carry a path and a
single line number — no side. That's lossy: for a deletion the number is the old
line, but the consumers fed it into new-file lookups, and two consecutive
deletions (which share a new-file line number) couldn't be told apart at all.

Replace GetFileAndLineForClickedDiffLine with GetDiffLineInfo, returning the
fuller (file, type, new-line, old-line) record from diff-line-metadata-notes.md.
This is mechanism #1: parse the decolorized view buffer — walk up to the file's
"diff --git" section, reuse patch.Parse on it (splitting multi-file commit diffs
on the "diff --git" boundaries), and read the type and line numbers off the patch
arithmetic. It serves the structure-preserving renderings — no pager, git diff
--color, and delta --color-only without line numbers — with no external
dependency.

To avoid trusting a mis-parse, the parser bails when a hunk's body no longer
matches its header (Patch.IsWellFormed). That's what happens when a pager keeps
the diff/hunk headers but restructures the body: delta's line-number gutters push
the +/- marker off the start of each line, so every body line reads as context.
Such renderings fall through to the next backend rather than yielding a confident
wrong answer. (diff-so-fancy goes further and rewrites the headers too, so it
fails even earlier, on the missing "diff --git".)

GetDiffLineInfo is a seam with swappable backends: the buffer parser first, then
the old hyperlink reader as a fallback for renderings the parser can't handle
(delta's default mode, or delta with line-number gutters). The future #2 OSC
per-cell metadata reader plugs in ahead of both, behind the same record shape.

Wire the consumers to the record per that doc's field mapping:
- dive into staging/patch building lands on the exact patch line, looking a
  deletion up by its old-file line number (PatchLineForOldLineNumber) so the
  two-deletions case resolves correctly;
- `e` edits at the new-file line;
- `G` anchors the PR link on the left (old) side for a deletion, the right (new)
  side otherwise.

The hyperlink fallback can't convey the side, so it reports DiffLineOther, which
the consumers treat as a non-deletion — i.e. exactly today's behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-08 12:58:59 +02:00
..
context WIP FocusedMainViewSnapshot approach 2026-08-08 12:58:59 +02:00
controllers Recover diff-line identity by parsing the buffer, behind a swappable seam 2026-08-08 12:58:59 +02:00
filetree Make the conflict marker size a parameter of our marker matching 2026-08-08 12:43:42 +02:00
mergeconflicts Recognize conflict markers that have no label 2026-08-08 12:43:42 +02:00
modes Make Commit.Hash a getter for an unexported hash field 2025-04-29 14:57:15 +02:00
patch_exploring Recover diff-line identity by parsing the buffer, behind a swappable seam 2026-08-08 12:58:59 +02:00
popup Decouple hiding the working tree state from blocking input 2026-08-05 17:29:20 +02:00
presentation Show a Github PR's combined checks state in branches list and main view 2026-08-02 13:06:21 +02:00
services/custom_commands Remove the RefreshMode field 2026-07-17 12:32:32 +02:00
status Render the app status in a single background render loop 2026-07-17 15:55:01 +02:00
style Modernize all codes 2025-11-15 10:46:23 +01:00
types Recover diff-line identity by parsing the buffer, behind a swappable seam 2026-08-08 12:58:59 +02:00
background.go Read the gui's per-repo pointers on the UI thread in background routines 2026-07-20 17:07:39 +02:00
command_log_panel.go Adapt links 2026-07-31 08:42:51 +02:00
context.go Bump gocui (and tcell) 2025-12-23 16:49:16 +01:00
context_config.go Remove some unused code 2025-07-08 15:14:45 +02:00
controllers.go Extract some functions from CommitFilesController to a new CommitFilesHelper 2026-08-08 12:58:59 +02:00
dummies.go Move NewDummyCommon to pkg/common 2025-05-06 09:43:26 +02:00
editors.go Capture suggestions inputs on the UI thread 2026-07-17 12:35:54 +02:00
extras_panel.go Rename Key to Keys in Binding, KeybindingsOpts, and MenuItem 2026-05-25 15:18:18 +02:00
global_handlers.go Read lines based on scroll position instead of a fixed per-notch delta 2026-07-09 09:32:35 +02:00
gui.go Replace gui.showSelectionInFocusedMainView config with on-demand selection 2026-08-08 12:58:59 +02:00
gui_common.go Add RefreshBlockingInput to buffer keypresses until a refresh has landed 2026-07-22 08:31:11 +02:00
gui_driver.go Keep the destination visible while commits move 2026-07-31 08:37:28 +02:00
information_panel.go Rename ModeStatus.Description to InfoLabel 2025-08-14 17:59:38 +02:00
keybindings.go Fold remaining alt bindings into their main fields 2026-05-25 15:32:47 +02:00
layout.go Don't scroll a view up to fill blank space while its content is loading 2026-08-08 12:58:59 +02:00
main_panels.go Reset other main views' scroll after copying content, not before 2026-08-08 12:58:59 +02:00
menu_panel.go Fold remaining alt bindings into their main fields 2026-05-25 15:32:47 +02:00
options_map.go Cleanup: filter out empty keybindings earlier 2026-05-28 19:26:43 +02:00
pty.go Let a cmd/pty task restore a saved scroll position at its first paint 2026-08-08 12:58:59 +02:00
pty_test.go Prevent stale index.lock files from diffs rendered through a pty on Windows 2026-08-04 06:53:53 +02:00
recent_repos_panel.go Remove unused field gui.IsNewRepo 2024-12-01 10:44:26 +01:00
side_panels.go Assign the transient contexts' initial windows from the side panel config 2026-07-17 12:07:24 +02:00
side_panels_test.go Assign the transient contexts' initial windows from the side panel config 2026-07-17 12:07:24 +02:00
tasks_adapter.go Let a cmd/pty task restore a saved scroll position at its first paint 2026-08-08 12:58:59 +02:00
tasks_adapter_test.go Never hand NewCmdTask a nil reader when a command fails to start 2026-07-23 17:31:26 +02:00
test_mode.go Dump goroutine stacks when the test watchdog fires 2026-07-20 14:26:25 +02:00
test_timeout_norace.go Scale the integration test watchdog up under the race detector 2026-07-20 14:26:25 +02:00
test_timeout_race.go Scale the integration test watchdog up under the race detector 2026-07-20 14:26:25 +02:00
view_helpers.go Let a cmd/pty task restore a saved scroll position at its first paint 2026-08-08 12:58:59 +02:00
views.go Clear tab strips on views that are no longer tabs 2026-06-23 14:15:18 +02:00