8
0
Просмотр исходного кода

Handle table cell properties in pasted table.

Maciej Gołaszewski 5 лет назад
Родитель
Сommit
11393522f5

+ 7 - 0
packages/ckeditor5-table/src/tableclipboard.js

@@ -199,6 +199,13 @@ export default class TableClipboard extends Plugin {
 				updateNumericAttribute( 'colspan', cellToInsert.getAttribute( 'colspan' ), targetCell, writer, 1 );
 				updateNumericAttribute( 'rowspan', cellToInsert.getAttribute( 'rowspan' ), targetCell, writer, 1 );
 
+				const attributesToCopy = Array.from( cellToInsert.getAttributeKeys() )
+					.filter( attribute => attribute !== 'colspan' || attribute !== 'rowspan' );
+
+				for ( const attribute of attributesToCopy ) {
+					writer.setAttribute( attribute, cellToInsert.getAttribute( attribute ), targetCell );
+				}
+
 				// TODO: use Element._clone to copy full structure.
 				for ( const child of Array.from( cellToInsert.getChildren() ) ) {
 					writer.insert( child, targetCell, 'end' );

+ 47 - 3
packages/ckeditor5-table/tests/tableclipboard-paste.js

@@ -18,6 +18,7 @@ import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'
 import { assertSelectedCells, modelTable, viewTable } from './_utils/utils';
 
 import TableEditing from '../src/tableediting';
+import TableCellPropertiesEditing from '../src/tablecellproperties/tablecellpropertiesediting';
 import TableClipboard from '../src/tableclipboard';
 
 describe( 'table clipboard', () => {
@@ -1309,9 +1310,9 @@ describe( 'table clipboard', () => {
 					'<listItem listIndent="0" listType="bulleted">foo</listItem>' +
 					'<listItem listIndent="0" listType="bulleted">bar</listItem>' +
 					'<blockQuote>' +
-						'<paragraph>baz</paragraph>' +
-						'<listItem listIndent="0" listType="bulleted">foo</listItem>' +
-						'<listItem listIndent="0" listType="bulleted">bar</listItem>' +
+					'<paragraph>baz</paragraph>' +
+					'<listItem listIndent="0" listType="bulleted">foo</listItem>' +
+					'<listItem listIndent="0" listType="bulleted">bar</listItem>' +
 					'</blockQuote>',
 					'ab',
 					'02' ],
@@ -1319,6 +1320,49 @@ describe( 'table clipboard', () => {
 				[ '02', '21', '22' ]
 			] ) );
 		} );
+
+		it( 'handles table cell properties handling', async () => {
+			await createEditor( [ TableCellPropertiesEditing ] );
+
+			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( [
+				[ { contents: 'aa', style: 'border:1px solid #f00;background:#ba7;width:1337px' }, 'ab' ],
+				[ 'ba', 'bb' ]
+			] );
+
+			const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
+
+			expect( tableCell.getAttribute( 'borderColor' ) ).to.deep.equal( {
+				top: '#f00',
+				right: '#f00',
+				bottom: '#f00',
+				left: '#f00'
+			} );
+			expect( tableCell.getAttribute( 'borderStyle' ) ).to.deep.equal( {
+				top: 'solid',
+				right: 'solid',
+				bottom: 'solid',
+				left: 'solid'
+			} );
+			expect( tableCell.getAttribute( 'borderWidth' ) ).to.deep.equal( {
+				top: '1px',
+				right: '1px',
+				bottom: '1px',
+				left: '1px'
+			} );
+			expect( tableCell.getAttribute( 'backgroundColor' ) ).to.equal( '#ba7' );
+			expect( tableCell.getAttribute( 'width' ) ).to.equal( '1337px' );
+		} );
 	} );
 
 	async function createEditor( extraPlugins = [] ) {