Skip to content

Commit 04e7057

Browse files
authored
Enabling numContextLines in non-json format (#796)
1 parent 12ce07a commit 04e7057

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

web/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type ApiSearchResult struct {
2828
type LastInput struct {
2929
Query string
3030
Num int
31+
Ctx int
3132

3233
// If set, focus on the search box.
3334
AutoFocus bool

web/server.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,10 @@ func (s *Server) serveSearchErr(r *http.Request) (*ApiSearchResult, error) {
280280
}
281281

282282
numCtxLines := 0
283-
if qvals.Get("format") == "json" {
284-
if ctxLinesStr := qvals.Get("ctx"); ctxLinesStr != "" {
285-
numCtxLines, err = strconv.Atoi(ctxLinesStr)
286-
if err != nil || numCtxLines < 0 || numCtxLines > 10 {
287-
return nil, fmt.Errorf("Number of context lines must be between 0 and 10")
288-
}
283+
if ctxLinesStr := qvals.Get("ctx"); ctxLinesStr != "" {
284+
numCtxLines, err = strconv.Atoi(ctxLinesStr)
285+
if err != nil || numCtxLines < 0 || numCtxLines > 10 {
286+
return nil, fmt.Errorf("Number of context lines must be between 0 and 10")
289287
}
290288
}
291289
sOpts.NumContextLines = numCtxLines
@@ -313,6 +311,7 @@ func (s *Server) serveSearchErr(r *http.Request) (*ApiSearchResult, error) {
313311
Last: LastInput{
314312
Query: queryStr,
315313
Num: num,
314+
Ctx: numCtxLines,
316315
AutoFocus: true,
317316
},
318317
Stats: result.Stats,

0 commit comments

Comments
 (0)