From 4e7140aa3a80c8f571d45513f798afed7132835c Mon Sep 17 00:00:00 2001 From: Kuba Niegowski Date: Tue, 7 Jul 2020 19:44:25 +0200 Subject: [PATCH 1/3] Added "td" element to the blockElements list in DomConverter. --- packages/ckeditor5-engine/src/view/domconverter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ckeditor5-engine/src/view/domconverter.js b/packages/ckeditor5-engine/src/view/domconverter.js index 8abeb1d6cf6..9a6f9b578f8 100644 --- a/packages/ckeditor5-engine/src/view/domconverter.js +++ b/packages/ckeditor5-engine/src/view/domconverter.js @@ -82,7 +82,7 @@ export default class DomConverter { * @readonly * @member {Array.} 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' ]; /** * Block {@link module:engine/view/filler filler} creator, which is used to create all block fillers during the From 17aeb1fbcdf4fbad9d8b5f975acb0ed927afa1c3 Mon Sep 17 00:00:00 2001 From: Kuba Niegowski Date: Wed, 8 Jul 2020 16:17:12 +0200 Subject: [PATCH 2/3] Added test for pasting table with block fillers inside cells. --- .../tests/tableclipboard-paste.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/ckeditor5-table/tests/tableclipboard-paste.js b/packages/ckeditor5-table/tests/tableclipboard-paste.js index e7eac1472f4..fbe35332f3f 100644 --- a/packages/ckeditor5-table/tests/tableclipboard-paste.js +++ b/packages/ckeditor5-table/tests/tableclipboard-paste.js @@ -3553,6 +3553,32 @@ describe( 'table clipboard', () => { [ '02', '21', '22' ] ] ) ); } ); + + it( 'removes block fillers from empty cells', 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( [ + [ ' ', ' ' ], + [ ' ', ' ' ] + ] ); + + assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [ + [ '', '', '02' ], + [ '', '', '12' ], + [ '02', '21', '22' ] + ] ) ); + } ); } ); async function createEditor( extraPlugins = [] ) { From 8ae767c9c4b5cb867185b0916ecc48f7f73d44b3 Mon Sep 17 00:00:00 2001 From: Kuba Niegowski Date: Fri, 10 Jul 2020 13:42:15 +0200 Subject: [PATCH 3/3] Added th element support for DomConverter. --- packages/ckeditor5-engine/src/view/domconverter.js | 2 +- packages/ckeditor5-table/tests/tableclipboard-paste.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/ckeditor5-engine/src/view/domconverter.js b/packages/ckeditor5-engine/src/view/domconverter.js index 9a6f9b578f8..ce2ec97f1e9 100644 --- a/packages/ckeditor5-engine/src/view/domconverter.js +++ b/packages/ckeditor5-engine/src/view/domconverter.js @@ -82,7 +82,7 @@ export default class DomConverter { * @readonly * @member {Array.} module:engine/view/domconverter~DomConverter#blockElements */ - this.blockElements = [ 'p', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'dd', 'dt', 'figcaption', 'td' ]; + 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 diff --git a/packages/ckeditor5-table/tests/tableclipboard-paste.js b/packages/ckeditor5-table/tests/tableclipboard-paste.js index fbe35332f3f..63598d21b44 100644 --- a/packages/ckeditor5-table/tests/tableclipboard-paste.js +++ b/packages/ckeditor5-table/tests/tableclipboard-paste.js @@ -3554,7 +3554,7 @@ describe( 'table clipboard', () => { ] ) ); } ); - it( 'removes block fillers from empty cells', async () => { + it( 'removes block fillers from empty cells (both td and th)', async () => { await createEditor(); setModelData( model, modelTable( [ @@ -3571,7 +3571,7 @@ describe( 'table clipboard', () => { pasteTable( [ [ ' ', ' ' ], [ ' ', ' ' ] - ] ); + ], { headingRows: 1 } ); assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [ [ '', '', '02' ], @@ -3592,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;