codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.94k stars 376 forks source link

The find next function is not selecting the match when it overlaps with the previous query #1446

Closed andy0130tw closed 1 month ago

andy0130tw commented 1 month ago

Describe the issue

I found an edge case in the search extension where a matched keyword is not selected when the "next" button is triggered.

Steps to reproduce:

  1. Navigate to the sandbox page. The example document is console.log('hello')\n.
  2. While the cursor focuses the editor, press Ctrl/Cmd-f to bring up the search panel.
  3. In the search field, type a c. The first character is highlighted in yellow.
  4. Press Enter. The c is highlighted in orange as an indicator for the current search cursor.
  5. Type con in the search field. Press Enter again.
  6. con should be highlighted in orange, but it stays in yellow.

The logic is that the selection is landing on the next non-overlapping match across queries. This issue is not as obvious if the next query matches the document more than once. In such scenario, the selection in the last step jumps to the next match. Not ideal, but the user can be convinced that it can be navigated back by a Shift-Enter.

Demo: (I have added a seach config for this recording)

https://github.com/user-attachments/assets/b2243816-4072-43d1-8576-a122b0f83919

Browser and platform

N/A

Reproduction link

No response

marijnh commented 1 month ago

Attached patch should help.