diff --git a/web/api.go b/web/api.go index 8d07ae307..4f8c1468c 100644 --- a/web/api.go +++ b/web/api.go @@ -28,6 +28,7 @@ type ApiSearchResult struct { type LastInput struct { Query string Num int + Ctx int // If set, focus on the search box. AutoFocus bool diff --git a/web/server.go b/web/server.go index 75b631fd2..89c9fed27 100644 --- a/web/server.go +++ b/web/server.go @@ -280,12 +280,10 @@ func (s *Server) serveSearchErr(r *http.Request) (*ApiSearchResult, error) { } numCtxLines := 0 - if qvals.Get("format") == "json" { - if ctxLinesStr := qvals.Get("ctx"); ctxLinesStr != "" { - numCtxLines, err = strconv.Atoi(ctxLinesStr) - if err != nil || numCtxLines < 0 || numCtxLines > 10 { - return nil, fmt.Errorf("Number of context lines must be between 0 and 10") - } + if ctxLinesStr := qvals.Get("ctx"); ctxLinesStr != "" { + numCtxLines, err = strconv.Atoi(ctxLinesStr) + if err != nil || numCtxLines < 0 || numCtxLines > 10 { + return nil, fmt.Errorf("Number of context lines must be between 0 and 10") } } sOpts.NumContextLines = numCtxLines @@ -313,6 +311,7 @@ func (s *Server) serveSearchErr(r *http.Request) (*ApiSearchResult, error) { Last: LastInput{ Query: queryStr, Num: num, + Ctx: numCtxLines, AutoFocus: true, }, Stats: result.Stats,