@@ -78,7 +78,7 @@ const (
7878type DiffLine struct {
7979 LeftIdx int // line number, 1-based
8080 RightIdx int // line number, 1-based
81- Match int // line number, 1-based
81+ Match int // the diff matched index. -1: no match. 0: plain and no need to match. >0: for add/del, "Lines" slice index of the other side
8282 Type DiffLineType
8383 Content string
8484 Comments issues_model.CommentList // related PR code comments
@@ -206,8 +206,17 @@ type DiffSection struct {
206206 Lines []* DiffLine
207207}
208208
209+ func (diffSection * DiffSection ) GetLine (idx int ) * DiffLine {
210+ if idx <= 0 {
211+ return nil
212+ }
213+ return diffSection .Lines [idx ]
214+ }
215+
209216// GetLine gets a specific line by type (add or del) and file line number
210- func (diffSection * DiffSection ) GetLine (lineType DiffLineType , idx int ) * DiffLine {
217+ // This algorithm is not quite right.
218+ // Actually now we have "Match" field, it is always right, so use it instead in new GetLine
219+ func (diffSection * DiffSection ) getLineLegacy (lineType DiffLineType , idx int ) * DiffLine { //nolint:unused
211220 var (
212221 difference = 0
213222 addCount = 0
@@ -327,10 +336,10 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine, loc
327336 case DiffLineSection :
328337 return getLineContent (diffLine .Content [1 :], locale )
329338 case DiffLineAdd :
330- compareDiffLine := diffSection .GetLine (DiffLineDel , diffLine .RightIdx )
339+ compareDiffLine := diffSection .GetLine (diffLine .Match )
331340 return diffSection .getDiffLineForRender (DiffLineAdd , compareDiffLine , diffLine , locale )
332341 case DiffLineDel :
333- compareDiffLine := diffSection .GetLine (DiffLineAdd , diffLine .LeftIdx )
342+ compareDiffLine := diffSection .GetLine (diffLine .Match )
334343 return diffSection .getDiffLineForRender (DiffLineDel , diffLine , compareDiffLine , locale )
335344 default : // Plain
336345 // TODO: there was an "if" check: `if diffLine.Content >strings.IndexByte(" +-", diffLine.Content[0]) > -1 { ... } else { ... }`
0 commit comments