sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.85k stars 105 forks source link

feat(file-history): Hide unrelated changes when tracing line evolution #323

Closed sindrets closed 1 year ago

sindrets commented 1 year ago

When tracing line evolution (the -L flag option) we look at the diff patches Git outputs in order to determine what the relevant content is. We then hide the irrelevant content by setting foldmethod=manual in all the diff buffers and creating custom folds derived from the hunks in the git diff.

This seems to work quite well in most cases, and makes it a lot more efficient to review changes with the -L flag, as we no longer need to guess where in the file the change occurred. After all, Git knows this far better than us.

Bonus change: the scroll_view() action now uses the window that currently has the most visible content, to scroll. This makes the scrolling far less jumpy in cases where you have a large deleted hunk. As the cursor cannot be placed inside a region of filler lines, the scroll action would previously just shoot past such regions, something that could be very disorienting. Now it will instead be able to tell that the other window has more visible content, and scroll that instead.

Also fixed the bug where scroll_view() with a negative number would move the cursor up one line every time it was invoked.

weilbith commented 1 year ago

Thank you very much. That is amazing 😊

Example usage for me for a mapping in VimL: <left_hand_side_of_mapping> <cmd>execute 'DiffviewFileHistory -L:' . expand('<cword>') . ':' . expand('%:p')<CR>

The <cword> only takes the word under the cursor. With a treesitter movement to the text object beginning, this works quite fine. A LSP symbol might work better, but quickly gets complex and dirty.