Skip to content

Open folds only when stepping through a file's revisions - #375

Merged
dlyongemallo merged 1 commit into
dlyongemallo:mainfrom
seflue:fix/371-stage-opens-folds
Nov 3, 2026
Merged

dlyongemallo merged 1 commit into
dlyongemallo:mainfrom
seflue:fix/371-stage-opens-folds

Conversation

@seflue

@seflue seflue commented Nov 2, 2026

Copy link
Copy Markdown

Fixes #371

The cursor carry from #314 is meant for browsing the revisions of one
file and nothing else. Opening the fold under the restored cursor also
ran on every other restore, such as after staging or when switching
back to a file. It now runs only when the next entry is another
revision of the same file in the file history, including across a
rename.

A new spec restores a cursor left on a closed fold and checks that the
fold stays closed. The existing file history spec still checks that a
step opens the fold hiding the carried line.

The cursor carry is meant for browsing the revisions of one file and
nothing else. Opening the fold under the restored cursor also ran on
every other restore, such as after staging or when switching back
to a file. It now runs only on a step to another revision.

Fixes dlyongemallo#371
@nathanzeng

Copy link
Copy Markdown

Tried this out on my machine and it fixes #371 for me!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Fold-reveal state can be replayed through rename aliases, and refreshed entries for the same commit can incorrectly open folds without a revision change.

2 open issues
What changed in this PR

This PR narrows cursor-reveal behavior to revision navigation in file history, addressing unwanted fold opening after staging or switching files while preserving cursor carry from #314.

Changes:

  • Gates fold opening on same-file revision steps, including renames.
  • Enables revision-step detection for file-history views.
  • Adds tests for closed-fold restoration and revision-step classification.
File Description
lua/​diffview/​tests/​functional/​cursor_carry_spec.lua Tests fold preservation, cursor reveal, and revision-step detection.
lua/​diffview/​scene/​views/​standard/​standard_view.lua Adds revision-step detection and conditional fold reveal during cursor restoration.
lua/​diffview/​scene/​views/​file_history/​file_history_view.lua Enables revision-step behavior for file history.

Review effort: Balanced

Comment on lines +84 to +87
if not to or to == from then
return false
end
return to.path == from.path or alias ~= nil
Comment on lines +361 to +363
if target.reveal then
reveal_cursor_line(win.id)
end
@dlyongemallo
dlyongemallo merged commit fae72d6 into dlyongemallo:main Nov 3, 2026
8 checks passed
@dlyongemallo

Copy link
Copy Markdown
Owner

Thanks @seflue for the fix!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] staging/unstaging a file opens folds

4 participants