|
|
@@ -272,33 +272,6 @@ describe( 'table clipboard', () => {
|
|
|
] ) );
|
|
|
} );
|
|
|
|
|
|
- it( 'should block non-rectangular selection', () => {
|
|
|
- setModelData( model, modelTable( [
|
|
|
- [ { contents: '00', colspan: 3 } ],
|
|
|
- [ '10', '11', '12' ],
|
|
|
- [ '20', '21', '22' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- tableSelection.setCellSelection(
|
|
|
- modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
- modelRoot.getNodeByPath( [ 0, 1, 1 ] )
|
|
|
- );
|
|
|
-
|
|
|
- // Catches the temporary console log in the CK_DEBUG mode.
|
|
|
- sinon.stub( console, 'log' );
|
|
|
-
|
|
|
- pasteTable( [
|
|
|
- [ 'aa', 'ab' ],
|
|
|
- [ 'ba', 'bb' ]
|
|
|
- ] );
|
|
|
-
|
|
|
- assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
- [ { contents: '00', colspan: 3 } ],
|
|
|
- [ '10', '11', '12' ],
|
|
|
- [ '20', '21', '22' ]
|
|
|
- ] ) );
|
|
|
- } );
|
|
|
-
|
|
|
describe( 'single cell selected', () => {
|
|
|
beforeEach( () => {
|
|
|
setModelData( model, modelTable( [
|
|
|
@@ -792,6 +765,39 @@ describe( 'table clipboard', () => {
|
|
|
[ '', '', '', 'ea', 'eb', 'ec', 'ed' ]
|
|
|
] ) );
|
|
|
} );
|
|
|
+
|
|
|
+ it( 'should fix non-rectangular are on matched table fragment', () => {
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | 01 | 02 |
|
|
|
+ // +----+----+ +
|
|
|
+ // | 10 | 11 | |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 20 | 22 |
|
|
|
+ // +----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', '01', { contents: '02', rowspan: 2 } ],
|
|
|
+ [ '10', '11[]' ],
|
|
|
+ [ { contents: '20', colspan: 2 }, '22' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ 'ba', 'bb' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | 01 | 02 |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 10 | aa | ab |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 20 | ba | bb |
|
|
|
+ // +----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ '00', '01', '02' ],
|
|
|
+ [ '10', 'aa', 'ab' ],
|
|
|
+ [ '20', 'ba', 'bb' ]
|
|
|
+ ] ) );
|
|
|
+ } );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
@@ -1371,8 +1377,7 @@ describe( 'table clipboard', () => {
|
|
|
/* eslint-enable no-multi-spaces */
|
|
|
} );
|
|
|
|
|
|
- // TODO: Skipped case - should allow pasting but no tools to compare areas (like in MergeCellsCommand).
|
|
|
- it.skip( 'handles pasting table that has cell with colspan (last row in selection is spanned)', () => {
|
|
|
+ it( 'handles pasting table that has cell with colspan (last row in selection is spanned)', () => {
|
|
|
// +----+----+----+----+
|
|
|
// | 00 | 01 | 02 | 03 |
|
|
|
// +----+----+----+----+
|
|
|
@@ -1389,6 +1394,7 @@ describe( 'table clipboard', () => {
|
|
|
[ '30', '31', '32', '33' ]
|
|
|
] ) );
|
|
|
|
|
|
+ // Select 02 -> 10 (selection 3x3)
|
|
|
tableSelection.setCellSelection(
|
|
|
modelRoot.getNodeByPath( [ 0, 0, 2 ] ),
|
|
|
modelRoot.getNodeByPath( [ 0, 1, 0 ] )
|
|
|
@@ -1414,6 +1420,132 @@ describe( 'table clipboard', () => {
|
|
|
[ 0, 0, 0, 0 ]
|
|
|
] );
|
|
|
} );
|
|
|
+
|
|
|
+ it( 'handles pasting table that has cell with colspan (multiple ending rows in the selection are spanned)', () => {
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | 01 | 02 |
|
|
|
+ // +----+ + +
|
|
|
+ // | 10 | | |
|
|
|
+ // +----+ + +
|
|
|
+ // | 20 | | |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 30 | 31 | 32 |
|
|
|
+ // +----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', { contents: '01', rowspan: 3 }, { contents: '02', rowspan: 3 } ],
|
|
|
+ [ '10' ],
|
|
|
+ [ '20' ],
|
|
|
+ [ '30', '31', '32' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 01 -> 02 (selection 2x2)
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 1 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 2 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ 'ba', 'bb' ],
|
|
|
+ [ 'ca', 'cb' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ '00', 'aa', 'ab' ],
|
|
|
+ [ '10', 'ba', 'bb' ],
|
|
|
+ [ '20', 'ca', 'cb' ],
|
|
|
+ [ '30', '31', '32' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 0, 1, 1 ],
|
|
|
+ [ 0, 1, 1 ],
|
|
|
+ [ 0, 1, 1 ],
|
|
|
+ [ 0, 0, 0 ]
|
|
|
+ ] );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'handles pasting table that has cell with colspan (last column in selection is spanned)', () => {
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 00 | 01 | 03 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 10 | 11 | 13 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 20 | | 23 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 30 | 31 | 32 | 33 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', { contents: '01', colspan: 2 }, '03' ],
|
|
|
+ [ '10', { contents: '11', colspan: 2, rowspan: 2 }, '13' ],
|
|
|
+ [ '20', '23' ],
|
|
|
+ [ '30', '31', '32', '33' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 20 -> 01 (selection 3x3)
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 1 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab', 'ac' ],
|
|
|
+ [ 'ba', 'bb', 'bc' ],
|
|
|
+ [ 'ca', 'cb', 'cc' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ 'aa', 'ab', 'ac', '03' ],
|
|
|
+ [ 'ba', 'bb', 'bc', '13' ],
|
|
|
+ [ 'ca', 'cb', 'cc', '23' ],
|
|
|
+ [ '30', '31', '32', '33' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 1, 1, 1, 0 ],
|
|
|
+ [ 1, 1, 1, 0 ],
|
|
|
+ [ 1, 1, 1, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ]
|
|
|
+ ] );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'handles pasting table that has cell with colspan (multiple ending columns in the selection are spanned)', () => {
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 00 | 01 | 02 | 03 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 10 | 13 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 20 | 23 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', '01', '02', '03' ],
|
|
|
+ [ { contents: '10', colspan: 3 }, '13' ],
|
|
|
+ [ { contents: '20', colspan: 3 }, '23' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 10 -> 20 (selection 3x2)
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 0 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab', 'ac' ],
|
|
|
+ [ 'ba', 'bb', 'bc' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ '00', '01', '02', '03' ],
|
|
|
+ [ 'aa', 'ab', 'ac', '13' ],
|
|
|
+ [ 'ba', 'bb', 'bc', '23' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 0, 0, 0, 0 ],
|
|
|
+ [ 1, 1, 1, 0 ],
|
|
|
+ [ 1, 1, 1, 0 ]
|
|
|
+ ] );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
describe( 'content and paste tables have spans', () => {
|
|
|
@@ -1565,8 +1697,7 @@ describe( 'table clipboard', () => {
|
|
|
/* eslint-enable no-multi-spaces */
|
|
|
} );
|
|
|
|
|
|
- // TODO: Skipped case - should allow pasting but no tools to compare areas (like in MergeCellsCommand).
|
|
|
- it.skip( 'handles pasting table that has cell with colspan (last row in selection is spanned)', () => {
|
|
|
+ it( 'handles pasting table that has cell with colspan (last row in selection is spanned)', () => {
|
|
|
// +----+----+----+----+
|
|
|
// | 00 | 01 | 02 | 03 |
|
|
|
// +----+----+----+----+
|
|
|
@@ -1583,6 +1714,7 @@ describe( 'table clipboard', () => {
|
|
|
[ '30', '31', '32', '33' ]
|
|
|
] ) );
|
|
|
|
|
|
+ // Select 02 -> 10 (selection 3x3)
|
|
|
tableSelection.setCellSelection(
|
|
|
modelRoot.getNodeByPath( [ 0, 0, 2 ] ),
|
|
|
modelRoot.getNodeByPath( [ 0, 1, 0 ] )
|
|
|
@@ -1602,111 +1734,591 @@ describe( 'table clipboard', () => {
|
|
|
] );
|
|
|
|
|
|
assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
- [ '00', '01', '02', '03' ],
|
|
|
- [ '10', { colspan: 2, contents: 'aa' }, '13' ],
|
|
|
- [ '20', 'ba', 'bb', '23' ],
|
|
|
+ [ 'aa', 'ab', 'ac', '03' ],
|
|
|
+ [ { contents: 'ba', colspan: 2, rowspan: 2 }, 'bc', '13' ],
|
|
|
+ [ 'cc', '23' ],
|
|
|
[ '30', '31', '32', '33' ]
|
|
|
] ) );
|
|
|
|
|
|
/* eslint-disable no-multi-spaces */
|
|
|
assertSelectedCells( model, [
|
|
|
- [ 0, 0, 0, 0 ],
|
|
|
- [ 0, 1, 0 ],
|
|
|
- [ 0, 1, 1, 0 ],
|
|
|
+ [ 1, 1, 1, 0 ],
|
|
|
+ [ 1, 1, 0 ],
|
|
|
+ [ 1, 0 ],
|
|
|
[ 0, 0, 0, 0 ]
|
|
|
] );
|
|
|
/* eslint-enable no-multi-spaces */
|
|
|
} );
|
|
|
- } );
|
|
|
- } );
|
|
|
|
|
|
- describe( 'pasted table is bigger than the selected area', () => {
|
|
|
- describe( 'no spans', () => {
|
|
|
- it( 'handles simple table paste to a simple table fragment - at the beginning of a table', () => {
|
|
|
+ it( 'handles pasting table that has cell with colspan (last column in selection is spanned)', () => {
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 00 | 01 | 03 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 10 | 11 | 13 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 20 | | 23 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 30 | 31 | 32 | 33 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', { contents: '01', colspan: 2 }, '03' ],
|
|
|
+ [ '10', { contents: '11', colspan: 2, rowspan: 2 }, '13' ],
|
|
|
+ [ '20', '23' ],
|
|
|
+ [ '30', '31', '32', '33' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 20 -> 01 (selection 3x3)
|
|
|
tableSelection.setCellSelection(
|
|
|
- modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
- modelRoot.getNodeByPath( [ 0, 1, 1 ] )
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 1 ] )
|
|
|
);
|
|
|
|
|
|
+ // +----+----+----+
|
|
|
+ // | aa | ab | ac |
|
|
|
+ // +----+----+----+
|
|
|
+ // | ba | bc |
|
|
|
+ // + +----+
|
|
|
+ // | | cc |
|
|
|
+ // +----+----+----+
|
|
|
pasteTable( [
|
|
|
[ 'aa', 'ab', 'ac' ],
|
|
|
- [ 'ba', 'bb', 'bc' ],
|
|
|
- [ 'ca', 'cb', 'cc' ]
|
|
|
+ [ { contents: 'ba', colspan: 2, rowspan: 2 }, 'bc' ],
|
|
|
+ [ 'cc' ]
|
|
|
] );
|
|
|
|
|
|
assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
- [ 'aa', 'ab', '02', '03' ],
|
|
|
- [ 'ba', 'bb', '12', '13' ],
|
|
|
- [ '20', '21', '22', '23' ],
|
|
|
+ [ 'aa', 'ab', 'ac', '03' ],
|
|
|
+ [ { contents: 'ba', colspan: 2, rowspan: 2 }, 'bc', '13' ],
|
|
|
+ [ 'cc', '23' ],
|
|
|
[ '30', '31', '32', '33' ]
|
|
|
] ) );
|
|
|
|
|
|
+ /* eslint-disable no-multi-spaces */
|
|
|
assertSelectedCells( model, [
|
|
|
- [ 1, 1, 0, 0 ],
|
|
|
- [ 1, 1, 0, 0 ],
|
|
|
- [ 0, 0, 0, 0 ],
|
|
|
+ [ 1, 1, 1, 0 ],
|
|
|
+ [ 1, 1, 0 ],
|
|
|
+ [ 1, 0 ],
|
|
|
[ 0, 0, 0, 0 ]
|
|
|
] );
|
|
|
+ /* eslint-enable no-multi-spaces */
|
|
|
} );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'handles simple table paste to a simple table fragment - at the end of a table', () => {
|
|
|
+ describe( 'non-rectangular content table selection', () => {
|
|
|
+ it( 'should split cells outside the selected area before pasting (rowspan ends in selection)', () => {
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | 01 | 02 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 10 | | 12 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 20 | | 22 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 30 | | 32 |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 40 | 41 | 42 |
|
|
|
+ // +----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', { contents: '01', rowspan: 4 }, '02' ],
|
|
|
+ [ '10', '12' ],
|
|
|
+ [ '20', '22' ],
|
|
|
+ [ '30', '32' ],
|
|
|
+ [ '40', '41', '42' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 20 -> 32
|
|
|
tableSelection.setCellSelection(
|
|
|
- modelRoot.getNodeByPath( [ 0, 2, 2 ] ),
|
|
|
- modelRoot.getNodeByPath( [ 0, 3, 3 ] )
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 3, 1 ] )
|
|
|
);
|
|
|
|
|
|
pasteTable( [
|
|
|
[ 'aa', 'ab', 'ac' ],
|
|
|
- [ 'ba', 'bb', 'bc' ],
|
|
|
- [ 'ca', 'cb', 'cc' ]
|
|
|
+ [ 'ba', 'bb', 'bc' ]
|
|
|
] );
|
|
|
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | 01 | 02 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 10 | | 12 |
|
|
|
+ // +----+----+----+
|
|
|
+ // | aa | ab | ac |
|
|
|
+ // +----+----+----+
|
|
|
+ // | ba | bb | bc |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 40 | 41 | 42 |
|
|
|
+ // +----+----+----+
|
|
|
assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
- [ '00', '01', '02', '03' ],
|
|
|
- [ '10', '11', '12', '13' ],
|
|
|
- [ '20', '21', 'aa', 'ab' ],
|
|
|
- [ '30', '31', 'ba', 'bb' ]
|
|
|
+ [ '00', { contents: '01', rowspan: 2 }, '02' ],
|
|
|
+ [ '10', '12' ],
|
|
|
+ [ 'aa', 'ab', 'ac' ],
|
|
|
+ [ 'ba', 'bb', 'bc' ],
|
|
|
+ [ '40', '41', '42' ]
|
|
|
] ) );
|
|
|
-
|
|
|
- assertSelectedCells( model, [
|
|
|
- [ 0, 0, 0, 0 ],
|
|
|
- [ 0, 0, 0, 0 ],
|
|
|
- [ 0, 0, 1, 1 ],
|
|
|
- [ 0, 0, 1, 1 ]
|
|
|
- ] );
|
|
|
} );
|
|
|
|
|
|
- it( 'handles simple table paste to a simple table fragment - in the middle of a table', () => {
|
|
|
+ it( 'should split cells outside the selected area before pasting (rowspan ends after the selection)', () => {
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | 01 | 02 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 10 | | 12 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 20 | | 22 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 30 | | 32 |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 40 | 41 | 42 |
|
|
|
+ // +----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', { contents: '01', rowspan: 4 }, '02' ],
|
|
|
+ [ '10', '12' ],
|
|
|
+ [ '20', '22' ],
|
|
|
+ [ '30', '32' ],
|
|
|
+ [ '40', '41', '42' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 10 -> 22
|
|
|
tableSelection.setCellSelection(
|
|
|
- modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
|
|
|
- modelRoot.getNodeByPath( [ 0, 2, 2 ] )
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 1 ] )
|
|
|
);
|
|
|
|
|
|
pasteTable( [
|
|
|
[ 'aa', 'ab', 'ac' ],
|
|
|
- [ 'ba', 'bb', 'bc' ],
|
|
|
- [ 'ca', 'cb', 'cc' ]
|
|
|
+ [ 'ba', 'bb', 'bc' ]
|
|
|
] );
|
|
|
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | 01 | 02 |
|
|
|
+ // +----+----+----+
|
|
|
+ // | aa | ab | ac |
|
|
|
+ // +----+----+----+
|
|
|
+ // | ba | bb | bc |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 30 | | 32 |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 40 | 41 | 42 |
|
|
|
+ // +----+----+----+
|
|
|
assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
- [ '00', '01', '02', '03' ],
|
|
|
- [ '10', 'aa', 'ab', '13' ],
|
|
|
- [ '20', 'ba', 'bb', '23' ],
|
|
|
- [ '30', '31', '32', '33' ]
|
|
|
+ [ '00', '01', '02' ],
|
|
|
+ [ 'aa', 'ab', 'ac' ],
|
|
|
+ [ 'ba', 'bb', 'bc' ],
|
|
|
+ [ '30', '', '32' ],
|
|
|
+ [ '40', '41', '42' ]
|
|
|
] ) );
|
|
|
-
|
|
|
- assertSelectedCells( model, [
|
|
|
- [ 0, 0, 0, 0 ],
|
|
|
- [ 0, 1, 1, 0 ],
|
|
|
- [ 0, 1, 1, 0 ],
|
|
|
- [ 0, 0, 0, 0 ]
|
|
|
- ] );
|
|
|
} );
|
|
|
|
|
|
- it( 'handles paste to a simple row fragment - in the middle of a table', () => {
|
|
|
+ it( 'should split cells inside the selected area before pasting (rowspan ends after the selection)', () => {
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | 01 | 02 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 10 | | 12 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 20 | | 22 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 30 | | 32 |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 40 | 41 | 42 |
|
|
|
+ // +----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', { contents: '01', rowspan: 4 }, '02' ],
|
|
|
+ [ '10', '12' ],
|
|
|
+ [ '20', '22' ],
|
|
|
+ [ '30', '32' ],
|
|
|
+ [ '40', '41', '42' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 00 -> 12
|
|
|
tableSelection.setCellSelection(
|
|
|
- modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
|
|
|
- modelRoot.getNodeByPath( [ 0, 1, 2 ] )
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 1 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab', 'ac' ],
|
|
|
+ [ 'ba', 'bb', 'bc' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+
|
|
|
+ // | aa | ab | ac |
|
|
|
+ // +----+----+----+
|
|
|
+ // | ba | bb | bc |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 20 | | 22 |
|
|
|
+ // +----+ +----+
|
|
|
+ // | 30 | | 32 |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 40 | 41 | 42 |
|
|
|
+ // +----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ 'aa', 'ab', 'ac' ],
|
|
|
+ [ 'ba', 'bb', 'bc' ],
|
|
|
+ [ '20', { rowspan: 2, contents: '' }, '22' ],
|
|
|
+ [ '30', '32' ],
|
|
|
+ [ '40', '41', '42' ]
|
|
|
+ ] ) );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should split cells outside the selected area before pasting (colspan ends in selection)', () => {
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 00 | 01 | 02 | 03 | 04 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 10 | 14 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 20 | 21 | 22 | 23 | 24 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', '01', '02', '03', '04' ],
|
|
|
+ [ { contents: '10', colspan: 4 }, '14' ],
|
|
|
+ [ '20', '21', '22', '23', '24' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 02 -> 23
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 2 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 3 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ 'ba', 'bb' ],
|
|
|
+ [ 'ca', 'cb' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 00 | 01 | aa | ab | 04 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 10 | ba | bb | 14 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 20 | 21 | ca | cb | 24 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ '00', '01', 'aa', 'ab', '04' ],
|
|
|
+ [ { contents: '10', colspan: 2 }, 'ba', 'bb', '14' ],
|
|
|
+ [ '20', '21', 'ca', 'cb', '24' ]
|
|
|
+ ] ) );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should split cells outside the selected area before pasting (colspan ends after the selection)', () => {
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 00 | 01 | 02 | 03 | 04 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 10 | 14 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 20 | 21 | 22 | 23 | 24 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', '01', '02', '03', '04' ],
|
|
|
+ [ { contents: '10', colspan: 4 }, '14' ],
|
|
|
+ [ '20', '21', '22', '23', '24' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 01 -> 22
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 1 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 2 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ 'ba', 'bb' ],
|
|
|
+ [ 'ca', 'cb' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 00 | aa | ab | 03 | 04 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 10 | ba | bb | | 14 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 20 | ca | cb | 23 | 24 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ '00', 'aa', 'ab', '03', '04' ],
|
|
|
+ [ '10', 'ba', 'bb', '', '14' ],
|
|
|
+ [ '20', 'ca', 'cb', '23', '24' ]
|
|
|
+ ] ) );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should split cells inside the selected area before pasting (colspan ends after the selection)', () => {
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 00 | 01 | 02 | 03 | 04 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 10 | 14 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | 20 | 21 | 22 | 23 | 24 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', '01', '02', '03', '04' ],
|
|
|
+ [ { contents: '10', colspan: 4 }, '14' ],
|
|
|
+ [ '20', '21', '22', '23', '24' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 00 -> 21
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 1 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ 'ba', 'bb' ],
|
|
|
+ [ 'ca', 'cb' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | aa | ab | 02 | 03 | 04 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | ba | bb | | 14 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ // | ca | cb | 22 | 23 | 24 |
|
|
|
+ // +----+----+----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ 'aa', 'ab', '02', '03', '04' ],
|
|
|
+ [ 'ba', 'bb', { colspan: 2, contents: '' }, '14' ],
|
|
|
+ [ 'ca', 'cb', '22', '23', '24' ]
|
|
|
+ ] ) );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should split cells anchored outside selection rectangle that overlaps selection (above selection)', () => {
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | 02 |
|
|
|
+ // + +----+
|
|
|
+ // | | 12 |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 20 | 21 | 22 |
|
|
|
+ // +----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ { contents: '00', colspan: 2, rowspan: 2 }, '02' ],
|
|
|
+ [ '12' ],
|
|
|
+ [ '20', '21', '22' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 21 -> 12
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 1 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 0 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ 'ba', 'bb' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | | 02 |
|
|
|
+ // + +----+----+
|
|
|
+ // | | aa | ab |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 20 | ba | bb |
|
|
|
+ // +----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ { contents: '00', rowspan: 2 }, '', '02' ],
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ '20', 'ba', 'bb' ]
|
|
|
+ ] ) );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should split cells anchored outside selection rectangle that overlaps selection (below selection)', () => {
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | 01 | 02 |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 10 | 12 |
|
|
|
+ // + +----+
|
|
|
+ // | | 22 |
|
|
|
+ // +----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ '00', '01', '02' ],
|
|
|
+ [ { contents: '10', colspan: 2, rowspan: 2 }, '12' ],
|
|
|
+ [ '22' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 01 -> 12
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 1 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 1 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ 'ba', 'bb' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+
|
|
|
+ // | 00 | aa | ab |
|
|
|
+ // +----+----+----+
|
|
|
+ // | 10 | ba | bb |
|
|
|
+ // + +----+----+
|
|
|
+ // | | | 22 |
|
|
|
+ // +----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ '00', 'aa', 'ab' ],
|
|
|
+ [ { contents: '10', rowspan: 2 }, 'ba', 'bb' ],
|
|
|
+ [ '', '22' ]
|
|
|
+ ] ) );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should properly handle complex case', () => {
|
|
|
+ // +----+----+----+----+----+----+----+
|
|
|
+ // | 00 | 03 | 04 |
|
|
|
+ // + + +----+----+----+
|
|
|
+ // | | | 14 | 15 | 16 |
|
|
|
+ // + + +----+----+----+
|
|
|
+ // | | | 24 |
|
|
|
+ // +----+----+----+----+----+----+----+
|
|
|
+ // | 30 | 31 | 33 | 34 | 35 | 36 |
|
|
|
+ // + +----+----+ +----+----+----+
|
|
|
+ // | | 41 | 42 | | 44 | 45 |
|
|
|
+ // + +----+----+ +----+ +
|
|
|
+ // | | 51 | 52 | | 54 | |
|
|
|
+ // +----+----+----+ +----+ +
|
|
|
+ // | 60 | 61 | 62 | | 64 | |
|
|
|
+ // +----+----+----+----+----+----+----+
|
|
|
+ setModelData( model, modelTable( [
|
|
|
+ [ { contents: '00', colspan: 3, rowspan: 3 }, { contents: '03', rowspan: 3 }, { colspan: 3, contents: '04' } ],
|
|
|
+ [ '14', '15', '16' ],
|
|
|
+ [ { contents: '24', colspan: 3 } ],
|
|
|
+ [
|
|
|
+ { contents: '30', rowspan: 3 },
|
|
|
+ { contents: '31', colspan: 2 },
|
|
|
+ { contents: '33', rowspan: 4 },
|
|
|
+ '34', '35', '36'
|
|
|
+ ],
|
|
|
+ [ '41', '42', '44', { contents: '45', colspan: 2, rowspan: 3 } ],
|
|
|
+ [ '51', '52', '54' ],
|
|
|
+ [ '60', '61', '62', '64' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ // Select 42 -> 24 (3x3 selection)
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 4, 1 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 0 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab', 'ac' ],
|
|
|
+ [ 'ba', 'bb', 'bc' ],
|
|
|
+ [ 'ca', 'cb', 'cc' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+----+----+----+----+
|
|
|
+ // | 00 | | 03 | 04 |
|
|
|
+ // + + + +----+----+----+
|
|
|
+ // | | | | 14 | 15 | 16 |
|
|
|
+ // + +----+----+----+----+----+
|
|
|
+ // | | aa | ab | ac | |
|
|
|
+ // +----+----+----+----+----+----+----+
|
|
|
+ // | 30 | 31 | ba | bb | bc | 35 | 36 |
|
|
|
+ // + +----+----+----+----+----+----+
|
|
|
+ // | | 41 | ca | cb | cc | 45 |
|
|
|
+ // + +----+----+----+----+ +
|
|
|
+ // | | 51 | 52 | | 54 | |
|
|
|
+ // +----+----+----+ +----+ +
|
|
|
+ // | 60 | 61 | 62 | | 64 | |
|
|
|
+ // +----+----+----+----+----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [
|
|
|
+ { contents: '00', colspan: 2, rowspan: 3 },
|
|
|
+ { contents: '', rowspan: 2 },
|
|
|
+ { contents: '03', rowspan: 2 },
|
|
|
+ { contents: '04', colspan: 3 }
|
|
|
+ ],
|
|
|
+ [ '14', '15', '16' ],
|
|
|
+ [ 'aa', 'ab', 'ac', { contents: '', colspan: 2 } ],
|
|
|
+ [ { contents: '30', rowspan: 3 }, '31', 'ba', 'bb', 'bc', '35', '36' ],
|
|
|
+ [ '41', 'ca', 'cb', 'cc', { contents: '45', colspan: 2, rowspan: 3 } ],
|
|
|
+ [ '51', '52', { contents: '', rowspan: 2 }, '54' ],
|
|
|
+ [ '60', '61', '62', '64' ]
|
|
|
+ ] ) );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'pasted table is bigger than the selected area', () => {
|
|
|
+ describe( 'no spans', () => {
|
|
|
+ it( 'handles simple table paste to a simple table fragment - at the beginning of a table', () => {
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 1 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab', 'ac' ],
|
|
|
+ [ 'ba', 'bb', 'bc' ],
|
|
|
+ [ 'ca', 'cb', 'cc' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ 'aa', 'ab', '02', '03' ],
|
|
|
+ [ 'ba', 'bb', '12', '13' ],
|
|
|
+ [ '20', '21', '22', '23' ],
|
|
|
+ [ '30', '31', '32', '33' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ]
|
|
|
+ ] );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'handles simple table paste to a simple table fragment - at the end of a table', () => {
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 2 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 3, 3 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab', 'ac' ],
|
|
|
+ [ 'ba', 'bb', 'bc' ],
|
|
|
+ [ 'ca', 'cb', 'cc' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ '00', '01', '02', '03' ],
|
|
|
+ [ '10', '11', '12', '13' ],
|
|
|
+ [ '20', '21', 'aa', 'ab' ],
|
|
|
+ [ '30', '31', 'ba', 'bb' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 0, 0, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ],
|
|
|
+ [ 0, 0, 1, 1 ],
|
|
|
+ [ 0, 0, 1, 1 ]
|
|
|
+ ] );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'handles simple table paste to a simple table fragment - in the middle of a table', () => {
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 2 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab', 'ac' ],
|
|
|
+ [ 'ba', 'bb', 'bc' ],
|
|
|
+ [ 'ca', 'cb', 'cc' ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ '00', '01', '02', '03' ],
|
|
|
+ [ '10', 'aa', 'ab', '13' ],
|
|
|
+ [ '20', 'ba', 'bb', '23' ],
|
|
|
+ [ '30', '31', '32', '33' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 0, 0, 0, 0 ],
|
|
|
+ [ 0, 1, 1, 0 ],
|
|
|
+ [ 0, 1, 1, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ]
|
|
|
+ ] );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'handles paste to a simple row fragment - in the middle of a table', () => {
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 2 ] )
|
|
|
);
|
|
|
|
|
|
pasteTable( [
|
|
|
@@ -1997,6 +2609,294 @@ describe( 'table clipboard', () => {
|
|
|
] );
|
|
|
} );
|
|
|
} );
|
|
|
+
|
|
|
+ describe( 'fixing pasted table broken layout', () => {
|
|
|
+ it( 'should trim pasted cells\' width if they exceeds table width established by the first row', () => {
|
|
|
+ // Select 00 -> 22 (selection 2x3 - equal to expected fixed table)
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 2, 1 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ // +----+----+
|
|
|
+ // | aa | ab | <- First row establish table width=2.
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ba | bb | <- Cell "bb" sticks out by 2 slots.
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ca | <- Cell "ca" sticks out by 1 slot.
|
|
|
+ // +----+----+----+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ 'ba', { colspan: 3, contents: 'bb' } ],
|
|
|
+ [ { colspan: 3, contents: 'ca' } ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | aa | ab | 02 | 03 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ba | bb | 12 | 13 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ca | 22 | 23 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 30 | 31 | 32 | 33 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ 'aa', 'ab', '02', '03' ],
|
|
|
+ [ 'ba', 'bb', '12', '13' ],
|
|
|
+ [ { contents: 'ca', colspan: 2 }, '22', '23' ],
|
|
|
+ [ '30', '31', '32', '33' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ /* eslint-disable no-multi-spaces */
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 1, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ]
|
|
|
+ ] );
|
|
|
+ /* eslint-enable no-multi-spaces */
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should trim pasted cells\' height if they exceeds table height established by the last row', () => {
|
|
|
+ // Select 00 -> 12 (selection 3x2 - equal to expected fixed table)
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 2 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ // +----+----+----+
|
|
|
+ // | aa | ab | ac |
|
|
|
+ // +----+----+ +
|
|
|
+ // | ba | bb | | <- Last row establish table height=2.
|
|
|
+ // +----+ + +
|
|
|
+ // | | | <- Cell "ac" sticks out by 1 slot.
|
|
|
+ // + +----+
|
|
|
+ // | | <- Cell "bb" sticks out by 2 slots.
|
|
|
+ // +----+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab', { contents: 'ac', rowspan: 3 } ],
|
|
|
+ [ 'ba', { contents: 'bb', rowspan: 3 } ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | aa | ab | ac | 03 |
|
|
|
+ // +----+----+ +----+
|
|
|
+ // | ba | bb | | 13 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 20 | 21 | 22 | 23 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 30 | 31 | 32 | 33 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ 'aa', 'ab', { rowspan: 2, contents: 'ac' }, '03' ],
|
|
|
+ [ 'ba', 'bb', '13' ],
|
|
|
+ [ '20', '21', '22', '23' ],
|
|
|
+ [ '30', '31', '32', '33' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ /* eslint-disable no-multi-spaces */
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 1, 1, 1, 0 ],
|
|
|
+ [ 1, 1, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ]
|
|
|
+ ] );
|
|
|
+ /* eslint-enable no-multi-spaces */
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should trim pasted cells\' height and width if they exceeds table height and width', () => {
|
|
|
+ // Select 00 -> 11 (selection 2x2 - equal to expected fixed table)
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 1 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ // +----+----+
|
|
|
+ // | aa | ab |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ba | bb | <- Cell "bb" sticks out by 2 slots in width and by 1 slot in height.
|
|
|
+ // +----+ +
|
|
|
+ // | |
|
|
|
+ // +----+----+----+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 } ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | aa | ab | 02 | 03 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ba | bb | 12 | 13 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 20 | 21 | 22 | 23 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 30 | 31 | 32 | 33 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ 'aa', 'ab', '02', '03' ],
|
|
|
+ [ 'ba', 'bb', '12', '13' ],
|
|
|
+ [ '20', '21', '22', '23' ],
|
|
|
+ [ '30', '31', '32', '33' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ /* eslint-disable no-multi-spaces */
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ]
|
|
|
+ ] );
|
|
|
+ /* eslint-enable no-multi-spaces */
|
|
|
+ } );
|
|
|
+
|
|
|
+ it(
|
|
|
+ 'should trim pasted cells\' width if they exceeds pasted table width (pasted height is bigger then selection height)',
|
|
|
+ () => {
|
|
|
+ // Select 00 -> 11 (selection 2x2 - smaller by height than the expected fixed table)
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 1 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ // +----+----+
|
|
|
+ // | aa | ab | <- First row establish table width=2.
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ba | bb | <- Cell "bb" sticks out by 2 slots.
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ca | <- Cell "ca" sticks out by 1 slot.
|
|
|
+ // +----+----+----+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ 'ba', { colspan: 3, contents: 'bb' } ],
|
|
|
+ [ { colspan: 3, contents: 'ca' } ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | aa | ab | 02 | 03 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ba | bb | 12 | 13 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 20 | 21 | 22 | 23 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 30 | 31 | 32 | 33 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ 'aa', 'ab', '02', '03' ],
|
|
|
+ [ 'ba', 'bb', '12', '13' ],
|
|
|
+ [ '20', '21', '22', '23' ],
|
|
|
+ [ '30', '31', '32', '33' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ]
|
|
|
+ ] );
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ it(
|
|
|
+ 'should trim pasted cells\' height if they exceeds pasted table height (pasted width is bigger then selection width)',
|
|
|
+ () => {
|
|
|
+ // Select 00 -> 11 (selection 2x2 - smaller by width than the expected fixed table)
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 1 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ // +----+----+----+
|
|
|
+ // | aa | ab | ac |
|
|
|
+ // +----+----+ +
|
|
|
+ // | ba | bb | | <- Last row establish table height=2.
|
|
|
+ // +----+ + +
|
|
|
+ // | | | <- Cell "ac" sticks out by 1 slot.
|
|
|
+ // + +----+
|
|
|
+ // | | <- Cell "bb" sticks out by 2 slots.
|
|
|
+ // +----+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab', { contents: 'ac', rowspan: 3 } ],
|
|
|
+ [ 'ba', { contents: 'bb', rowspan: 3 } ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | aa | ab | 02 | 03 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ba | bb | 12 | 13 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 20 | 21 | 22 | 23 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 30 | 31 | 32 | 33 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ 'aa', 'ab', '02', '03' ],
|
|
|
+ [ 'ba', 'bb', '12', '13' ],
|
|
|
+ [ '20', '21', '22', '23' ],
|
|
|
+ [ '30', '31', '32', '33' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ /* eslint-disable no-multi-spaces */
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ]
|
|
|
+ ] );
|
|
|
+ /* eslint-enable no-multi-spaces */
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ it(
|
|
|
+ `should trim pasted pasted cells' height and width if they exceeds pasted table dimensions
|
|
|
+ (pasted table is bigger then selection width)`,
|
|
|
+ () => {
|
|
|
+ // Select 00 -> 11 (selection 2x2 - smaller than the expected fixed table)
|
|
|
+ tableSelection.setCellSelection(
|
|
|
+ modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
|
|
|
+ modelRoot.getNodeByPath( [ 0, 1, 1 ] )
|
|
|
+ );
|
|
|
+
|
|
|
+ // +----+----+----+
|
|
|
+ // | aa | ab | ac |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ba | bb | <- Cell "bb" sticks out by 1 slots in width and by 1 slot in height.
|
|
|
+ // +----+ +
|
|
|
+ // | ca | |
|
|
|
+ // +----+ +
|
|
|
+ // | |
|
|
|
+ // +----+----+----+
|
|
|
+ pasteTable( [
|
|
|
+ [ 'aa', 'ab' ],
|
|
|
+ [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 } ]
|
|
|
+ ] );
|
|
|
+
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | aa | ab | 02 | 03 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | ba | bb | 12 | 13 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 20 | 21 | 22 | 23 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ // | 30 | 31 | 32 | 33 |
|
|
|
+ // +----+----+----+----+
|
|
|
+ assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
|
|
|
+ [ 'aa', 'ab', '02', '03' ],
|
|
|
+ [ 'ba', 'bb', '12', '13' ],
|
|
|
+ [ '20', '21', '22', '23' ],
|
|
|
+ [ '30', '31', '32', '33' ]
|
|
|
+ ] ) );
|
|
|
+
|
|
|
+ /* eslint-disable no-multi-spaces */
|
|
|
+ assertSelectedCells( model, [
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 1, 1, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ],
|
|
|
+ [ 0, 0, 0, 0 ]
|
|
|
+ ] );
|
|
|
+ /* eslint-enable no-multi-spaces */
|
|
|
+ }
|
|
|
+ );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
describe( 'Clipboard integration - paste (content scenarios)', () => {
|