mergecellscommand.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
  6. import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  7. import MergeCellsCommand from '../../src/commands/mergecellscommand';
  8. import { modelTable } from '../_utils/utils';
  9. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  10. import TableSelection from '../../src/tableselection';
  11. import TableEditing from '../../src/tableediting';
  12. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  13. describe( 'MergeCellsCommand', () => {
  14. let editor, model, command, root, tableSelection;
  15. beforeEach( async () => {
  16. editor = await ModelTestEditor.create( {
  17. plugins: [ Paragraph, TableEditing, TableSelection ]
  18. } );
  19. model = editor.model;
  20. root = model.document.getRoot( 'main' );
  21. tableSelection = editor.plugins.get( TableSelection );
  22. command = new MergeCellsCommand( editor );
  23. } );
  24. afterEach( () => {
  25. return editor.destroy();
  26. } );
  27. describe( 'isEnabled', () => {
  28. it( 'should be false if collapsed selection in table cell', () => {
  29. setData( model, modelTable( [
  30. [ '00[]', '01' ]
  31. ] ) );
  32. expect( command.isEnabled ).to.be.false;
  33. } );
  34. it( 'should be false if only one table cell is selected', () => {
  35. setData( model, modelTable( [
  36. [ '00', '01' ]
  37. ] ) );
  38. selectNodes( [ [ 0, 0, 0 ] ] );
  39. expect( command.isEnabled ).to.be.false;
  40. } );
  41. it( 'should be true if at least two adjacent table cells are selected', () => {
  42. setData( model, modelTable( [
  43. [ '00', '01' ]
  44. ] ) );
  45. selectNodes( [ [ 0, 0, 0 ], [ 0, 0, 1 ] ] );
  46. expect( command.isEnabled ).to.be.true;
  47. } );
  48. it( 'should be true if many table cells are selected', () => {
  49. setData( model, modelTable( [
  50. [ '00', '01', '02', '03' ],
  51. [ '10', '11', '12', '13' ],
  52. [ '20', '21', '22', '23' ],
  53. [ '30', '31', '32', '33' ]
  54. ] ) );
  55. selectNodes( [
  56. [ 0, 0, 1 ], [ 0, 0, 2 ],
  57. [ 0, 1, 1 ], [ 0, 1, 2 ],
  58. [ 0, 2, 1 ], [ 0, 2, 2 ],
  59. [ 0, 3, 1 ], [ 0, 3, 2 ]
  60. ] );
  61. expect( command.isEnabled ).to.be.true;
  62. } );
  63. it( 'should be false if at least one table cell is not selected from an area', () => {
  64. setData( model, modelTable( [
  65. [ '00', '01', '02', '03' ],
  66. [ '10', '11', '12', '13' ],
  67. [ '20', '21', '22', '23' ],
  68. [ '30', '31', '32', '33' ]
  69. ] ) );
  70. selectNodes( [
  71. [ 0, 0, 1 ], [ 0, 0, 2 ],
  72. [ 0, 1, 2 ], // one table cell not selected from this row
  73. [ 0, 2, 1 ], [ 0, 2, 2 ],
  74. [ 0, 3, 1 ], [ 0, 3, 2 ]
  75. ] );
  76. expect( command.isEnabled ).to.be.false;
  77. } );
  78. it( 'should be false if table cells are not in adjacent rows', () => {
  79. setData( model, modelTable( [
  80. [ '00', '01' ],
  81. [ '10', '11' ]
  82. ] ) );
  83. selectNodes( [
  84. [ 0, 1, 0 ],
  85. [ 0, 0, 1 ]
  86. ] );
  87. expect( command.isEnabled ).to.be.false;
  88. } );
  89. it( 'should be false if table cells are not in adjacent columns', () => {
  90. setData( model, modelTable( [
  91. [ '00', '01', '02' ]
  92. ] ) );
  93. selectNodes( [ [ 0, 0, 0 ], [ 0, 0, 2 ] ] );
  94. expect( command.isEnabled ).to.be.false;
  95. } );
  96. it( 'should be false if any table cell with colspan attribute extends over selection area', () => {
  97. setData( model, modelTable( [
  98. [ '00', { colspan: 2, contents: '01' } ],
  99. [ '10', '11', '12' ]
  100. ] ) );
  101. selectNodes( [
  102. [ 0, 0, 0 ], [ 0, 0, 1 ],
  103. [ 0, 1, 0 ], [ 0, 1, 1 ]
  104. ] );
  105. expect( command.isEnabled ).to.be.false;
  106. } );
  107. it( 'should be true if none table cell with colspan attribute extends over selection area', () => {
  108. setData( model, modelTable( [
  109. [ '00', { colspan: 2, contents: '01' } ],
  110. [ '10', '11', '12' ]
  111. ] ) );
  112. selectNodes( [
  113. [ 0, 0, 0 ], [ 0, 0, 1 ],
  114. [ 0, 1, 0 ], [ 0, 1, 1 ],
  115. [ 0, 1, 2 ]
  116. ] );
  117. expect( command.isEnabled ).to.be.true;
  118. } );
  119. it( 'should be true if first table cell is inside selection area', () => {
  120. setData( model, modelTable( [
  121. [ { colspan: 2, rowspan: 2, contents: '00' }, '02', '03' ],
  122. [ '12', '13' ]
  123. ] ) );
  124. selectNodes( [
  125. [ 0, 0, 0 ], [ 0, 0, 1 ],
  126. [ 0, 1, 0 ]
  127. ] );
  128. expect( command.isEnabled ).to.be.true;
  129. } );
  130. it( 'should be false if any table cell with rowspan attribute extends over selection area', () => {
  131. setData( model, modelTable( [
  132. [ '00', { rowspan: 2, contents: '01' } ],
  133. [ '10' ]
  134. ] ) );
  135. selectNodes( [ [ 0, 0, 0 ], [ 0, 0, 1 ] ] );
  136. expect( command.isEnabled ).to.be.false;
  137. } );
  138. it( 'should be true if none table cell with rowspan attribute extends over selection area', () => {
  139. setData( model, modelTable( [
  140. [ '00', { rowspan: 2, contents: '01' } ],
  141. [ '10' ]
  142. ] ) );
  143. selectNodes( [
  144. [ 0, 0, 0 ], [ 0, 0, 1 ],
  145. [ 0, 1, 0 ]
  146. ] );
  147. expect( command.isEnabled ).to.be.true;
  148. } );
  149. it( 'should be false if not in a cell', () => {
  150. setData( model, '<paragraph>11[]</paragraph>' );
  151. expect( command.isEnabled ).to.be.false;
  152. } );
  153. it( 'should be false if selection has cells from header and body sections', () => {
  154. setData( model, modelTable( [
  155. [ '00[]', '01' ],
  156. [ '10', '11' ]
  157. ], { headingRows: 1 } ) );
  158. tableSelection.setCellSelection(
  159. root.getNodeByPath( [ 0, 0, 0 ] ),
  160. root.getNodeByPath( [ 0, 1, 0 ] )
  161. );
  162. expect( command.isEnabled ).to.be.false;
  163. } );
  164. it( 'should be false if more than 10 rows selected and some are in heading section', () => {
  165. setData( model, modelTable( [
  166. [ '0' ],
  167. [ '1' ],
  168. [ '2' ],
  169. [ '3' ],
  170. [ '4' ],
  171. [ '5' ],
  172. [ '6' ],
  173. [ '7' ],
  174. [ '8' ],
  175. [ '9' ],
  176. [ '10' ],
  177. [ '11' ],
  178. [ '12' ],
  179. [ '13' ],
  180. [ '14' ]
  181. ], { headingRows: 10 } ) );
  182. const tableSelection = editor.plugins.get( TableSelection );
  183. const modelRoot = model.document.getRoot();
  184. tableSelection.setCellSelection(
  185. modelRoot.getNodeByPath( [ 0, 1, 0 ] ),
  186. modelRoot.getNodeByPath( [ 0, 12, 0 ] )
  187. );
  188. expect( command.isEnabled ).to.be.false;
  189. } );
  190. it( 'should be true if selection has cells only from column headers - rows in body section', () => {
  191. setData( model, modelTable( [
  192. [ '00[]', '01', '02', '03' ],
  193. [ '10', '11', '12', '13' ]
  194. ], { headingColumns: 2 } ) );
  195. tableSelection.setCellSelection(
  196. root.getNodeByPath( [ 0, 0, 0 ] ),
  197. root.getNodeByPath( [ 0, 1, 1 ] )
  198. );
  199. expect( command.isEnabled ).to.be.true;
  200. } );
  201. it( 'should be false if selection has cells from column headers and other cells - rows in body section', () => {
  202. setData( model, modelTable( [
  203. [ '00[]', '01', '02', '03' ],
  204. [ '10', '11', '12', '13' ]
  205. ], { headingColumns: 2 } ) );
  206. tableSelection.setCellSelection(
  207. root.getNodeByPath( [ 0, 0, 0 ] ),
  208. root.getNodeByPath( [ 0, 1, 2 ] )
  209. );
  210. expect( command.isEnabled ).to.be.false;
  211. } );
  212. it( 'should be true if selection has cells only from column headers - rows in header section', () => {
  213. setData( model, modelTable( [
  214. [ '00[]', '01', '02', '03' ],
  215. [ '10', '11', '12', '13' ]
  216. ], { headingColumns: 2, headingRows: 1 } ) );
  217. tableSelection.setCellSelection(
  218. root.getNodeByPath( [ 0, 0, 0 ] ),
  219. root.getNodeByPath( [ 0, 0, 1 ] )
  220. );
  221. expect( command.isEnabled ).to.be.true;
  222. } );
  223. it( 'should be false if selection has cells only from column headers and other cells - rows in header section', () => {
  224. setData( model, modelTable( [
  225. [ '00[]', '01', '02', '03' ],
  226. [ '10', '11', '12', '13' ]
  227. ], { headingColumns: 2, headingRows: 1 } ) );
  228. tableSelection.setCellSelection(
  229. root.getNodeByPath( [ 0, 0, 0 ] ),
  230. root.getNodeByPath( [ 0, 0, 2 ] )
  231. );
  232. expect( command.isEnabled ).to.be.false;
  233. } );
  234. it( 'should be false if selection has cells from column headers, row headers and body sections', () => {
  235. setData( model, modelTable( [
  236. [ '00[]', '01', '02', '03' ],
  237. [ '10', '11', '12', '13' ]
  238. ], { headingColumns: 2, headingRows: 1 } ) );
  239. tableSelection.setCellSelection(
  240. root.getNodeByPath( [ 0, 0, 0 ] ),
  241. root.getNodeByPath( [ 0, 1, 2 ] )
  242. );
  243. expect( command.isEnabled ).to.be.false;
  244. } );
  245. } );
  246. describe( 'execute()', () => {
  247. it( 'should merge simple table cell selection', () => {
  248. setData( model, modelTable( [
  249. [ '[]00', '01' ],
  250. [ '10', '11' ]
  251. ] ) );
  252. tableSelection.setCellSelection(
  253. root.getNodeByPath( [ 0, 0, 0 ] ),
  254. root.getNodeByPath( [ 0, 0, 1 ] )
  255. );
  256. command.execute();
  257. assertEqualMarkup( getData( model ), modelTable( [
  258. [ { colspan: 2, contents: '<paragraph>[00</paragraph><paragraph>01]</paragraph>' } ],
  259. [ '10', '11' ]
  260. ] ) );
  261. } );
  262. it( 'should merge simple table cell selection and remove empty columns', () => {
  263. setData( model, modelTable( [
  264. [ '[]00', '01' ]
  265. ] ) );
  266. tableSelection.setCellSelection(
  267. root.getNodeByPath( [ 0, 0, 0 ] ),
  268. root.getNodeByPath( [ 0, 0, 1 ] )
  269. );
  270. command.execute();
  271. assertEqualMarkup( getData( model ), modelTable( [
  272. [ '<paragraph>[00</paragraph><paragraph>01]</paragraph>' ]
  273. ] ) );
  274. } );
  275. it( 'should merge selection with a cell with rowspan in the selection', () => {
  276. setData( model, modelTable( [
  277. [ '[]00', '01', '02' ],
  278. [ '10', { contents: '11', rowspan: 2 }, '12' ],
  279. [ '20', '22' ]
  280. ] ) );
  281. tableSelection.setCellSelection(
  282. root.getNodeByPath( [ 0, 1, 0 ] ),
  283. root.getNodeByPath( [ 0, 2, 1 ] )
  284. );
  285. command.execute();
  286. assertEqualMarkup( getData( model ), modelTable( [
  287. [ '00', '01', '02' ],
  288. [ {
  289. colspan: 3,
  290. contents: '<paragraph>[10</paragraph><paragraph>11</paragraph><paragraph>12</paragraph>' +
  291. '<paragraph>20</paragraph><paragraph>22]</paragraph>'
  292. } ]
  293. ] ) );
  294. } );
  295. it( 'should merge selection with a cell with rowspan in the selection (reverse selection)', () => {
  296. setData( model, modelTable( [
  297. [ '[]00', '01', '02' ],
  298. [ '10', { contents: '11', rowspan: 2 }, '12' ],
  299. [ '20', '22' ]
  300. ] ) );
  301. tableSelection.setCellSelection(
  302. root.getNodeByPath( [ 0, 2, 1 ] ),
  303. root.getNodeByPath( [ 0, 1, 0 ] )
  304. );
  305. command.execute();
  306. assertEqualMarkup( getData( model ), modelTable( [
  307. [ '00', '01', '02' ],
  308. [ {
  309. colspan: 3,
  310. contents: '<paragraph>[10</paragraph><paragraph>11</paragraph><paragraph>12</paragraph>' +
  311. '<paragraph>20</paragraph><paragraph>22]</paragraph>'
  312. } ]
  313. ] ) );
  314. } );
  315. it( 'should merge selection inside a table (properly calculate target rowspan/colspan)', () => {
  316. setData( model, modelTable( [
  317. [ '[]00', '01', '02', '03' ],
  318. [ '10', '11', { contents: '12', rowspan: 2 }, '13' ],
  319. [ '20', '21', '23' ],
  320. [ '30', '31', '32', '33' ]
  321. ] ) );
  322. tableSelection.setCellSelection(
  323. root.getNodeByPath( [ 0, 2, 1 ] ),
  324. root.getNodeByPath( [ 0, 1, 2 ] )
  325. );
  326. command.execute();
  327. assertEqualMarkup( getData( model ), modelTable( [
  328. [ '00', '01', '02', '03' ],
  329. [ '10', {
  330. colspan: 2,
  331. rowspan: 2,
  332. contents: '<paragraph>[11</paragraph><paragraph>12</paragraph><paragraph>21]</paragraph>'
  333. }, '13' ],
  334. [ '20', '23' ],
  335. [ '30', '31', '32', '33' ]
  336. ] ) );
  337. } );
  338. it( 'should merge table cells - extend colspan attribute', () => {
  339. // +----+----+----+----+
  340. // | 00 | 02 | 03 |
  341. // +----+----+----+----+
  342. // | 10 | 11 | 12 | 13 |
  343. // +----+----+----+----+
  344. // | 20 | 21 | 22 | 23 |
  345. // +----+----+----+----+
  346. setData( model, modelTable( [
  347. [ { colspan: 2, contents: '00' }, '02', '03' ],
  348. [ '10', '11', '12', '13' ],
  349. [ '20', '21', '22', '23' ]
  350. ] ) );
  351. selectNodes( [
  352. [ 0, 0, 0 ], [ 0, 0, 1 ],
  353. [ 0, 1, 0 ], [ 0, 1, 1 ], [ 0, 1, 2 ]
  354. ] );
  355. command.execute();
  356. // +----+----+----+----+
  357. // | 00 02 | 03 |
  358. // + +----+
  359. // | 10 11 12 | 13 |
  360. // +----+----+----+----+
  361. // | 20 | 21 | 22 | 23 |
  362. // +----+----+----+----+
  363. assertEqualMarkup( getData( model ), modelTable( [
  364. [ {
  365. colspan: 3,
  366. rowspan: 2,
  367. contents: '<paragraph>[00</paragraph>' +
  368. '<paragraph>02</paragraph>' +
  369. '<paragraph>10</paragraph>' +
  370. '<paragraph>11</paragraph>' +
  371. '<paragraph>12]</paragraph>'
  372. }, '03' ],
  373. [ '13' ],
  374. [ '20', '21', '22', '23' ]
  375. ] ) );
  376. } );
  377. it( 'should merge to a single paragraph - every cell is empty', () => {
  378. setData( model, modelTable( [
  379. [ '[]', '' ],
  380. [ '10', '11' ]
  381. ] ) );
  382. selectNodes( [ [ 0, 0, 0 ], [ 0, 0, 1 ] ] );
  383. command.execute();
  384. assertEqualMarkup( getData( model ), modelTable( [
  385. [ { colspan: 2, contents: '<paragraph>[]</paragraph>' } ],
  386. [ '10', '11' ]
  387. ] ) );
  388. } );
  389. it( 'should merge to a single paragraph - merged cell is empty', () => {
  390. setData( model, modelTable( [
  391. [ 'foo', '' ],
  392. [ '10', '11' ]
  393. ] ) );
  394. selectNodes( [ [ 0, 0, 0 ], [ 0, 0, 1 ] ] );
  395. command.execute();
  396. assertEqualMarkup( getData( model ), modelTable( [
  397. [ { colspan: 2, contents: '<paragraph>[foo]</paragraph>' } ],
  398. [ '10', '11' ]
  399. ] ) );
  400. } );
  401. it( 'should merge to a single paragraph - cell to which others are merged is empty', () => {
  402. setData( model, modelTable( [
  403. [ '', 'foo' ],
  404. [ '10', '11' ]
  405. ] ) );
  406. selectNodes( [ [ 0, 0, 0 ], [ 0, 0, 1 ] ] );
  407. command.execute();
  408. assertEqualMarkup( getData( model ), modelTable( [
  409. [ { colspan: 2, contents: '<paragraph>[foo]</paragraph>' } ],
  410. [ '10', '11' ]
  411. ] ) );
  412. } );
  413. it( 'should not merge empty blocks other then <paragraph> to a single block', () => {
  414. model.schema.register( 'block', {
  415. allowWhere: '$block',
  416. allowContentOf: '$block',
  417. isBlock: true
  418. } );
  419. setData( model, modelTable( [
  420. [ '<block>[]</block>', '<block></block>' ],
  421. [ '10', '11' ]
  422. ] ) );
  423. selectNodes( [ [ 0, 0, 0 ], [ 0, 0, 1 ] ] );
  424. command.execute();
  425. assertEqualMarkup( getData( model ), modelTable( [
  426. [ { colspan: 2, contents: '<block>[</block><block>]</block>' } ],
  427. [ '10', '11' ]
  428. ] ) );
  429. } );
  430. describe( 'removing empty row', () => {
  431. it( 'should remove empty row if merging all table cells from that row', () => {
  432. setData( model, modelTable( [
  433. [ '00' ],
  434. [ '10' ],
  435. [ '20' ]
  436. ] ) );
  437. selectNodes( [
  438. [ 0, 0, 0 ],
  439. [ 0, 1, 0 ],
  440. [ 0, 2, 0 ]
  441. ] );
  442. command.execute();
  443. assertEqualMarkup( getData( model ), modelTable( [
  444. [
  445. '<paragraph>[00</paragraph><paragraph>10</paragraph><paragraph>20]</paragraph>'
  446. ]
  447. ] ) );
  448. } );
  449. it( 'should decrease heading rows if some heading rows were removed', () => {
  450. setData( model, modelTable( [
  451. [ '00' ],
  452. [ '10' ],
  453. [ '20' ]
  454. ], { headingRows: 2 } ) );
  455. selectNodes( [
  456. [ 0, 0, 0 ],
  457. [ 0, 1, 0 ]
  458. ] );
  459. command.execute();
  460. assertEqualMarkup( getData( model ), modelTable( [
  461. [
  462. '<paragraph>[00</paragraph><paragraph>10]</paragraph>'
  463. ],
  464. [ '20' ]
  465. ], { headingRows: 1 } ) );
  466. } );
  467. it( 'should decrease heading rows if multiple heading rows were removed', () => {
  468. // +----+----+
  469. // | 00 | 01 |
  470. // + +----+
  471. // | | 11 |
  472. // +----+----+
  473. // | 20 | 21 |
  474. // +----+----+
  475. // | 30 | 31 |
  476. // + +----+
  477. // | | 41 |
  478. // +----+----+ <-- heading rows
  479. // | 50 | 51 |
  480. // +----+----+
  481. setData( model, modelTable( [
  482. [ { contents: '00', rowspan: 2 }, '01' ],
  483. [ '11' ],
  484. [ '20', '21' ],
  485. [ { contents: '30', rowspan: 2 }, '31' ],
  486. [ '41' ],
  487. [ '50', '51' ]
  488. ], { headingRows: 5 } ) );
  489. selectNodes( [
  490. [ 0, 0, 1 ],
  491. [ 0, 1, 0 ],
  492. [ 0, 2, 1 ],
  493. [ 0, 3, 1 ],
  494. [ 0, 4, 0 ]
  495. ] );
  496. command.execute();
  497. const contents = [ '[01', '11', '21', '31', '41]' ].map( content => `<paragraph>${ content }</paragraph>` ).join( '' );
  498. // +----+----+
  499. // | 00 | 01 |
  500. // +----+ +
  501. // | 20 | |
  502. // +----+ +
  503. // | 30 | |
  504. // +----+----+ <-- heading rows
  505. // | 50 | 51 |
  506. // +----+----+
  507. assertEqualMarkup( getData( model ), modelTable( [
  508. [ '00', { contents, rowspan: 3 } ],
  509. [ '20' ],
  510. [ '30' ],
  511. [ '50', '51' ]
  512. ], { headingRows: 3 } ) );
  513. } );
  514. it( 'should create one undo step (1 batch)', () => {
  515. setData( model, modelTable( [
  516. [ '00' ],
  517. [ '10' ],
  518. [ '20' ]
  519. ], { headingRows: 2 } ) );
  520. selectNodes( [
  521. [ 0, 0, 0 ],
  522. [ 0, 1, 0 ]
  523. ] );
  524. const createdBatches = new Set();
  525. model.on( 'applyOperation', ( evt, [ operation ] ) => {
  526. createdBatches.add( operation.batch );
  527. } );
  528. command.execute();
  529. expect( createdBatches.size ).to.equal( 1 );
  530. } );
  531. it( 'should decrease rowspan if cell overlaps removed row', () => {
  532. setData( model, modelTable( [
  533. [ '00', { rowspan: 2, contents: '01' }, { rowspan: 3, contents: '02' } ],
  534. [ '10' ],
  535. [ '20', '21' ]
  536. ] ) );
  537. selectNodes( [
  538. [ 0, 0, 0 ],
  539. [ 0, 1, 0 ],
  540. [ 0, 2, 0 ]
  541. ] );
  542. command.execute();
  543. assertEqualMarkup( getData( model ), modelTable( [
  544. [
  545. { rowspan: 2, contents: '<paragraph>[00</paragraph><paragraph>10</paragraph><paragraph>20]</paragraph>' },
  546. '01',
  547. { rowspan: 2, contents: '02' }
  548. ],
  549. [ '21' ]
  550. ] ) );
  551. } );
  552. it( 'should not decrease rowspan if cell from previous row does not overlaps removed row', () => {
  553. setData( model, modelTable( [
  554. [ '00', { rowspan: 2, contents: '01' } ],
  555. [ '10' ],
  556. [ '20', '21' ],
  557. [ '30', '31' ]
  558. ] ) );
  559. selectNodes( [
  560. [ 0, 2, 0 ], [ 0, 2, 1 ],
  561. [ 0, 3, 0 ], [ 0, 3, 1 ]
  562. ] );
  563. command.execute();
  564. assertEqualMarkup( getData( model ), modelTable( [
  565. [ '00', { rowspan: 2, contents: '01' } ],
  566. [ '10' ],
  567. [
  568. {
  569. colspan: 2,
  570. contents: '<paragraph>[20</paragraph><paragraph>21</paragraph>' +
  571. '<paragraph>30</paragraph><paragraph>31]</paragraph>'
  572. }
  573. ]
  574. ] ) );
  575. } );
  576. } );
  577. } );
  578. function selectNodes( paths ) {
  579. model.change( writer => {
  580. const ranges = paths.map( path => writer.createRangeOn( root.getNodeByPath( path ) ) );
  581. writer.setSelection( ranges );
  582. } );
  583. }
  584. } );