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

Disable horizontal merge between header and body cells. #225

Merged
merged 1 commit into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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