fix(preview): make preview_hunk and preview_hunk_inline show consistent diff - #1480
Open
letstakeawalk wants to merge 4 commits into
Open
fix(preview): make preview_hunk and preview_hunk_inline show consistent diff#1480letstakeawalk wants to merge 4 commits into
preview_hunk and preview_hunk_inline show consistent diff#1480letstakeawalk wants to merge 4 commits into
Conversation
- Accept greedy parameter instead of hardcoding true
- Use `get_hunks` and `get_cursor_hunk` directly instead of `get_hunk` - Return hunk index and total count for use by callers
- Make `preview_hunk` async to support greedy diff re-computation - Use `get_hunk_with_staged` for consistent hunk resolution - Replace local `noautocmd` wrapper with `Util.noautocmd`
- Add `opts` and `callback` parameter docs for `preview_hunk` - Add `opts` parameter docs for `preview_hunk_inline`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
preview_hunkwas the only hunk command that did not support greedy. When navigating withnav_hunk(which defaults togreedy=true) anddiff_opts.linematchenabled,preview_hunkshows linematch-split hunks individually whilepreview_hunk_inlinecorrectly shows the merged diff. This causes inconsistent preview behavior between the two commands.Steps to reproduce
Given a file with the following content committed:
Then changed to:
Before
nav_hunk("next")→ cursor at line 2preview_hunk()Note: preview title shows
Hunk 1 of 7preview_hunk_inline()Note the difference
nav_hunk("next")→ cursor at line 7preview_hunk()preview_hunk_inlineshows the diff as expected according to greedynav_hunk, butpreview_hunkonly shows the individual linematch-split hunk.After (with this PR)
preview_hunknow shows the same merged result aspreview_hunk_inline, with the correct greedy hunk count in the title (Hunk 1 of 2andHunk 2 of 2).Changes
get_hunk_with_stagedto return hunk index and countpreview_hunk— make it async, useget_hunk_with_stagedand
Util.noautocmdpreview_hunk_inline— parameterize the hardcodedtruenav_hunkto both preview functions