When only using block level images, insertcontent-invalid-insertion-position in console on paste of HTML
📝 Provide detailed reproduction steps (if any)
-
Have an editor with only the folowing plugins: [ Essentials, ImageBlock, Paragraph, Undo ]
-
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.
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.
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
Thank you, I can reproduce the problem and will investigate it.
Issue details:
- It reproduces for any content with the following pattern: block element + non-paragraph element that needs autoparagraphing (soft break, text etc) + block element.
- 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.
- If
ImageInlineplugin 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.