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

#7753: Upcast conversion should handle wrapping in paragraphs if it would allow conversion #7787

Merged
merged 13 commits into from
Aug 7, 2020

Conversation

niegowski
Copy link
Contributor

@niegowski niegowski commented Aug 5, 2020

Suggested merge commit message (convention)

Fix (engine): Upcast conversion should handle wrapping in paragraphs if it would allow conversion. Closes #7753. Closes #6698.

Internal (paragraph): Auto-paragraphing content conversion moved to the engine package.

Tests (table): Added tests for upcasting inline elements inside a table cell.


Additional information

@niegowski niegowski marked this pull request as ready for review August 6, 2020 12:19
@niegowski niegowski requested a review from jodator August 6, 2020 12:55
Copy link
Contributor

@jodator jodator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I've proposed some changes in the tests names and some minor changes to the way how autoparagraphing is used.

* @param {module:engine/model/writer~Writer} writer The model writer.
* @returns {Boolean} `true` if any change has been applied, `false` otherwise.
*/
_autoparagraphEmptyRoots( writer ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not using this AFAICS so maybe we could move it to a helper function outside model class.

I'm not entirely sure if this belongs to model, but seeing this called in DataController as this.model._autoparagraphEmptyRoots() gives me strange feeling.

AFAICS we have model/utils with some default post-fixers.

ps.: As we cleanup this I think that autoparagraphEmptyRoots should be autoParagraphEmptyRoots.

// Check if the node wrapped with a paragraph would be accepted by the schema.
const paragraph = wrapWithParagraphIfPossible( node, modelCursor, writer, schema );

return paragraph && {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no :D Please don do't do that ;) Conditional return shouldn't be used. For me the only acceptable way for using && is in isFooBar() checks.

Maybe split logic of wrapWith... to ifPossible() (return null) and wrapWithParagraph + return {} would make it clearer?


conversionApi.writer.insert( text, data.modelCursor );
// When node is already converted then do nothing.
if ( data.modelRange || !consumable.test( data.viewItem ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to tell that we can convert anything using consumable.test() so checking for data.modelRange is unexpected here. What case this covers? Maybe we need to check for a fix for that elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was handled this way (only data.modelRange) in the original code for this. I was also surprised so I added consumable.test there. It's also strange that CC is 100%

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that CC can't notice that it's redundant. Updated it.

packages/ckeditor5-engine/src/conversion/upcasthelpers.js Outdated Show resolved Hide resolved

dispatcher.on( 'documentFragment', ( evt, data, conversionApi ) => {
const section = conversionApi.writer.createElement( 'section' );
const position = ModelPosition._createAt( section, 0 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use conversionApi.writer to create postions? Using writer or model is preferable then importing ModelPosition.
We left that in tests and in engine source code but we might use proper API in the test.

@@ -969,6 +969,31 @@ describe( 'upcast-converters', () => {
expect( conversionResult.getChild( 0 ).data ).to.equal( 'foobar' );
} );

it( 'should wrap text with paragraph if it would allow conversion', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe 'should auto-paragraph text if it is not allowed at insert postion but is inserted where paragraph is allowed'?

@niegowski niegowski requested a review from jodator August 7, 2020 11:29
Copy link
Contributor

@jodator jodator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check this.

packages/ckeditor5-engine/src/controller/datacontroller.js Outdated Show resolved Hide resolved
packages/ckeditor5-engine/src/model/model.js Outdated Show resolved Hide resolved
@jodator jodator merged commit 5e857fd into master Aug 7, 2020
@jodator jodator deleted the i/6698 branch August 7, 2020 12:22
@MrMitch
Copy link

MrMitch commented Aug 9, 2020

@niegowski and @jodator thank you for taking the time to do this and fix #6698, greatly appreciated !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants