@@ -126,13 +126,51 @@ func (self *patchTransformer) transformHunkLines(hunk *Hunk, firstLineIdx int) [
126126 skippedNewlineMessageIndex := - 1
127127 newLines := []* PatchLine {}
128128
129- for i , line := range hunk .bodyLines {
129+ for i := 0 ; i < len (hunk .bodyLines ); i ++ {
130+ line := hunk .bodyLines [i ]
130131 lineIdx := i + firstLineIdx + 1 // plus one for header line
131132 if line .Content == "" {
132133 break
133134 }
134135 isLineSelected := lo .Contains (self .opts .IncludedLineIndices , lineIdx )
135136
137+ // Check for change block (multiple consecutive deletions)
138+ if line .Kind == DELETION {
139+ deletionCount := 0
140+ for j := i ; j < len (hunk .bodyLines ) && hunk .bodyLines [j ].Kind == DELETION ; j ++ {
141+ deletionCount ++
142+ }
143+ if deletionCount > 1 {
144+ selectedDeletions := []* PatchLine {}
145+ pendingContext := []* PatchLine {}
146+ for j := 0 ; j < deletionCount ; j ++ {
147+ delLine := hunk .bodyLines [i + j ]
148+ delLineIdx := i + j + firstLineIdx + 1
149+ if lo .Contains (self .opts .IncludedLineIndices , delLineIdx ) {
150+ selectedDeletions = append (selectedDeletions , delLine )
151+ } else if (delLine .Kind == DELETION && ! self .opts .Reverse ) || (delLine .Kind == ADDITION && self .opts .Reverse ) {
152+ pendingContext = append (pendingContext , & PatchLine {Kind : CONTEXT , Content : " " + delLine .Content [1 :]})
153+ }
154+ }
155+ newLines = append (newLines , selectedDeletions ... )
156+
157+ // Process additions in the block
158+ addIdx := i + deletionCount
159+ for addIdx < len (hunk .bodyLines ) && hunk .bodyLines [addIdx ].Kind == ADDITION {
160+ addLineIdx := addIdx + firstLineIdx + 1
161+ if lo .Contains (self .opts .IncludedLineIndices , addLineIdx ) {
162+ newLines = append (newLines , hunk .bodyLines [addIdx ])
163+ } else {
164+ skippedNewlineMessageIndex = addLineIdx + 1
165+ }
166+ addIdx ++
167+ }
168+ newLines = append (newLines , pendingContext ... )
169+ i = addIdx - 1
170+ continue
171+ }
172+ }
173+
136174 if isLineSelected || (line .Kind == NEWLINE_MESSAGE && skippedNewlineMessageIndex != lineIdx ) || line .Kind == CONTEXT {
137175 newLines = append (newLines , line )
138176 continue
0 commit comments