[Bug] staging/unstaging a file opens folds
Description
Staging or unstaging a file opens folds.
22a293181f6132d175efbbf279c251d7f01d1e8b is the first 'bad' commit (per git bisect)
Expected behavior
Staging or unstaging a file does not affect folds.
Actual behavior
https://github.com/user-attachments/assets/8e8984e2-3947-40f0-a5c6-c2fdc46035bf
Steps to reproduce
- Use the following 1-line init.lua
vim.pack.add({ "https://github.com/dlyongemallo/diffview-plus.nvim" })
- Got to a repo that has a bunch of git changes
- Start nvim and then
:DiffviewOpen - Move your cursor onto a fold, and then stage or unstage with
sfrom the file panel
Health check
Output of :checkhealth diffview
diffview: ✅
Checking icon provider ~
- No icon provider found (nvim-web-devicons or mini.icons). Icons will be disabled; set `use_icons = false` to silence this.
Checking VCS tools ~
- The plugin requires at least one of the supported VCS tools to be valid.
- ✅ OK Git is up-to-date. (2.56.0)
Log info
Relevant info from :DiffviewLog
############################
### PUT LOG CONTENT HERE ###
############################
Neovim version
12.6
Operating system and version
Fedora 44
Minimal config
22a293181f6132d175efbbf279c251d7f01d1e8b is the first 'bad' commit
@seflue @dlyongemallo Looks like this happens when the cursor is placed in a fold. I updated the reproductions steps to specify that.
I also vibe-coded a PR in my fork here in case that's helpful for reference: https://github.com/nathanzeng/diffview.nvim-fork/pull/1
When the cursor is in a fold this is actually intended. But only to unfold where the cursor is, not to open all folds.
For the way I use diffview plus, I don't think I ever want to unfold. Would you consider supporting that via configuration or as a default?
@nathanzeng @dlyongemallo I opened a PR (#375). The mistake was, that the way, the cursor is handled during browsing through file revisions - especially the folding - was also applied in other cases. The reason why I added it for revision browsing: When I step through revision of a file, I am interested in the development of a certain code section. This is why I want to keep the cursor position (it is a best guess) and when the cursor lands in a fold, I want to see the code immediately. But this behavior doesn't make sense when switching between different files and the bug was the missing constrain.