Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong line number in code search result #29260

Merged
merged 8 commits into from
Mar 6, 2024

Conversation

yp05327
Copy link
Contributor

@yp05327 yp05327 commented Feb 19, 2024

Fix #29136

Before:
The result is a table and all line numbers are all in one row.
image
image

After:
image
image

Updated:
added active class to the target line.
image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 19, 2024
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 19, 2024
@yp05327 yp05327 added type/bug topic/ui Change the appearance of the Gitea UI labels Feb 19, 2024
@lunny
Copy link
Member

lunny commented Feb 19, 2024

The map is unordered? How about using two slices?

@wxiaoguang
Copy link
Contributor

  1. It should use slices, but not map. Map is unordered.
  2. It should highlight the whole code block first, then split it. Otherwise it doesn't work well with multiple line highlighting.

@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 20, 2024
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 20, 2024
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 22, 2024
@wxiaoguang
Copy link
Contributor

There seems to be CI failures

@yp05327
Copy link
Contributor Author

yp05327 commented Feb 26, 2024

CI failure is caused by the file which is end with two \n, and we have another issue caused by this:
image
image

@yp05327
Copy link
Contributor Author

yp05327 commented Feb 26, 2024

It is caused by the code here. We removed \n, and it seems that chroma didn't add newlines.
image

@silverwind
Copy link
Member

silverwind commented Feb 26, 2024

If your example has single trailing \n, then UI should not render it, but monaco should.

@yp05327
Copy link
Contributor Author

yp05327 commented Feb 26, 2024

So 3 lines here is expected? even there are only two lines below.
image

And we should also not render it in search results?

@yp05327
Copy link
Contributor Author

yp05327 commented Feb 26, 2024

If the content is aaa\n\n, when we search aaa, we will get aaa\n.
And the \n here is not the last \n of this file, so we should render it in the search result?
But if the content is aaa\n, when we search aaa, we will also get aaa\n.
But the \n here is the last \n in this file, so how should we deal with it in this case? 🤔

@silverwind
Copy link
Member

So 3 lines here is expected? even there are only two lines below. image

And we should also not render it in search results?

a\n expectance is "1 line", no final newline in code view or search results, final newline visible in monaco.
a\n\n expectance is "2 lines", no final newline in code view or search results, final newline visible in monaco.

@silverwind
Copy link
Member

If the content is aaa\n\n, when we search aaa, we will get aaa\n. And the \n here is not the last \n of this file, so we should render it in the search result? But if the content is aaa\n, when we search aaa, we will also get aaa\n. But the \n here is the last \n in this file, so how should we deal with it in this case? 🤔

Search should just be a simple "contains" query in the raw text, including matching any trailing newline. It is only hidding during view rendering, does not affect the search.

@silverwind
Copy link
Member

It's indented behaviour that final newline does not render in code view and this matches GitHub behaviour. It's just that our line count is off by 1 if there is a final newline.

@lunny lunny added the backport/v1.21 This PR should be backported to Gitea 1.21 label Mar 1, 2024
@lunny
Copy link
Member

lunny commented Mar 1, 2024

image

@yp05327
Copy link
Contributor Author

yp05327 commented Mar 1, 2024

image

What is your test content?

@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 5, 2024
@wxiaoguang
Copy link
Contributor

I think it could just do this : 5f8ff71 , no more trailing EOL trick.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 5, 2024
@wxiaoguang wxiaoguang enabled auto-merge (squash) March 6, 2024 07:00
@wxiaoguang wxiaoguang added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 6, 2024
@wxiaoguang wxiaoguang merged commit a2b0fb1 into go-gitea:main Mar 6, 2024
26 checks passed
@GiteaBot GiteaBot added this to the 1.23.0 milestone Mar 6, 2024
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Mar 6, 2024
Fix go-gitea#29136

Before: The result is a table and all line numbers are all in one row.

After: Use a separate table column for the line numbers.

---------

Co-authored-by: wxiaoguang <[email protected]>
@GiteaBot GiteaBot added backport/done All backports for this PR have been created and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Mar 6, 2024
silverwind added a commit to silverwind/gitea that referenced this pull request Mar 6, 2024
* origin/main: (29 commits)
  Tweak actions color and borders (go-gitea#29640)
  Add download URL for executable files (go-gitea#28260)
  Move all login and account creation page labels to be above inputs (go-gitea#29432)
  Avoid issue info panic (go-gitea#29625)
  Cache repository default branch commit status to reduce query on commit status table (go-gitea#29444)
  Avoid unexpected panic in graceful manager (go-gitea#29629)
  Add a link for the recently pushed branch notification (go-gitea#29627)
  Fix wrong header of org project view page (go-gitea#29626)
  Detect broken git hooks (go-gitea#29494)
  Sync branches to DB immediately when handle git hook calling (go-gitea#29493)
  Fix wrong line number in code search result (go-gitea#29260)
  Make wiki default branch name changable (go-gitea#29603)
  A small refactor for agit implementation (go-gitea#29614)
  Update Twitter Logo (go-gitea#29621)
  Fix 500 error when adding PR comment (go-gitea#29622)
  Run editorconfig-checker on `locale_en-US.ini` (go-gitea#29608)
  bump protobuf module (go-gitea#29617)
  Add ac claim for old docker/build-push-action@v3 / current buildx gha cache (go-gitea#29584)
  Skip email domain check when admins edit user emails (go-gitea#29609)
  Improve natural sort (go-gitea#29611)
  ...
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 7, 2024
* giteaofficial/main:
  Use strict protocol check when redirect (go-gitea#29642)
  Update various logos and unify their filenames (go-gitea#29637)
  Tweak actions color and borders (go-gitea#29640)
  Add download URL for executable files (go-gitea#28260)
  Move all login and account creation page labels to be above inputs (go-gitea#29432)
  Avoid issue info panic (go-gitea#29625)
  Cache repository default branch commit status to reduce query on commit status table (go-gitea#29444)
  Avoid unexpected panic in graceful manager (go-gitea#29629)
  Add a link for the recently pushed branch notification (go-gitea#29627)
  Fix wrong header of org project view page (go-gitea#29626)
  Detect broken git hooks (go-gitea#29494)
  Sync branches to DB immediately when handle git hook calling (go-gitea#29493)
  Fix wrong line number in code search result (go-gitea#29260)
  Make wiki default branch name changable (go-gitea#29603)
  A small refactor for agit implementation (go-gitea#29614)
  Update Twitter Logo (go-gitea#29621)
  Fix 500 error when adding PR comment (go-gitea#29622)
@lunny lunny modified the milestones: 1.23.0, 1.22.0 Mar 8, 2024
DennisRasey pushed a commit to DennisRasey/forgejo that referenced this pull request Mar 10, 2024
Port [Fix wrong line number in code search result (gitea#29260)](go-gitea/gitea#29260)

PS: also added [`-e`](https://git-scm.com/docs/git-grep#Documentation/git-grep.txt--e) before passing the keyword (my bad)

Co-authored-by: yp05327 <[email protected]>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2619
Reviewed-by: Earl Warren <[email protected]>
Co-authored-by: Shiny Nematoda <[email protected]>
Co-committed-by: Shiny Nematoda <[email protected]>
@yp05327 yp05327 deleted the fix-29136 branch March 13, 2024 02:18
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jun 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created backport/v1.21 This PR should be backported to Gitea 1.21 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. topic/ui Change the appearance of the Gitea UI type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong linenumber in search-result, when line is to long
6 participants