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

Codemirror blob: Scroll search match into view #42513

Merged
merged 1 commit into from Oct 5, 2022

Conversation

fkling
Copy link
Contributor

@fkling fkling commented Oct 4, 2022

Addresses #42482

This commit adds logic to scroll the next occurrence of the blob search term into view if no match is present in the current viewport.

It doesn't look like CodeMirror provides an API to actually "select" a specific match. An alternative approach would be to just determine whether any match is visible and then call findNext to actually select the next match, but I'm actually not sure how deterministic it is.

cm-blob-scroll-match.mp4

Test plan

  • Go to any file (e.g. github.com/sourcegraph/sourcegraph/-/blob/doc/dev/background-information/web/temporary_settings.md?view=code)
  • Search for a term that is present in the document, after the currently visible content -> next occurrence is scrolled into view.
  • Search for a term that is present in the document, before the currently visible content -> first occurrence should be scrolled into view
  • Search for a term that is not present in the document -> nothing should happen

App preview:

Check out the client app preview documentation to learn more.

This commit adds logic to scroll the next occurrence of the blob search
term into view if no match is present in the current viewport.
@fkling fkling added team/graph Graph Team (previously Code Intel/Language Tools/Language Platform) team/code-navigation codemirror PRs and issues related to migrating to CodeMirror labels Oct 4, 2022
@cla-bot cla-bot bot added the cla-signed label Oct 4, 2022
Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻 I didn't understand first what exactly this PR changes from the old behavior. Just to be 100% sure I got it right, the concrete difference is that you no longer have to press 'Enter' to focus on the first result?

@fkling
Copy link
Contributor Author

fkling commented Oct 5, 2022

@olafurpg

Just to be 100% sure I got it right, the concrete difference is that you no longer have to press 'Enter' to focus on the first result?

Yes, that's right. The first/next match will be scrolled into view as you type. At least that's how I understood the issue.

@fkling fkling merged commit 05a31ae into main Oct 5, 2022
@fkling fkling deleted the fkling/42482-search-scroll-next-match-into-view branch October 5, 2022 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed codemirror PRs and issues related to migrating to CodeMirror team/code-navigation team/graph Graph Team (previously Code Intel/Language Tools/Language Platform)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants