瀏覽代碼

Disable horizontal merge between header and body cells.

Andrew Stewart 6 年之前
父節點
當前提交
733723007f

+ 10 - 0
packages/ckeditor5-table/src/commands/mergecellcommand.js

@@ -153,7 +153,10 @@ export default class MergeCellCommand extends Command {
 // @param {String} direction
 // @returns {module:engine/model/node~Node|null}
 function getHorizontalCell( tableCell, direction, tableUtils ) {
+	const tableRow = tableCell.parent;
+	const table = tableRow.parent;
 	const horizontalCell = direction == 'right' ? tableCell.nextSibling : tableCell.previousSibling;
+	const headingColumns = table.getAttribute( 'headingColumns' ) || 0;
 
 	if ( !horizontalCell ) {
 		return;
@@ -169,6 +172,13 @@ function getHorizontalCell( tableCell, direction, tableUtils ) {
 
 	const leftCellSpan = parseInt( cellOnLeft.getAttribute( 'colspan' ) || 1 );
 
+	const isMergeWithBodyCell = direction == 'right' && rightCellColumn === headingColumns;
+	const isMergeWithHeadCell = direction == 'left' && leftCellColumn === ( headingColumns - 1 );
+
+	if ( headingColumns && ( isMergeWithBodyCell || isMergeWithHeadCell ) ) {
+		return;
+	}
+
 	// The cell on the right must have index that is distant to the cell on the left by the left cell's width (colspan).
 	const cellsAreTouching = leftCellColumn + leftCellSpan === rightCellColumn;
 

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

@@ -93,6 +93,14 @@ 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' ],
+				], { headingColumns: 1 } ) );
+
+				expect( command.isEnabled ).to.be.false;
+			} );
 		} );
 
 		describe( 'value', () => {
@@ -273,6 +281,14 @@ 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[]' ],
+				], { headingColumns: 1 } ) );
+
+				expect( command.isEnabled ).to.be.false;
+			} );
 		} );
 
 		describe( 'value', () => {