mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-01 00:54:58 +02:00
Press enter in main view of files/commitFiles to enter staging/patch-building
This was already possible, but only when a file was selected, and it woudln't always land on the right line when a pager was used. Now it's also possible to do this for directories, and it jumps to the right line. At the moment this is a hack that relies on delta's hyperlinks, so it only works on lines that have hyperlinks (added and context). The implementation is very hacky for other reasons too (e.g. the addition of the weirdly named ClickedViewRealLineIdx to OnFocusOpts).
This commit is contained in:
@ -104,6 +104,38 @@ func (self *Patch) LineNumberOfLine(idx int) int {
|
||||
return hunk.newStart + offset
|
||||
}
|
||||
|
||||
// Takes a line number in the new file and returns the line index in the patch.
|
||||
// This is the opposite of LineNumberOfLine.
|
||||
// If the line number is not contained in any of the hunks, it returns the
|
||||
// closest position.
|
||||
func (self *Patch) PatchLineForLineNumber(lineNumber int) int {
|
||||
if len(self.hunks) == 0 {
|
||||
return len(self.header)
|
||||
}
|
||||
|
||||
for hunkIdx, hunk := range self.hunks {
|
||||
if lineNumber <= hunk.newStart {
|
||||
return self.HunkStartIdx(hunkIdx)
|
||||
}
|
||||
|
||||
if lineNumber < hunk.newStart+hunk.newLength() {
|
||||
lines := hunk.bodyLines
|
||||
offset := lineNumber - hunk.newStart
|
||||
for i, line := range lines {
|
||||
if offset == 0 {
|
||||
return self.HunkStartIdx(hunkIdx) + i + 1
|
||||
}
|
||||
|
||||
if line.Kind == ADDITION || line.Kind == CONTEXT {
|
||||
offset--
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self.LineCount() - 1
|
||||
}
|
||||
|
||||
// Returns hunk index containing the line at the given patch line index
|
||||
func (self *Patch) HunkContainingLine(idx int) int {
|
||||
for hunkIdx, hunk := range self.hunks {
|
||||
|
Reference in New Issue
Block a user