diff options
author | Giteabot <teabot@gitea.io> | 2024-03-06 17:05:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-06 10:05:41 +0100 |
commit | 9db426ad8c7122633fa3e31a427fd1e65ddad334 (patch) | |
tree | 2616a12717fdc44d1cbbe7ebf0e99a5f3f741f35 /templates | |
parent | a8277cfc8fd6263ce935d14bcbff183c4ecf116d (diff) | |
download | gitea-9db426ad8c7122633fa3e31a427fd1e65ddad334.tar.gz gitea-9db426ad8c7122633fa3e31a427fd1e65ddad334.zip |
Fix wrong line number in code search result (#29260) (#29623)
Backport #29260 by @yp05327
Fix #29136
Before:
The result is a table and all line numbers are all in one row.


After:


~~Updated:~~
~~added `active` class to the target line.~~

Co-authored-by: yp05327 <576951401@qq.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'templates')
-rw-r--r-- | templates/code/searchresults.tmpl | 15 | ||||
-rw-r--r-- | templates/repo/search.tmpl | 15 | ||||
-rw-r--r-- | templates/shared/searchfile.tmpl | 14 |
3 files changed, 16 insertions, 28 deletions
diff --git a/templates/code/searchresults.tmpl b/templates/code/searchresults.tmpl index bb21a5e0dc..08bb12951d 100644 --- a/templates/code/searchresults.tmpl +++ b/templates/code/searchresults.tmpl @@ -22,20 +22,7 @@ <a role="button" class="ui basic tiny button" rel="nofollow" href="{{$repo.Link}}/src/commit/{{$result.CommitID | PathEscape}}/{{.Filename | PathEscapeSegments}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a> </h4> <div class="ui attached table segment"> - <div class="file-body file-code code-view"> - <table> - <tbody> - <tr> - <td class="lines-num"> - {{range .LineNumbers}} - <a href="{{$repo.Link}}/src/commit/{{$result.CommitID | PathEscape}}/{{$result.Filename | PathEscapeSegments}}#L{{.}}"><span>{{.}}</span></a> - {{end}} - </td> - <td class="lines-code chroma"><code class="code-inner">{{.FormattedLines}}</code></td> - </tr> - </tbody> - </table> - </div> + {{template "shared/searchfile" dict "RepoLink" $repo.Link "SearchResult" .}} </div> {{template "shared/searchbottom" dict "root" $ "result" .}} </div> diff --git a/templates/repo/search.tmpl b/templates/repo/search.tmpl index b616b4de32..4aa2cd0171 100644 --- a/templates/repo/search.tmpl +++ b/templates/repo/search.tmpl @@ -44,20 +44,7 @@ <a role="button" class="ui basic tiny button" rel="nofollow" href="{{$.SourcePath}}/src/commit/{{PathEscape $result.CommitID}}/{{PathEscapeSegments .Filename}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a> </h4> <div class="ui attached table segment"> - <div class="file-body file-code code-view"> - <table> - <tbody> - <tr> - <td class="lines-num"> - {{range .LineNumbers}} - <a href="{{$.SourcePath}}/src/commit/{{PathEscape $result.CommitID}}/{{PathEscapeSegments $result.Filename}}#L{{.}}"><span>{{.}}</span></a> - {{end}} - </td> - <td class="lines-code chroma"><code class="code-inner">{{.FormattedLines}}</code></td> - </tr> - </tbody> - </table> - </div> + {{template "shared/searchfile" dict "RepoLink" $.SourcePath "SearchResult" .}} </div> {{template "shared/searchbottom" dict "root" $ "result" .}} </div> diff --git a/templates/shared/searchfile.tmpl b/templates/shared/searchfile.tmpl new file mode 100644 index 0000000000..280584e4d1 --- /dev/null +++ b/templates/shared/searchfile.tmpl @@ -0,0 +1,14 @@ +<div class="file-body file-code code-view"> + <table> + <tbody> + {{range .SearchResult.Lines}} + <tr> + <td class="lines-num"> + <a href="{{$.RepoLink}}/src/commit/{{PathEscape $.SearchResult.CommitID}}/{{PathEscapeSegments $.SearchResult.Filename}}#L{{.Num}}"><span>{{.Num}}</span></a> + </td> + <td class="lines-code chroma"><code class="code-inner">{{.FormattedContent}}</code></td> + </tr> + {{end}} + </tbody> + </table> +</div> |