Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Joel-Levi opened this issue May 7, 2024 · 4 comments
Labels
support:2 An issue reported by a commercially licensed client. type:bug This issue reports a buggy (incorrect) behavior.

Comments

@Joel-Levi
Copy link

Joel-Levi commented May 7, 2024

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

throw new CKEditorError( 'insertcontent-invalid-insertion-position', this );

❓ 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 Joel-Levi added the type:bug This issue reports a buggy (incorrect) behavior. label May 7, 2024
@Joel-Levi Joel-Levi changed the title When only using block level images, insertcontent-invalid-insertion-position in console When only using block level images, insertcontent-invalid-insertion-position in console on paste of HTML May 7, 2024
@aldonace-wu aldonace-wu added the support:2 An issue reported by a commercially licensed client. label May 20, 2024
@Dumluregn
Copy link
Contributor

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

Screen.Recording.2024-05-20.at.13.38.55.mov

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.

@Joel-Levi
Copy link
Author

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

@Dumluregn
Copy link
Contributor

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

@Dumluregn
Copy link
Contributor

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
    private _updateLastNodeFromAutoParagraph( node: Node ): void {
    const positionAfterLastNode = this.writer.createPositionAfter( this._lastNode! );
    const positionAfterNode = this.writer.createPositionAfter( node );
    // If the real end was after the last auto paragraph then update relevant properties.
    if ( positionAfterNode.isAfter( positionAfterLastNode ) ) {
    this._lastNode = node;
    /* istanbul ignore if -- @preserve */
    if ( this.position.parent != node || !this.position.isAtEnd ) {
    // Algorithm's correctness check. We should never end up here but it's good to know that we did.
    // At this point the insertion position should be at the end of the last auto paragraph.
    // Note: This error is documented in other place in this file.
    throw new CKEditorError( 'insertcontent-invalid-insertion-position', this );
    }
    this.position = positionAfterNode;
    this._setAffectedBoundaries( this.position );
    }
    }
    .
  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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support:2 An issue reported by a commercially licensed client. type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

No branches or pull requests

3 participants