Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sort get_nav_hunks to handle mixed hunk states #1114

Merged
merged 1 commit into from
Aug 25, 2024

Conversation

iofq
Copy link
Contributor

@iofq iofq commented Aug 24, 2024

Fixes #1113

gitsigns.hunks.find_nearest_hunk's algorithm only works on a sorted list of hunks (because it returns i+1 which it assumes is the next hunk), however get_nav_hunks did not return the list of hunks sorted.

So get_nav_hunks might return a list with lines 16, 29, 24 (staged hunks appended to unstaged); then when jumping from 16 to the next hunk, it would find and jump to 29 when you would expect it to find the hunk at line 24.

I'm not familiar with the codebase, but this does not look like it will break anything else. find_nearest_hunk is only used in nav_hunk.

@@ -573,6 +573,9 @@ local function get_nav_hunks(bufnr, target, greedy)
hunks = hunks_head
end
end
table.sort(hunks, function(h1, h2)
Copy link
Owner

Choose a reason for hiding this comment

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

I think this can moved to below line 571.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, updated

@lewis6991 lewis6991 merged commit 80214a8 into lewis6991:main Aug 25, 2024
6 checks passed
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.

nav_hunk with opts { target = 'all' } does not handle files with mixed hunks
2 participants