Browse Source

Fix: Merge cell command should be disabled for directions that cross table sections.

Maciej Gołaszewski 7 years ago
parent
commit
5148198be6

+ 8 - 1
packages/ckeditor5-table/src/commands/mergecellcommand.js

@@ -144,7 +144,14 @@ function getVerticalCell( tableCell, direction ) {
 	const rowIndex = table.getChildIndex( tableRow );
 
 	// Don't search for mergeable cell if direction points out of the table.
-	if ( direction == 'down' && rowIndex === table.childCount - 1 || direction == 'up' && rowIndex === 0 ) {
+	if ( ( direction == 'down' && rowIndex === table.childCount - 1 ) || ( direction == 'up' && rowIndex === 0 ) ) {
+		return;
+	}
+
+	const headingRows = parseInt( table.getAttribute( 'headingRows' ) || 0 );
+
+	// Don't search for mergeable cell if direction points out of the current table section.
+	if ( headingRows && ( ( direction == 'down' && rowIndex === headingRows - 1 ) || ( direction == 'up' && rowIndex === headingRows ) ) ) {
 		return;
 	}
 

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

@@ -316,6 +316,15 @@ describe( 'MergeCellCommand', () => {
 
 				expect( command.isEnabled ).to.be.false;
 			} );
+
+			it( 'should be false if mergeable cell is in other table section then current cell', () => {
+				setData( model, modelTable( [
+					[ '00[]', '01' ],
+					[ '10', '11' ]
+				], { headingRows: 1 } ) );
+
+				expect( command.isEnabled ).to.be.false;
+			} );
 		} );
 
 		describe( 'value', () => {
@@ -426,6 +435,15 @@ describe( 'MergeCellCommand', () => {
 
 				expect( command.isEnabled ).to.be.false;
 			} );
+
+			it( 'should be false if mergeable cell is in other table section then current cell', () => {
+				setData( model, modelTable( [
+					[ '00', '01' ],
+					[ '10[]', '11' ]
+				], { headingRows: 1 } ) );
+
+				expect( command.isEnabled ).to.be.false;
+			} );
 		} );
 
 		describe( 'value', () => {