Feat #1239: Add support to goto hunk locations from commit view #1862
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.
This PR addresses the feature requested on issue #1239
What was implemented?
Two new functionalities on the CommitView buffer. Placing the cursor on a line inside a hunk:
<cr>: Jump file at that specific location in the corresponding commit, i.e., if the cursor is at a line added or at a context line, jump to the commit being viewed. If it is on a deleted line, jump to the parent commit. The view of the commit is done in an hidden read-only buffer and pressingqexits it and put you back on the CommitView.a(the default for the new mapOpenFileInWorktree) tries to open the file the hunk belongs to but in its current state (current worktree).Inspiration and design decisions
The
<cr>behavior mimics what magit does (seemagit-diff-visit-file). Basically, it opens the view of the file in the current CommitView window.I didn't find an equivalent for the other feature on magit so I took some decisions when opening the file in the current worktree:
Initially I opted to implement a more destructive approach, i.e., opening the file closes neogit. However, I realized that you can also open a CommitView while rebasing and you don't want to quit neogit in that location. That was the main motivation to change the approach and be more conservative.
Why
aby default and not<s-cr>as mentioned in the issue? Mainly because<s-cr>is a problematic map in some shells/environments. I haven't a strong position aboutaso any suggestion is welcome (note that it shouldn't collide with other mappings, e.g., we cannot usec).Some implementation notes
Some general notes for the review:
Hunkclass declaration missed some members so I added them in a separate commitneogit_commit_buffersectionjump.luaNote: I run the test locally and I've got a failure:
However, the same failure is reproducible on the master branch so, not related with the changes.