1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2026-06-11 22:30:56 +02:00
Files
lazygit/pkg/commands/patch/patch_line.go
T
Stefan Haller 6bfcab3d89 Fix selection after staging an added line
In some cases, staging an added line could result in the previous deleted line
to become selected, rather than the next added line.
2026-03-19 16:57:53 +01:00

39 lines
814 B
Go

package patch
import "github.com/samber/lo"
type PatchLineKind int
const (
PATCH_HEADER PatchLineKind = iota
HUNK_HEADER
ADDITION
DELETION
CONTEXT
NEWLINE_MESSAGE
)
type PatchLine struct {
Kind PatchLineKind
Content string // something like '+ hello' (note the first character is not removed)
}
func (self *PatchLine) IsChange() bool {
return self.Kind == ADDITION || self.Kind == DELETION
}
func (self *PatchLine) IsAddition() bool {
return self.Kind == ADDITION
}
func (self *PatchLine) IsDeletion() bool {
return self.Kind == DELETION
}
// Returns the number of lines in the given slice that have one of the given kinds
func nLinesWithKind(lines []*PatchLine, kinds []PatchLineKind) int {
return lo.CountBy(lines, func(line *PatchLine) bool {
return lo.Contains(kinds, line.Kind)
})
}