From 04e7057ffe6b07323fdd605f65bddabfcb041398 Mon Sep 17 00:00:00 2001 From: po3rin Date: Mon, 29 Jul 2024 15:33:26 +0900 Subject: [PATCH] Enabling numContextLines in non-json format (#796) --- web/api.go | 1 + web/server.go | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/web/api.go b/web/api.go index 8d07ae30..4f8c1468 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 75b631fd..89c9fed2 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,