@@ -78,7 +78,7 @@ const (
78
78
type DiffLine struct {
79
79
LeftIdx int // line number, 1-based
80
80
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
82
82
Type DiffLineType
83
83
Content string
84
84
Comments issues_model.CommentList // related PR code comments
@@ -206,8 +206,17 @@ type DiffSection struct {
206
206
Lines []* DiffLine
207
207
}
208
208
209
+ func (diffSection * DiffSection ) GetLine (idx int ) * DiffLine {
210
+ if idx <= 0 {
211
+ return nil
212
+ }
213
+ return diffSection .Lines [idx ]
214
+ }
215
+
209
216
// 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
211
220
var (
212
221
difference = 0
213
222
addCount = 0
@@ -327,10 +336,10 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine, loc
327
336
case DiffLineSection :
328
337
return getLineContent (diffLine .Content [1 :], locale )
329
338
case DiffLineAdd :
330
- compareDiffLine := diffSection .GetLine (DiffLineDel , diffLine .RightIdx )
339
+ compareDiffLine := diffSection .GetLine (diffLine .Match )
331
340
return diffSection .getDiffLineForRender (DiffLineAdd , compareDiffLine , diffLine , locale )
332
341
case DiffLineDel :
333
- compareDiffLine := diffSection .GetLine (DiffLineAdd , diffLine .LeftIdx )
342
+ compareDiffLine := diffSection .GetLine (diffLine .Match )
334
343
return diffSection .getDiffLineForRender (DiffLineDel , diffLine , compareDiffLine , locale )
335
344
default : // Plain
336
345
// TODO: there was an "if" check: `if diffLine.Content >strings.IndexByte(" +-", diffLine.Content[0]) > -1 { ... } else { ... }`
0 commit comments