Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Fix: The table cell should always have paragraph in the model. #127

Merged
merged 4 commits into from
Oct 2, 2018

Conversation

jodator
Copy link
Contributor

@jodator jodator commented Sep 25, 2018

Suggested merge commit message (convention)

Fix: The table cell should always have paragraph in the model. Closes ckeditor/ckeditor5#3237.

BREAKING CHANGE: The injectTablePostFixer() function from table/converters/table-post-fixer is now injectTableLayoutPostFixer()and is moved to table/converters/table-layout-post-fixer module.


Additional information

  • I've added you @Reinmar for the review - I'm not sure if the fix is sufficient.

@jodator jodator assigned Reinmar and unassigned Reinmar Sep 25, 2018
@jodator jodator requested a review from Reinmar September 25, 2018 14:39
@coveralls
Copy link

coveralls commented Sep 25, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 996136f on t/125 into 2f2fe4a on master.

* </tr>
* </tbody>
* </table>
*
* ## Ensuring proper table structure
Copy link
Member

Choose a reason for hiding this comment

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

table structure? or rather "Ensuring a proper content of table cells"?

@@ -49,14 +50,14 @@ import TableWalker from './../tablewalker';
* <table>
* <thead>
* <tr>
* <td rowspan="2">FOO</td>
* <td colspan="2">BAR</td>
* <td rowspan="2"><p>FOO</p></td>
Copy link
Member

Choose a reason for hiding this comment

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

It seems that my comment disappeared so one more time...

Is it correct? Those <p>s won't be rendered (there will be spans or nothing). It's a bit confusing and I'm not sure if this is a mistake or a mental shortcut.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd remove them.

@@ -181,6 +181,19 @@ describe( 'Table post-fixer', () => {
} );
} );

describe( 'on removing tableCell contents', () => {
it( 'should fix empty table cells', () => {
Copy link
Member

Choose a reason for hiding this comment

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

It's hard to understand from this test that it checks that a paragraph should be added. I checked that it fails without the patch and the error is quite obvious then, but the code and description of this test are cryptic.

There are many opinions regarding writing so many tools for creating tests. But, leaving this aside, when we write them we should make sure that tests remain understandable.

@Reinmar
Copy link
Member

Reinmar commented Sep 28, 2018

Other than the issues in the code, I checked that this PR fixes the bug.

@jodator
Copy link
Contributor Author

jodator commented Oct 1, 2018

@Reinmar I've updated the solution:

  • the Table Post-Ffixer was renamed to a more descriptive: Table Layout Post-Fixer as it fixes table layout (missing table cells)
  • I've moved the table cell content post fixer to own file as it does something else then table layout post-fixer
  • more tests added as it should act also on adding table/tableRow/tableCell to the model.

Copy link
Member

@Reinmar Reinmar left a comment

Choose a reason for hiding this comment

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

Approved, works fine, code looks good, but you may want to report a followup for the "What if a cell already has some content, but that's a text?" problem

// @param {module:engine/model/element~Element} table
// @param {module:engine/model/writer~Writer} writer
function fixTableCellContent( tableCell, writer ) {
if ( tableCell.childCount == 0 ) {
Copy link
Member

Choose a reason for hiding this comment

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

What if a cell already has some content, but that's a text? We can make this a followup because I don't know right now scenario which would lead to this, but it's certainly possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIR the $text is not allowed in the model of a table cell.

Copy link
Member

Choose a reason for hiding this comment

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

Which does not mean it cannot end there. Schema rules are not enforced. Check out https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/framework/guides/deep-dive/schema.html#implementing-additional-constraints and the following section.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Weird things start to happen after pasting a (disallowed) image into a table cell
3 participants