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

Merge pull request #279 from ckeditor/i/6431

Internal: The remove row command should be disabled when the entire table column is selected. Closes ckeditor/ckeditor5#6431.
Aleksander Nowodzinski 5 лет назад
Родитель
Сommit
9193d5ff5e

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

@@ -560,11 +560,8 @@ export default class TableUtils extends Plugin {
 	 * @returns {Number}
 	 */
 	getRows( table ) {
-		return [ ...table.getChildren() ].reduce( ( rows, row ) => {
-			const currentRowCount = parseInt( row.getChild( 0 ).getAttribute( 'rowspan' ) || 1 );
-
-			return rows + currentRowCount;
-		}, 0 );
+		// Simple row counting, not including rowspan due to #6427.
+		return table.childCount;
 	}
 }
 

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

@@ -86,6 +86,24 @@ describe( 'RemoveRowCommand', () => {
 
 			expect( command.isEnabled ).to.be.false;
 		} );
+
+		it( 'should be false when the first column with rowspan is selected', () => {
+			// (#6427)
+			setData( model, modelTable( [
+				[ { rowspan: 2, contents: '00' }, '01' ],
+				[ '11' ],
+				[ '20', '21' ]
+			] ) );
+
+			const tableSelection = editor.plugins.get( TableSelection );
+			const modelRoot = model.document.getRoot();
+			tableSelection._setCellSelection(
+				modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
+				modelRoot.getNodeByPath( [ 0, 2, 0 ] )
+			);
+
+			expect( command.isEnabled ).to.be.false;
+		} );
 	} );
 
 	describe( 'execute()', () => {

+ 1 - 1
packages/ckeditor5-table/tests/tableutils.js

@@ -726,7 +726,7 @@ describe( 'TableUtils', () => {
 				[ '21' ]
 			] ) );
 
-			expect( tableUtils.getRows( root.getNodeByPath( [ 0 ] ) ) ).to.equal( 4 );
+			expect( tableUtils.getRows( root.getNodeByPath( [ 0 ] ) ) ).to.equal( 3 );
 		} );
 	} );
 } );