@@ -16,14 +16,13 @@ import (
16
16
17
17
// Result a search result to display
18
18
type Result struct {
19
- RepoID int64
20
- Filename string
21
- CommitID string
22
- UpdatedUnix timeutil.TimeStamp
23
- Language string
24
- Color string
25
- LineNumbers []int
26
- FormattedLines template.HTML
19
+ RepoID int64
20
+ Filename string
21
+ CommitID string
22
+ UpdatedUnix timeutil.TimeStamp
23
+ Language string
24
+ Color string
25
+ Lines map [int ]template.HTML
27
26
}
28
27
29
28
type SearchResultLanguages = internal.SearchResultLanguages
@@ -67,12 +66,11 @@ func writeStrings(buf *bytes.Buffer, strs ...string) error {
67
66
func searchResult (result * internal.SearchResult , startIndex , endIndex int ) (* Result , error ) {
68
67
startLineNum := 1 + strings .Count (result .Content [:startIndex ], "\n " )
69
68
70
- var formattedLinesBuffer bytes.Buffer
71
-
72
69
contentLines := strings .SplitAfter (result .Content [startIndex :endIndex ], "\n " )
73
- lineNumbers := make ([] int , len (contentLines ))
70
+ lines := make (map [ int ]template. HTML , len (contentLines ))
74
71
index := startIndex
75
72
for i , line := range contentLines {
73
+ var formattedLinesBuffer bytes.Buffer
76
74
var err error
77
75
if index < result .EndIndex &&
78
76
result .StartIndex < index + len (line ) &&
@@ -93,21 +91,18 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
93
91
return nil , err
94
92
}
95
93
96
- lineNumbers [ i ] = startLineNum + i
94
+ lines [ startLineNum + i ], _ = highlight . Code ( result . Filename , "" , formattedLinesBuffer . String ())
97
95
index += len (line )
98
96
}
99
97
100
- highlighted , _ := highlight .Code (result .Filename , "" , formattedLinesBuffer .String ())
101
-
102
98
return & Result {
103
- RepoID : result .RepoID ,
104
- Filename : result .Filename ,
105
- CommitID : result .CommitID ,
106
- UpdatedUnix : result .UpdatedUnix ,
107
- Language : result .Language ,
108
- Color : result .Color ,
109
- LineNumbers : lineNumbers ,
110
- FormattedLines : highlighted ,
99
+ RepoID : result .RepoID ,
100
+ Filename : result .Filename ,
101
+ CommitID : result .CommitID ,
102
+ UpdatedUnix : result .UpdatedUnix ,
103
+ Language : result .Language ,
104
+ Color : result .Color ,
105
+ Lines : lines ,
111
106
}, nil
112
107
}
113
108
0 commit comments