mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
fix out of range error
This commit is contained in:
@ -137,12 +137,17 @@ func ModifiedPatchForLines(log *logrus.Entry, filename string, diffText string,
|
||||
}
|
||||
|
||||
// I want to know, given a hunk, what line a given index is on
|
||||
func (hunk *PatchHunk) LineNumberOfLine(idx int) int {
|
||||
lines := hunk.bodyLines[0 : idx-hunk.FirstLineIdx-1]
|
||||
func (hunk *PatchHunk) LineNumberOfLine(idx int) (int, error) {
|
||||
n := idx - hunk.FirstLineIdx - 1
|
||||
if n < 0 || len(hunk.bodyLines) <= n {
|
||||
return -1, fmt.Errorf("line index out of range")
|
||||
}
|
||||
|
||||
lines := hunk.bodyLines[0:n]
|
||||
|
||||
offset := nLinesWithPrefix(lines, []string{"+", " "})
|
||||
|
||||
return hunk.newStart + offset
|
||||
return hunk.newStart + offset, nil
|
||||
}
|
||||
|
||||
func nLinesWithPrefix(lines []string, chars []string) int {
|
||||
|
Reference in New Issue
Block a user