jesseduffield.lazygit/pkg/gui/types
Stefan Haller 3b6568cf9f Preserve the diff scroll and selection when the context size changes
Increasing or decreasing the diff context size (the `{`/`}` keybindings)
re-renders the diff with a different `git diff -U<n>` command. Because the
command key changes, the render reset the main view to the top — losing the
spot the user was reading, which is exactly the spot the context change is
about.

Preserve it instead, reusing the identity-based restore built for the escape
path. This is its sibling consumer: capture the lines around the anchor (the
selection, or the top visible line when there's none) as restore candidates,
and after the re-render land on the nearest one that survived, put back at the
same screen row. Prefer the anchor line itself, falling back outward only when
it didn't survive: a context line vanishes when the context size shrinks,
whereas additions and deletions always survive, so expansion stops at the
first change line in each direction and the candidate list always contains a
survivor. Landing on the nearest survivor keeps scrolling to a minimum, and a
context line that is still in the patch stays put (or stays selected).

This generalizes the shared restore helper to take a prioritized candidate
list (the escape path passes a single candidate). It covers the focused main
view and every side panel's diff, since they all render into the same "main"
view through the same path. A showing selection is re-established on the landed
line; otherwise the view stays in scroll mode.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-08 12:58:59 +02:00
..
common.go Remember how to get back to a repo we entered a submodule from 2026-08-08 11:15:01 +02:00
common_commands.go Don't refresh pull requests when checking out a local branch 2026-04-01 09:13:55 +02:00
context.go Restore the focused main view by patch identity on escape 2026-08-08 12:58:59 +02:00
diff_line_info.go Preserve the diff scroll and selection when the context size changes 2026-08-08 12:58:59 +02:00
keybindings.go Rename Key to Keys in Binding, KeybindingsOpts, and MenuItem 2026-05-25 15:18:18 +02:00
modes.go Add a "Mark commit as base commit for rebase" command 2023-07-31 08:41:41 +02:00
ref_range.go Move the Ref interface from gui/types to models 2025-07-31 15:21:34 +02:00
refresh.go Don't refuse a repo switch during a pure refresh 2026-07-20 17:07:39 +02:00
rendering.go Cleanup: add NewRunPtyTaskWithPrefix funxtion instead of setting Prefix manually 2025-07-02 16:15:19 +02:00
search_state.go Add search history 2023-09-20 08:35:41 +03:00
suggestion.go Set groundwork for better disabled reasons with range select 2024-01-23 13:03:37 +11:00
version_number.go Show popup message with breaking changes on startup 2024-03-12 13:27:14 +01:00
version_number_test.go Show popup message with breaking changes on startup 2024-03-12 13:27:14 +01:00
views.go Copy gocui files into lazygit repo under pkg/gocui 2026-04-30 14:29:08 +02:00