Parcourir la source

Internal: Fixed a case where a table with empty row in model would break remove row command.

Marek Lewandowski il y a 5 ans
Parent
commit
3912b2a80d

+ 2 - 1
packages/ckeditor5-table/src/tableutils.js

@@ -561,7 +561,8 @@ export default class TableUtils extends Plugin {
 	 */
 	getRows( table ) {
 		return [ ...table.getChildren() ].reduce( ( rows, row ) => {
-			const currentRowCount = parseInt( row.getChild( 0 ).getAttribute( 'rowspan' ) || 1 );
+			const firstCell = row.getChild( 0 );
+			const currentRowCount = firstCell ? parseInt( firstCell.getAttribute( 'rowspan' ) || 1 ) : 0;
 
 			return rows + currentRowCount;
 		}, 0 );

+ 10 - 0
packages/ckeditor5-table/tests/commands/removerowcommand.js

@@ -86,6 +86,16 @@ describe( 'RemoveRowCommand', () => {
 
 			expect( command.isEnabled ).to.be.false;
 		} );
+
+		it( 'should work return a proper value even if there\'s empty row in model', () => {
+			setData( model, modelTable( [
+				[ '00', '01[]' ],
+				[ '10', '11' ],
+				[]
+			] ) );
+
+			expect( command.isEnabled ).to.be.true;
+		} );
 	} );
 
 	describe( 'execute()', () => {

+ 9 - 0
packages/ckeditor5-table/tests/tableutils.js

@@ -728,5 +728,14 @@ describe( 'TableUtils', () => {
 
 			expect( tableUtils.getRows( root.getNodeByPath( [ 0 ] ) ) ).to.equal( 4 );
 		} );
+
+		it( 'should work correctly with rows containing no cells', () => {
+			setData( model, modelTable( [
+				[ '00', '01' ],
+				[]
+			] ) );
+
+			expect( tableUtils.getRows( root.getNodeByPath( [ 0 ] ) ) ).to.equal( 1 );
+		} );
 	} );
 } );