ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

Find and replace highlight sometimes jumps to the first item instead of next after replacing

Open f1ames opened this issue 1 year ago • 2 comments

📝 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:

  1. Got to editor instance with Find and Replace enabled, e.g. https://ckeditor.com/docs/ckeditor5/42.0.0/features/find-and-replace.html.
  2. Use complex document, e.g. content from https://ckeditor.com/docs/ckeditor5/42.0.0/examples/builds/classic-editor.html.
  3. Open Find and Replace dialog.
  4. Type 'You' as "Find" and press "Find" button.
  5. Navigate to 5th result.
  6. Fill replace text and press replace.
  7. 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.

f1ames avatar Jul 02 '24 10:07 f1ames

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.

rmoustgaard avatar Sep 16 '24 13:09 rmoustgaard

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

lkszzajac avatar Sep 19 '24 11:09 lkszzajac

I proposed fix: https://github.com/ckeditor/ckeditor5/pull/17292

Mati365 avatar Oct 22 '24 05:10 Mati365