ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

When only using block level images, insertcontent-invalid-insertion-position in console on paste of HTML

Open Joel-Levi opened this issue 1 year ago • 4 comments

📝 Provide detailed reproduction steps (if any)

Reproduction repo

  1. Have an editor with only the folowing plugins: [ Essentials, ImageBlock, Paragraph, Undo ]

  2. Paste html looking like: <img><br><img> or <img>CK<img>

Clipboard contents on moment of pasting:

<meta http-equiv="content-type" content="text/html; charset=utf-8"><img src="http://127.0.0.1:5501/sample/repro.png"> <br> <img src="http://127.0.0.1:5501/sample/repro.png">%

✔️ Expected result

HTML gets pasted and is rendered properly

❌ Actual result

nothing is pasted, insertcontent-invalid-insertion-position error in the console, coming from here : https://github.com/ckeditor/ckeditor5/blob/04a8c63bdad639792727275a0e30832869c7067f/packages/ckeditor5-engine/src/model/utils/insertcontent.ts#L362

❓ Possible solution

unfocusing the editor after this reproduction fixes the rendering somehow.

📃 Other details

  • Browser: Latest Chrome, Latest Firefox
  • OS: Linux Ubuntu
  • First affected CKEditor version: ?
  • Installed CKEditor plugins: [ Essentials, ImageBlock, Paragraph, Undo ]

If you'd like to see this fixed sooner, add a 👍 reaction to this post.

Joel-Levi avatar May 07 '24 14:05 Joel-Levi

Hello, thank you for reporting and providing a sample repo. Unfortunately, I wasn't able to reproduce the issue - see the recording below.

https://github.com/ckeditor/ckeditor5/assets/10883184/ba248810-9c73-4ee8-9712-2caf27ec0b52

It would be best if you are able to also send a recording showing the exact use case, so showing the source you are copying the content from, and the editor state when you are pasting it.

Dumluregn avatar May 20 '24 11:05 Dumluregn

recording.webm

I am dragging the content that is in the reproduction page into the editor. You can see nothing is rendered, until I press a button

Joel-Levi avatar May 21 '24 07:05 Joel-Levi

Thank you, I can reproduce the problem and will investigate it.

Dumluregn avatar May 21 '24 10:05 Dumluregn

Issue details:

  1. It reproduces for any content with the following pattern: block element + non-paragraph element that needs autoparagraphing (soft break, text etc) + block element.
  2. When such content is pasted/dropped into the editor, only the middle part is autoparagraphed, which later causes a positions mismatch inside https://github.com/ckeditor/ckeditor5/blob/39a77912905694a61e8da4c42dd1b36f76fde400/packages/ckeditor5-engine/src/model/utils/insertcontent.ts#L349-L368.
  3. If ImageInline plugin is loaded, pasted image becomes <imageInline> instead. Then the whole content goes into an autoparagraph so the positions are correct and the issue does not occur.

I added a failing unit test and images to the imageBlock manual test for easy issue reproduction at ck/16321-invalid-insert-content branch.

Dumluregn avatar May 21 '24 13:05 Dumluregn