Find and replace highlight sometimes jumps to the first item instead of next after replacing
📝 Provide detailed reproduction steps (if any)
I'll start with videos since it illustrates this case nicely.
1st example works fine, and replace cycles nicely over words in order:
https://github.com/cksource/ckeditor5-commercial/assets/1061942/678d2099-5e1a-4a77-acef-43c844cb4ca0
2nd and 3rd shows that highlight sometimes jumps to the first item:
https://github.com/cksource/ckeditor5-commercial/assets/1061942/82279342-3e5f-446a-89bb-3b08bc81f928
https://github.com/cksource/ckeditor5-commercial/assets/1061942/0054df5f-27ed-4b23-9393-36c1f3c65059
Steps
As in 3rd video:
- Got to editor instance with Find and Replace enabled, e.g. https://ckeditor.com/docs/ckeditor5/42.0.0/features/find-and-replace.html.
- Use complex document, e.g. content from https://ckeditor.com/docs/ckeditor5/42.0.0/examples/builds/classic-editor.html.
- Open Find and Replace dialog.
- Type 'You' as "Find" and press "Find" button.
- Navigate to 5th result.
- Fill replace text and press replace.
- Press replace again.
✔️ Expected result
Replace should cycle over items in order.
❌ Actual result
Sometimes highlight jumps to first item.
❓ Possible solution
Not sure, I was suspecting complex structure and first item in a block/paragraph but was not able to confirm that with quick testing.
📃 Other details
- Browser: Chrome
- OS: MacOS
- First affected CKEditor version: Not sure
- Installed CKEditor plugins: Find and replace
If you'd like to see this fixed sooner, add a 👍 reaction to this post.
This is simple to replicate without tracked changes:
- Go to https://ckeditor.com/ckeditor-5/demo/feature-rich/
- Replace all the text with "This doesn't work. This doesn't work. This doesn't work."
- Open Find and Replace, and Find the word "work".
- Click 'Next result' to skip the first occurrence.
- Replace the second occurrence with another word.
- Expected: Highlight/cursor moves to the third occurrence
- Actual: Cursor jumps back to the first occurrence.
The issue is reproducible in blocks that contain 2+ occurrences of queried sequence. If there is only one occurrence, the selection is moved as expected.
- block with 1 occurrence:
https://github.com/user-attachments/assets/12e88a5a-02e0-45a6-9c56-810d6d7a28a0
- block with 2 occurrences:
https://github.com/user-attachments/assets/5afaccba-e61b-43b0-b5d7-f0360213a0a5
I proposed fix: https://github.com/ckeditor/ckeditor5/pull/17292