Skip to content

Add margins support for list in PFW plugin#5438

Merged
Comandeer merged 23 commits intomasterfrom
t/5316
Apr 24, 2023
Merged

Add margins support for list in PFW plugin#5438
Comandeer merged 23 commits intomasterfrom
t/5316

Conversation

@KarolDawidziuk
Copy link
Copy Markdown
Contributor

What is the purpose of this pull request?

New feature

Does your PR contain necessary tests?

All patches that change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

Did you follow the CKEditor 4 code style guide?

Your code should follow the guidelines from the CKEditor 4 code style guide which helps keep the entire codebase consistent.

  • PR is consistent with the code style guide

What is the proposed changelog entry for this pull request?

* [#5316](https://github.com/ckeditor/ckeditor4/issues/5316): Feature: Add margins support for list elements in PFW plugin when [pasteTools_keepZeroMargins](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-pasteTools_keepZeroMargins) is ON.

What changes did you make?

As lists are unwrapped during the cleaning process and we lost information about margins, I've added a temporary attribute called cke-list-style-margins to save information about zero margins. Then margins are applied during creating a new list when the pasteTools_keepZeroMargins config option is ON.

To prepare a unit test I've used our getClipboard tool and I've take an appropriate html from each browser.

Which issues does your PR resolve?

Closes #5316.

@KarolDawidziuk KarolDawidziuk changed the title Add margins support for list elements in PFW plugin Add margins support for list in PFW plugin Mar 6, 2023
Copy link
Copy Markdown
Member

@Comandeer Comandeer 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 at the first sight! However, I'm wondering if the introduction of the temporary variable is really needed. I was able to replace it with a direct reference to list item styles and it still worked in the manual test. Could you check it?

}
}

delete element.attributes[ 'cke-list-style-margins' ];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably it could be moved to the CKEDITOR.plugins.pastefromword.lists.cleanup function, alongside removal of other temporary attributes.

* @member CKEDITOR.plugins.pastetools.filters.word.lists
*/
createLists: function( root ) {
createLists: function( root, editor ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please update API docs for this method. The same goes for the dissolveList() one.


var value = CKEDITOR.tools.convertToPx( parsedStyles[ key ] );
if ( value === 0 ) {
zeroMargins += key + ': ' + value + 'px; ';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nitpick: in case of zero value, the unit can be skipped:

Suggested change
zeroMargins += key + ': ' + value + 'px; ';
zeroMargins += key + ': ' + value;


// Preserve keeping list margins zero when pasteTools_keepZeroMargins is ON. #5316
if ( keepZeroMargins ) {
innermostContainer.attributes.style = firstLevel1Element.attributes[ 'cke-list-style-margins' ];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is that temporary attribute really needed? From my quick test, it seems that firstLevel1Element styles contain margin styles at this point and can be used directly instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've checked it in my first approach but it doesn't work for me. After your review, I've checked it again and it works well. 🤔 Moreover, the changes are much simpler than adding a temporary variable

@github-actions
Copy link
Copy Markdown

It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days.

@github-actions github-actions bot added the stale The issue / PR will be closed within the next 7 days of inactivity. label Mar 21, 2023
@jacekbogdanski jacekbogdanski removed the stale The issue / PR will be closed within the next 7 days of inactivity. label Mar 22, 2023
@KarolDawidziuk
Copy link
Copy Markdown
Contributor Author

Thanks, @Comandeer for the review.
I've simplified code and PR is ready for another check.

@Comandeer Comandeer self-assigned this Mar 29, 2023
Copy link
Copy Markdown
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

Zero margins seem to work correctly but there is some issue with non-zero ones. I've applied the margin to the list and it's rendered in the editor as the margin between each of the list items when in Word is rendered only before and after the list (sample document). Could you check if we can fix it in some easy way?

Additionally, it would be good to add some tests for non-zero margins.

@KarolDawidziuk
Copy link
Copy Markdown
Contributor Author

Thanks @Comandeer for the review.

I've added support for non-zero margins for list by default when ACF will be properly set. In addition I've added missing unit and manual test for non-zero ones and PR is ready for another check.

Copy link
Copy Markdown
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

The logic looks good and margins are preserved. But there are failing tests due to these changes:

96 failed Paste from Word tests.

Could you check them? I assume that it would be enough to update fixtures to include the information about list margins.

@KarolDawidziuk
Copy link
Copy Markdown
Contributor Author

@Comandeer, fixtures updated

@Comandeer
Copy link
Copy Markdown
Member

Rebased on to the latest master.

Copy link
Copy Markdown
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

I'm wondering about changes to horizontal margins (left and right). We already support them via indent plugins and probably shouldn't touch it at all – especially since the current logic incorrectly handles them (see margin-left.docx).

We should probably stick only to the vertical ones (top and bottom).

@KarolDawidziuk
Copy link
Copy Markdown
Contributor Author

@Comandeer handling of the horizontal margins in lists images was removed.

@Comandeer
Copy link
Copy Markdown
Member

Rebased onto the latest master.

Copy link
Copy Markdown
Member

@Comandeer Comandeer 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, there is one small improvement left.

}, 0 );
}

function getMargins( styles ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably we should get margins from both the first and the last list elements – as Word uses the first one to apply margins before the list and the last one to apply the margin after the list – see list-different-margins.docx.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


var value = CKEDITOR.tools.convertToPx( parsedStyles[ key ] );

// Preserve keeping zero list margins when pasteTools_keepZeroMargins is ON. #53163
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Preserve keeping zero list margins when pasteTools_keepZeroMargins is ON. #53163
// Preserve keeping zero list margins when pasteTools_keepZeroMargins is ON (#53163).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like most of the fixtures are the same as on master, only formatting differs. Could you revert them to their master's versions?

@KarolDawidziuk
Copy link
Copy Markdown
Contributor Author

@Comandeer PR is ready to review.

Copy link
Copy Markdown
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

LGTM! I've just added a missing semicolon between zero margins in the getMargin() function.

@Comandeer Comandeer merged commit ed450ea into master Apr 24, 2023
@Comandeer Comandeer deleted the t/5316 branch April 24, 2023 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add margins support for list elements in PFW plugin

3 participants