Skip to content

Commit

Permalink
Merge pull request #7584 from ckeditor/i/7487
Browse files Browse the repository at this point in the history
Other (engine): Table cells should not be filled with single spaces while pasting table with empty cells. Closes #7487.

Tests (table): Added test for pasting table with block fillers inside cells.
  • Loading branch information
jodator authored Jul 10, 2020
2 parents e023fd6 + 8ae767c commit 284c7c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/view/domconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class DomConverter {
* @readonly
* @member {Array.<String>} module:engine/view/domconverter~DomConverter#blockElements
*/
this.blockElements = [ 'p', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'dd', 'dt', 'figcaption' ];
this.blockElements = [ 'p', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'dd', 'dt', 'figcaption', 'td', 'th' ];

/**
* Block {@link module:engine/view/filler filler} creator, which is used to create all block fillers during the
Expand Down
30 changes: 28 additions & 2 deletions packages/ckeditor5-table/tests/tableclipboard-paste.js
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,32 @@ describe( 'table clipboard', () => {
[ '02', '21', '22' ]
] ) );
} );

it( 'removes block fillers from empty cells (both td and th)', async () => {
await createEditor();

setModelData( model, modelTable( [
[ '00', '01', '02' ],
[ '01', '11', '12' ],
[ '02', '21', '22' ]
] ) );

tableSelection.setCellSelection(
modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
modelRoot.getNodeByPath( [ 0, 1, 1 ] )
);

pasteTable( [
[ '&nbsp;', '&nbsp;' ],
[ '&nbsp;', '&nbsp;' ]
], { headingRows: 1 } );

assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
[ '', '', '02' ],
[ '', '', '12' ],
[ '02', '21', '22' ]
] ) );
} );
} );

async function createEditor( extraPlugins = [] ) {
Expand All @@ -3566,13 +3592,13 @@ describe( 'table clipboard', () => {
tableSelection = editor.plugins.get( 'TableSelection' );
}

function pasteTable( tableData ) {
function pasteTable( tableData, attributes = {} ) {
const data = {
dataTransfer: createDataTransfer(),
preventDefault: sinon.spy(),
stopPropagation: sinon.spy()
};
data.dataTransfer.setData( 'text/html', viewTable( tableData ) );
data.dataTransfer.setData( 'text/html', viewTable( tableData, attributes ) );
viewDocument.fire( 'paste', data );

return data;
Expand Down

0 comments on commit 284c7c1

Please sign in to comment.