-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Editor crashes after pasting multi-block content over existing content in a blockquote #1921
Comments
I wrote a test that reproduces the issue: it( 'does not blow up after pasting items over block-quote', () => {
setModelData( model,
'[<blockQuote>' +
'<paragraph>Foo</paragraph>' +
'<paragraph>Bar</paragraph>' +
'</blockQuote>]'
);
console.log( getModelData( model ) );
pasteHtml( editor, '<p>FooBar</p>' );
console.log( getModelData( model ) );
} );
function pasteHtml( editor, html ) {
editor.editing.view.document.fire( 'paste', {
dataTransfer: createDataTransfer( { 'text/html': html } ),
preventDefault() {
}
} );
}
function createDataTransfer( data ) {
return {
getData( type ) {
return data[ type ];
}
};
} And it fails (as expected):
A place in the code where the error was thrown: https://github.com/ckeditor/ckeditor5-engine/blob/04fa92058a83d70c7384713cab9f462d2f1ae90f/src/model/utils/insertcontent.js#L139 And I guess, I understand why it happens. The position after removing all nodes from the editor is invalid. After switching the position to be an instance of Then, I decided to write one more test for the it.only( 'deletes selection with elements before inserting the content', () => {
model.schema.register( 'p', { inheritAllFrom: '$block' } );
model.schema.register( 'div', {
allowWhere: '$block',
allowContentOf: '$root'
} );
setData( model, '[<div><p>Foo</p><p>Bar</p></div>]' );
const affectedRange = insertHelper( '<p>FooBar</p>' );
expect( getData( model ) ).to.equal( '<p>FooBar</p>[]' );
expect( stringify( root, affectedRange ) ).to.equal( '[<p>FooBar</p>]' );
} ); Unfortunately, it didn't fail as I expected. For such case, a position used to create an instance of What am I doing wrong here? |
Thanks to @Reinmar, we figured out what was wrong with the second test. Instead of using a short name of paragraph ( The corrected tests should look like: it( 'deletes selection with elements before inserting the content', () => {
model.schema.register( 'div', {
allowWhere: '$block',
allowContentOf: '$root'
} );
setData( model, '<div><paragraph>[Foo</paragraph><paragraph>Bar]</paragraph></div>' );
const affectedRange = insertHelper( '<paragraph>FooBar</paragraph>' );
expect( getData( model ) ).to.equal( '<paragraph>FooBar[]</paragraph>' );
expect( stringify( root, affectedRange ) ).to.equal( '[<paragraph>FooBar</paragraph>]' );
} ); And this one, as expected, fails. Going into deep, it leads to this issue – https://github.com/ckeditor/ckeditor5-engine/issues/1722 and I'll continue posting my thoughts here. |
Using the Title plugin, the issue is even "easier" to reproduce. Type whatever in the title section, then select all (CTRL/CMD+A) then paste anything. |
DUP of #2010. Fixed with ckeditor/ckeditor5-engine#1830. |
Is this a bug report or feature request? (choose one)
🐞 Bug report
💻 Version of CKEditor
Latest master
📋 Steps to reproduce
editor.setData( '<blockquote><p>test</p><p>test</p></blockquote>' );
✅ Expected result
Content is pasted properly.
❎ Actual result
The editor crashes.
📃 Other details that might be useful
Error
GIF
It's a regression. I've bisected it and it looks like these changes introduced a bug - ckeditor/ckeditor5-engine@f4e4644
The text was updated successfully, but these errors were encountered: