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

Explosion when pasting to nested element #2010

Closed
oskarwrobel opened this issue Aug 30, 2019 · 3 comments · Fixed by ckeditor/ckeditor5-engine#1830
Closed

Explosion when pasting to nested element #2010

oskarwrobel opened this issue Aug 30, 2019 · 3 comments · Fixed by ckeditor/ckeditor5-engine#1830
Assignees
Labels
package:block-quote package:heading type:bug This issue reports a buggy (incorrect) behavior.

Comments

@oskarwrobel
Copy link
Contributor

When pasting content to the document where the selection starts at the beginning of the nested element and ends in the next block

<blockQuote>
    <paragraph>[Foo</paragraph>
</blockQuote>
<paragraph>Bar]</paragraph>

the selected content is removed (the entire blockquote) and then new content is inserted at the selection position. The problem is the selection position does not change after deleting content and still refers to the removed place in the document (path [0,0,0] or [ '$root', 'blockQuote', 'paragraph' ]). When comes to insertion there is an explosion because insert position does not exist.

We should manually fix selection between deleting and inserting content. Model selection post-fixer could be extracted to som util (or maybe it is already) and called manually.

Aug-30-2019 11-14-20

ckeditorerror.js:66 Uncaught CKEditorError: model-position-path-incorrect: The position's path is incorrect. Read more: https://ckeditor.com/docs/ckeditor5/latest/framework/guides/support/error-codes.html#error-model-position-path-incorrect
 {"position":{"root":"main","path":[0,0,0],"stickiness":"toNext"}}
    at Position.get parent [as parent] (http://localhost:8125/ckeditor5-block-quote/tests/manual/blockquote.js:59068:11)
    at new Insertion (http://localhost:8125/ckeditor5-block-quote/tests/manual/blockquote.js:65021:48)
    at Object.callback (http://localhost:8125/ckeditor5-block-quote/tests/manual/blockquote.js:64941:21)
    at Model._runPendingChanges (http://localhost:8125/ckeditor5-block-quote/tests/manual/blockquote.js:53260:58)
    at Model.change (http://localhost:8125/ckeditor5-block-quote/tests/manual/blockquote.js:52682:16)
    at insertContent (http://localhost:8125/ckeditor5-block-quote/tests/manual/blockquote.js:64924:15)
    at Model.insertContent (http://localhost:8125/ckeditor5-block-quote/tests/manual/blockquote.js:52869:79)
    at Model.<anonymous> (http://localhost:8125/ckeditor5-block-quote/tests/manual/blockquote.js:113897:32)
    at Model.fire (http://localhost:8125/ckeditor5-block-quote/tests/manual/blockquote.js:111772:29)
    at Model.<computed> [as insertContent] (http://localhost:8125/ckeditor5-block-quote/tests/manual/blockquote.js:113901:16)
@oskarwrobel oskarwrobel added type:bug This issue reports a buggy (incorrect) behavior. status:confirmed labels Aug 30, 2019
@oskarwrobel
Copy link
Contributor Author

Turns out fix is very easy. Insertion position is stored before deleting content but should be after.

-               const insertionPosition = selection.getFirstPosition();
-
                if ( !selection.isCollapsed ) {
                        model.deleteContent( selection, { doNotAutoparagraph: true } );
                }

+               const insertionPosition = selection.getFirstPosition();
                const insertion = new Insertion( model, writer, insertionPosition );```

@oskarwrobel oskarwrobel self-assigned this Aug 30, 2019
@oskarwrobel oskarwrobel added this to the iteration 27 milestone Aug 30, 2019
@oskarwrobel
Copy link
Contributor Author

oskarwrobel commented Aug 30, 2019

Unfortunately, fix I proposed may lead to losing target position.

For the following model

<blockQuote>
    <p>Foo</p>
</blockQuote>
<p>Bar</p>

insert abc content in the place of <p>Bar</p>

The expected result will be:

<blockQuote>
    <p>Foo</p>
</blockQuote>
<p>abc</p>

The actual result:

<blockQuote>
    <p>Fooabc</p>
</blockQuote>

After deleting content the selection moves to the end of the last block element wher $text is allowed.

@Reinmar Reinmar modified the milestones: iteration 27, next Oct 3, 2019
@Reinmar Reinmar assigned oleq and unassigned oskarwrobel Mar 4, 2020
@Reinmar Reinmar modified the milestones: next, iteration 30 Mar 4, 2020
@oleq oleq removed their assignment Mar 6, 2020
@Reinmar Reinmar self-assigned this Mar 6, 2020
@Reinmar
Copy link
Member

Reinmar commented Mar 9, 2020

Fixed with ckeditor/ckeditor5-engine#1830.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:block-quote package:heading type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants