Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Disable horizontal merge between header and body cells.
Browse files Browse the repository at this point in the history
  • Loading branch information
aStewartDesign committed Nov 15, 2019
1 parent 63da06f commit 21eaf17
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/commands/mergecellcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions tests/commands/mergecellcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 21eaf17

Please sign in to comment.