@@ -312,25 +312,25 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine, loc
312312 case DiffLineAdd :
313313 compareDiffLine = diffSection .GetLine (DiffLineDel , diffLine .RightIdx )
314314 if compareDiffLine == nil {
315- highlightedLine := diffSection .file .HighlightedNewLines [diffLine .RightIdx - 1 ]
315+ highlightedLine := diffSection .file .highlightedNewLines [diffLine .RightIdx - 1 ]
316316 return DiffInlineWithUnicodeEscape (template .HTML (highlightedLine ), locale )
317317 }
318- diff1 = diffSection .file .HighlightedOldLines [compareDiffLine .LeftIdx - 1 ]
319- diff2 = diffSection .file .HighlightedNewLines [diffLine .RightIdx - 1 ]
318+ diff1 = diffSection .file .highlightedOldLines [compareDiffLine .LeftIdx - 1 ]
319+ diff2 = diffSection .file .highlightedNewLines [diffLine .RightIdx - 1 ]
320320 case DiffLineDel :
321321 compareDiffLine = diffSection .GetLine (DiffLineAdd , diffLine .LeftIdx )
322322 if compareDiffLine == nil {
323- highlightedLine := diffSection .file .HighlightedOldLines [diffLine .LeftIdx - 1 ]
323+ highlightedLine := diffSection .file .highlightedOldLines [diffLine .LeftIdx - 1 ]
324324 return DiffInlineWithUnicodeEscape (template .HTML (highlightedLine ), locale )
325325 }
326- diff1 = diffSection .file .HighlightedOldLines [diffLine .LeftIdx - 1 ]
327- diff2 = diffSection .file .HighlightedNewLines [compareDiffLine .RightIdx - 1 ]
326+ diff1 = diffSection .file .highlightedOldLines [diffLine .LeftIdx - 1 ]
327+ diff2 = diffSection .file .highlightedNewLines [compareDiffLine .RightIdx - 1 ]
328328 default :
329329 if strings .IndexByte (" +-" , diffLine .Content [0 ]) > - 1 {
330- highlightedContent := diffSection .file .HighlightedNewLines [diffLine .RightIdx - 1 ]
330+ highlightedContent := diffSection .file .highlightedNewLines [diffLine .RightIdx - 1 ]
331331 return DiffInlineWithUnicodeEscape (template .HTML (highlightedContent ), locale )
332332 }
333- highlightedContent := diffSection .file .HighlightedOldLines [diffLine .LeftIdx - 1 ]
333+ highlightedContent := diffSection .file .highlightedOldLines [diffLine .LeftIdx - 1 ]
334334 return DiffInlineWithUnicodeEscape (template .HTML (highlightedContent ), locale )
335335 }
336336
@@ -371,8 +371,8 @@ type DiffFile struct {
371371 IsSubmodule bool // if IsSubmodule==true, then there must be a SubmoduleDiffInfo
372372 SubmoduleDiffInfo * SubmoduleDiffInfo
373373
374- HighlightedOldLines []string
375- HighlightedNewLines []string
374+ highlightedOldLines []string
375+ highlightedNewLines []string
376376}
377377
378378// GetType returns type of diff file.
@@ -1226,7 +1226,7 @@ func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, fi
12261226 }
12271227 diffFile .IsGenerated = isGenerated .Value ()
12281228
1229- highlightCode (commit , beforeCommit , diffFile )
1229+ diffFile . highlightedOldLines , diffFile . highlightedNewLines = highlightCode (commit , beforeCommit , diffFile )
12301230
12311231 tailSection := diffFile .GetTailSection (gitRepo , beforeCommit , commit )
12321232 if tailSection != nil {
@@ -1248,17 +1248,19 @@ func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, fi
12481248 return diff , nil
12491249}
12501250
1251- func highlightCode (commit * git.Commit , beforeCommit * git.Commit , diffFile * DiffFile ) {
1251+ func highlightCode (commit * git.Commit , beforeCommit * git.Commit , diffFile * DiffFile ) ([]string , []string ) {
1252+ var oldLines []string
1253+ var newLines []string
1254+
12521255 if beforeCommit != nil {
12531256 oldBlob , err := beforeCommit .GetBlobByPath (diffFile .Name )
12541257 if err == nil {
12551258 oldContent , _ := oldBlob .GetBlobContent (oldBlob .Size ())
12561259 highlightedOldContent , _ := highlight .Code (diffFile .Name , diffFile .Language , oldContent )
12571260
1258- oldLines := strings .Split (string (highlightedOldContent ), "\n " )
1259- diffFile .HighlightedOldLines = make ([]string , len (oldLines ))
1260- for i , line := range oldLines {
1261- diffFile .HighlightedOldLines [i ] = line
1261+ oldLines = strings .Split (string (highlightedOldContent ), "\n " )
1262+ for _ , line := range oldLines {
1263+ oldLines = append (oldLines , line )
12621264 }
12631265 }
12641266 }
@@ -1268,12 +1270,13 @@ func highlightCode(commit *git.Commit, beforeCommit *git.Commit, diffFile *DiffF
12681270 newContent , _ := newBlob .GetBlobContent (newBlob .Size ())
12691271 highlightedNewContent , _ := highlight .Code (diffFile .Name , diffFile .Language , newContent )
12701272
1271- newLines := strings .Split (string (highlightedNewContent ), "\n " )
1272- diffFile .HighlightedNewLines = make ([]string , len (newLines ))
1273- for i , line := range newLines {
1274- diffFile .HighlightedNewLines [i ] = line
1273+ newLines = strings .Split (string (highlightedNewContent ), "\n " )
1274+ for _ , line := range newLines {
1275+ newLines = append (newLines , line )
12751276 }
12761277 }
1278+
1279+ return oldLines , newLines
12771280}
12781281
12791282type PullDiffStats struct {
0 commit comments