mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Toggle only added/deleted lines in patch building view
This improves the experience when selecting a hunk generously with the mouse, by dragging over it including some context lines above and below. Previously we would consider the "moving end" of the selection range for whether things need to be added or removed, but this doesn't make sense if it's a context line. Now we consider the first actual change line that is included in the range.
This commit is contained in:
@ -282,6 +282,20 @@ func (s *State) SelectedPatchRange() (int, int) {
|
||||
return s.patchLineIndices[start], s.patchLineIndices[end]
|
||||
}
|
||||
|
||||
// Returns the line indices of the selected patch range that are changes (i.e. additions or deletions)
|
||||
func (s *State) ChangeLinesInSelectedPatchRange() []int {
|
||||
viewStart, viewEnd := s.SelectedViewRange()
|
||||
patchStart, patchEnd := s.patchLineIndices[viewStart], s.patchLineIndices[viewEnd]
|
||||
lines := s.patch.Lines()
|
||||
indices := []int{}
|
||||
for i := patchStart; i <= patchEnd; i++ {
|
||||
if lines[i].IsChange() {
|
||||
indices = append(indices, i)
|
||||
}
|
||||
}
|
||||
return indices
|
||||
}
|
||||
|
||||
func (s *State) CurrentLineNumber() int {
|
||||
return s.patch.LineNumberOfLine(s.patchLineIndices[s.selectedLineIdx])
|
||||
}
|
||||
|
Reference in New Issue
Block a user