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

Search match counter does not reset properly when switching files #3361

Closed
kammeows opened this issue Mar 5, 2025 · 7 comments · Fixed by #3362
Closed

Search match counter does not reset properly when switching files #3361

kammeows opened this issue Mar 5, 2025 · 7 comments · Fixed by #3362
Labels
Area:Editor For CodeMirror-related features Bug

Comments

@kammeows
Copy link
Contributor

kammeows commented Mar 5, 2025

p5.js version

1.11.1

What is your operating system?

Windows

Web browser and version

132.0.6834.160

Actual Behavior

When switching between files in the p5.js Web Editor, the search match counter does not reset. The counter continues displaying results from the previously opened file instead of updating to reflect matches in the new file.

Because of this, it shows wrong values of matched words (if any).

In the following image, I have one hello written in sketch.js:

Image

I switch to index.html, which has 2 hellos written, but the counter doesn't update to 2 and instead shows a wrong value:

Image

And if I type 2 more hellos, it still doesn't update correctly:

Image

Once I switch back to sketch.js, it shows previous count, which again is a wrong behavior:

Image

Expected Behavior

  • When a user switches files, the search match counter should reset and update based on the newly opened file.
  • If the new file contains matching search terms, the counter should reflect the correct number of matches.
  • If no matches are found, the UI should display "No results".

Steps to reproduce

Steps:

  1. Open a file, write hello (only once)
  2. Click on ctrl+F to open the search dialog and search for the word hello. The search counter should display the correct number of matches.
  3. Switch to another file, which has a different number of matches for "hello".
  4. Observe the search match counter—it still displays the count from previous, instead of resetting.
@mennatawfiq
Copy link

Hi
I think the problem is that the SearchState object isn't updated when switching between files. To solve this, we need to clear the search state using the clearSearch function whenever a new file is opened.
I'm willing to work on this solution, so can someone assign it to me?

@raclim
Copy link
Collaborator

raclim commented Mar 5, 2025

Thanks for sharing your thoughts on this issue @mennatawfiq. Since @kammeows submitted a PR for it already we'll continue to work off of that one.

@Jatin24062005
Copy link
Contributor

Jatin24062005 commented Mar 6, 2025

Hey @raclim, before reviewing this pull request, I noticed that the issue is already open at Issue #2125. It would be better to close this duplicate issue and instead reference the older issue.

Additionally, @kammeows' pull request should also be linked to the original issue for better tracking. Let me know your thoughts!

I was also trying to fix this issue, but due to inconsistencies in the steps provided by the original issue author, I couldn't replicate it accurately. If any help is needed in the PR to resolve this, I'm happy to assist! @kammeows @raclim

@kammeows
Copy link
Contributor Author

kammeows commented Mar 6, 2025

Hey @Jatin24062005 thank you for your response! I wasn't aware that this issue was already opened before. @raclim should I link this pr to the original issue? I'm not sure how that is to be done though.

@raclim
Copy link
Collaborator

raclim commented Mar 6, 2025

Thanks for sharing your thoughts @kammeows and @Jatin24062005!

Hmm, ideally we do want to link to and work with the original issues to help with organization. However, I do think that there's a lot of helpful contextual information within this one that's opened that's laid out pretty well. I think it might be okay to keep both open for now, or if you'd like at @kammeows you can close this one and add in your thoughts to the original one, but I think that can be up to you!

@swastikCommits
Copy link

I would like to work in this

@raclim
Copy link
Collaborator

raclim commented Mar 6, 2025

Thanks for your interest in this @swastikCommits. Since @kammeows has submitted a PR for it already, we will continue to work off of their submission.

@raclim raclim added the Area:Editor For CodeMirror-related features label Mar 6, 2025
raclim added a commit that referenced this issue Mar 10, 2025
fix: reset search match counter when switching files (issue #3361)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:Editor For CodeMirror-related features Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants