Skip to content

Toggle compact diff view resets current position to the first line #271

Closed

Description

@amakrushin

*The use-case

  1. Open a diff in a large file, where hunks are spread across the file
  2. Switch to the compact diff view (press C), showing only the hunks and 5 lines that surround it
  3. Scroll to the hunk in the middle of the file. .
  4. Switch to full file view (press C)

Expected
View position is not changed, the same hunk in the middle of the file is visible

*Actual
The view position is reset to the top of the file.

Note
Conceptually, the issue is requesting more complex "fold-like" functionality from a simple "compact view" toggle.

Activity

  1. changed the title [-]Toggle compact diff view resets current position to first line[/-] [+]Toggle compact diff view resets current position to the first line[/+] on Jul 16, 2026
  2. umputun commented on Jul 17, 2026

    @umputun
    Owner

    the fix keeps the cursor on the same line across the compact toggle and centers the view on it, so the hunk you were on stays visible with the cursor on it. It does not restore the exact scroll position though.

    reproducing the same on-screen position isn't well-defined between the two views: compact collapses skipped regions into ⋯ N lines ⋯ dividers while full shows every line, so there's no 1:1 mapping, and hunks near the top or bottom clamp to the viewport edge instead of centering.

    so it's "same hunk visible, cursor on the right line" rather than pixel-exact scroll restoration. In many cases the exact position can't be reproduced at all: if you're 20 rows down in full view but compact leaves only 5 rows above the hunk, there's nothing to fill the gap above, so the same screen position can't exist. That's a limit of the two views showing different content, not just a scope call.

  3. umputun commented on Jul 17, 2026

    @umputun
    Owner

    fixed in #274 (adfa202)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions