diff --git a/packages/ckeditor5-table/src/tablecolumnresize/converters.js b/packages/ckeditor5-table/src/tablecolumnresize/converters.js index 27165983a45..37fed81fdea 100644 --- a/packages/ckeditor5-table/src/tablecolumnresize/converters.js +++ b/packages/ckeditor5-table/src/tablecolumnresize/converters.js @@ -68,9 +68,11 @@ export function downcastTableColumnWidthsAttribute() { return dispatcher => dispatcher.on( 'attribute:columnWidths:table', ( evt, data, conversionApi ) => { const viewWriter = conversionApi.writer; const modelTable = data.item; + const viewElement = conversionApi.mapper.toViewElement( modelTable ); - const viewTable = [ ...conversionApi.mapper.toViewElement( modelTable ).getChildren() ] - .find( viewChild => viewChild.is( 'element', 'table' ) ); + const viewTable = viewElement.is( 'element', 'table' ) ? + viewElement : + Array.from( viewElement.getChildren() ).find( viewChild => viewChild.is( 'element', 'table' ) ); if ( data.attributeNewValue ) { // If new value is the same as the old, the operation is not applied (see the `writer.setAttributeOnItem()`). diff --git a/packages/ckeditor5-table/tests/tablecolumnresize/tablecolumnresizeediting.js b/packages/ckeditor5-table/tests/tablecolumnresize/tablecolumnresizeediting.js index fce4079d901..504f00b7dfe 100644 --- a/packages/ckeditor5-table/tests/tablecolumnresize/tablecolumnresizeediting.js +++ b/packages/ckeditor5-table/tests/tablecolumnresize/tablecolumnresizeediting.js @@ -11,6 +11,7 @@ import TableCaption from '../../src/tablecaption'; import TableToolbar from '../../src/tabletoolbar'; import Table from '../../src/table'; import TableProperties from '../../src/tableproperties'; +import PlainTableOutput from '../../src/plaintableoutput'; // ClassicTestEditor can't be used, as it doesn't handle the focus, which is needed to test resizer visual cues. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; @@ -2558,6 +2559,53 @@ describe( 'TableColumnResizeEditing', () => { expect( initialViewColumnWidthsPx ).to.deep.equal( finalViewColumnWidthsPx ); } ); } ); + + describe( 'PlainTableOutput', () => { + let ptoEditor; + + beforeEach( async () => { + ptoEditor = await createEditor( { + plugins: [ Table, TableColumnResize, Paragraph, PlainTableOutput ] + } ); + } ); + + afterEach( async () => { + await ptoEditor.destroy(); + } ); + + it( 'should not crash', () => { + const table = modelTable( + [ [ 'Some', 'Data' ] ], + { columnWidths: '80%,20%', tableWidth: '100%' } + ); + setModelData( ptoEditor.model, table ); + + expect( () => ptoEditor.getData() ).to.not.throw(); + } ); + + it( 'should produce table not wrapped in
', () => { + const table = modelTable( + [ [ 'Some', 'Data' ] ], + { columnWidths: '80%,20%', tableWidth: '100%' } + ); + setModelData( ptoEditor.model, table ); + + expect( ptoEditor.getData() ).to.equal( + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
SomeData
' + ); + } ); + } ); } ); async function createEditor( configCustomization, additionalPlugins ) {