tableclipboard-paste.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  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. /* globals document console */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import BlockQuoteEditing from '@ckeditor/ckeditor5-block-quote/src/blockquoteediting';
  8. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  9. import HorizontalLineEditing from '@ckeditor/ckeditor5-horizontal-line/src/horizontallineediting';
  10. import ImageCaptionEditing from '@ckeditor/ckeditor5-image/src/imagecaption/imagecaptionediting';
  11. import ImageEditing from '@ckeditor/ckeditor5-image/src/image/imageediting';
  12. import ListEditing from '@ckeditor/ckeditor5-list/src/listediting';
  13. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  14. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  15. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  16. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  17. import { assertSelectedCells, modelTable, viewTable } from './_utils/utils';
  18. import TableEditing from '../src/tableediting';
  19. import TableCellPropertiesEditing from '../src/tablecellproperties/tablecellpropertiesediting';
  20. import TableWalker from '../src/tablewalker';
  21. import TableClipboard from '../src/tableclipboard';
  22. describe( 'table clipboard', () => {
  23. let editor, model, modelRoot, tableSelection, viewDocument, element;
  24. testUtils.createSinonSandbox();
  25. beforeEach( () => {
  26. element = document.createElement( 'div' );
  27. document.body.appendChild( element );
  28. } );
  29. afterEach( async () => {
  30. await editor.destroy();
  31. element.remove();
  32. } );
  33. describe( 'Clipboard integration - paste (selection scenarios)', () => {
  34. beforeEach( async () => {
  35. await createEditor();
  36. setModelData( model, modelTable( [
  37. [ '00[]', '01', '02', '03' ],
  38. [ '10', '11', '12', '13' ],
  39. [ '20', '21', '22', '23' ],
  40. [ '30', '31', '32', '33' ]
  41. ] ) );
  42. } );
  43. it( 'should be disabled in a readonly mode', () => {
  44. editor.isReadOnly = true;
  45. tableSelection.setCellSelection(
  46. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  47. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  48. );
  49. const data = pasteTable( [
  50. [ 'aa', 'ab' ],
  51. [ 'ba', 'bb' ]
  52. ] );
  53. editor.isReadOnly = false;
  54. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  55. [ '00', '01', '02', '03' ],
  56. [ '10', '11', '12', '13' ],
  57. [ '20', '21', '22', '23' ],
  58. [ '30', '31', '32', '33' ]
  59. ] ) );
  60. sinon.assert.calledOnce( data.preventDefault );
  61. } );
  62. it( 'should allow normal paste if no table cells are selected', () => {
  63. const data = {
  64. dataTransfer: createDataTransfer(),
  65. preventDefault: sinon.spy(),
  66. stopPropagation: sinon.spy()
  67. };
  68. data.dataTransfer.setData( 'text/html', '<p>foo</p>' );
  69. viewDocument.fire( 'paste', data );
  70. editor.isReadOnly = false;
  71. assertEqualMarkup( getModelData( model ), modelTable( [
  72. [ '00foo[]', '01', '02', '03' ],
  73. [ '10', '11', '12', '13' ],
  74. [ '20', '21', '22', '23' ],
  75. [ '30', '31', '32', '33' ]
  76. ] ) );
  77. } );
  78. it( 'should not alter model.insertContent if selectable is different from document selection', () => {
  79. model.change( writer => {
  80. writer.setSelection( modelRoot.getNodeByPath( [ 0, 0, 0 ] ), 0 );
  81. const selectedTableCells = model.createSelection( [
  82. model.createRangeOn( modelRoot.getNodeByPath( [ 0, 0, 0 ] ) ),
  83. model.createRangeOn( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) ),
  84. model.createRangeOn( modelRoot.getNodeByPath( [ 0, 1, 0 ] ) ),
  85. model.createRangeOn( modelRoot.getNodeByPath( [ 0, 1, 1 ] ) )
  86. ] );
  87. const tableToInsert = editor.plugins.get( 'TableUtils' ).createTable( writer, 2, 2 );
  88. for ( const { cell } of new TableWalker( tableToInsert ) ) {
  89. writer.insertText( 'foo', cell.getChild( 0 ), 0 );
  90. }
  91. model.insertContent( tableToInsert, selectedTableCells );
  92. } );
  93. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  94. [ '', '', '02', '03' ],
  95. [ '', '', '12', '13' ],
  96. [ '20', '21', '22', '23' ],
  97. [ '30', '31', '32', '33' ]
  98. ] ) );
  99. } );
  100. it( 'should not alter model.insertContent if no table pasted', () => {
  101. tableSelection.setCellSelection(
  102. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  103. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  104. );
  105. const data = {
  106. dataTransfer: createDataTransfer(),
  107. preventDefault: sinon.spy(),
  108. stopPropagation: sinon.spy()
  109. };
  110. data.dataTransfer.setData( 'text/html', '<p>foo</p>' );
  111. viewDocument.fire( 'paste', data );
  112. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  113. [ 'foo', '', '02', '03' ],
  114. [ '', '', '12', '13' ],
  115. [ '20', '21', '22', '23' ],
  116. [ '30', '31', '32', '33' ]
  117. ] ) );
  118. } );
  119. it( 'should not alter model.insertContent if mixed content is pasted (table + paragraph)', () => {
  120. tableSelection.setCellSelection(
  121. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  122. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  123. );
  124. const table = viewTable( [
  125. [ 'aa', 'ab' ],
  126. [ 'ba', 'bb' ] ] );
  127. const data = {
  128. dataTransfer: createDataTransfer(),
  129. preventDefault: sinon.spy(),
  130. stopPropagation: sinon.spy()
  131. };
  132. data.dataTransfer.setData( 'text/html', `${ table }<p>foo</p>` );
  133. viewDocument.fire( 'paste', data );
  134. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  135. [ 'foo', '', '02', '03' ],
  136. [ '', '', '12', '13' ],
  137. [ '20', '21', '22', '23' ],
  138. [ '30', '31', '32', '33' ]
  139. ] ) );
  140. } );
  141. it( 'should not alter model.insertContent if mixed content is pasted (paragraph + table)', () => {
  142. tableSelection.setCellSelection(
  143. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  144. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  145. );
  146. const table = viewTable( [
  147. [ 'aa', 'ab' ],
  148. [ 'ba', 'bb' ] ] );
  149. const data = {
  150. dataTransfer: createDataTransfer(),
  151. preventDefault: sinon.spy(),
  152. stopPropagation: sinon.spy()
  153. };
  154. data.dataTransfer.setData( 'text/html', `<p>foo</p>${ table }` );
  155. viewDocument.fire( 'paste', data );
  156. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  157. [ 'foo', '', '02', '03' ],
  158. [ '', '', '12', '13' ],
  159. [ '20', '21', '22', '23' ],
  160. [ '30', '31', '32', '33' ]
  161. ] ) );
  162. } );
  163. it( 'should not alter model.insertContent if mixed content is pasted (table + table)', () => {
  164. tableSelection.setCellSelection(
  165. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  166. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  167. );
  168. const table = viewTable( [
  169. [ 'aa', 'ab' ],
  170. [ 'ba', 'bb' ] ] );
  171. const data = {
  172. dataTransfer: createDataTransfer(),
  173. preventDefault: sinon.spy(),
  174. stopPropagation: sinon.spy()
  175. };
  176. data.dataTransfer.setData( 'text/html', `${ table }${ table }` );
  177. viewDocument.fire( 'paste', data );
  178. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  179. [ '', '', '02', '03' ],
  180. [ '', '', '12', '13' ],
  181. [ '20', '21', '22', '23' ],
  182. [ '30', '31', '32', '33' ]
  183. ] ) );
  184. } );
  185. it( 'should alter model.insertContent if selectable is a document selection', () => {
  186. tableSelection.setCellSelection(
  187. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  188. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  189. );
  190. model.change( writer => {
  191. const tableToInsert = editor.plugins.get( 'TableUtils' ).createTable( writer, 2, 2 );
  192. for ( const { cell } of new TableWalker( tableToInsert ) ) {
  193. writer.insertText( 'foo', cell.getChild( 0 ), 0 );
  194. }
  195. model.insertContent( tableToInsert, editor.model.document.selection );
  196. } );
  197. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  198. [ 'foo', 'foo', '02', '03' ],
  199. [ 'foo', 'foo', '12', '13' ],
  200. [ '20', '21', '22', '23' ],
  201. [ '30', '31', '32', '33' ]
  202. ] ) );
  203. } );
  204. describe( 'single cell selected', () => {
  205. it( 'blocks this case', () => {
  206. setModelData( model, modelTable( [
  207. [ '00', '01', '02' ],
  208. [ '10', '11', '12' ],
  209. [ '20', '21', '22' ]
  210. ] ) );
  211. tableSelection.setCellSelection(
  212. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  213. modelRoot.getNodeByPath( [ 0, 0, 0 ] )
  214. );
  215. // Catches the temporary console log in the CK_DEBUG mode.
  216. sinon.stub( console, 'log' );
  217. pasteTable( [
  218. [ 'aa', 'ab' ],
  219. [ 'ba', 'bb' ]
  220. ] );
  221. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  222. [ '00', '01', '02' ],
  223. [ '10', '11', '12' ],
  224. [ '20', '21', '22' ]
  225. ] ) );
  226. } );
  227. } );
  228. describe( 'pasted table is equal to the selected area', () => {
  229. describe( 'no spans', () => {
  230. it( 'handles simple table paste to a simple table fragment - at the beginning of a table', () => {
  231. tableSelection.setCellSelection(
  232. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  233. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  234. );
  235. pasteTable( [
  236. [ 'aa', 'ab' ],
  237. [ 'ba', 'bb' ]
  238. ] );
  239. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  240. [ 'aa', 'ab', '02', '03' ],
  241. [ 'ba', 'bb', '12', '13' ],
  242. [ '20', '21', '22', '23' ],
  243. [ '30', '31', '32', '33' ]
  244. ] ) );
  245. assertSelectedCells( model, [
  246. [ 1, 1, 0, 0 ],
  247. [ 1, 1, 0, 0 ],
  248. [ 0, 0, 0, 0 ],
  249. [ 0, 0, 0, 0 ]
  250. ] );
  251. } );
  252. it( 'handles simple table paste to a simple table fragment - at the end of a table', () => {
  253. tableSelection.setCellSelection(
  254. modelRoot.getNodeByPath( [ 0, 2, 2 ] ),
  255. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  256. );
  257. pasteTable( [
  258. [ 'aa', 'ab' ],
  259. [ 'ba', 'bb' ]
  260. ] );
  261. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  262. [ '00', '01', '02', '03' ],
  263. [ '10', '11', '12', '13' ],
  264. [ '20', '21', 'aa', 'ab' ],
  265. [ '30', '31', 'ba', 'bb' ]
  266. ] ) );
  267. assertSelectedCells( model, [
  268. [ 0, 0, 0, 0 ],
  269. [ 0, 0, 0, 0 ],
  270. [ 0, 0, 1, 1 ],
  271. [ 0, 0, 1, 1 ]
  272. ] );
  273. } );
  274. it( 'handles simple table paste to a simple table fragment - in the middle of a table', () => {
  275. tableSelection.setCellSelection(
  276. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  277. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  278. );
  279. pasteTable( [
  280. [ 'aa', 'ab' ],
  281. [ 'ba', 'bb' ]
  282. ] );
  283. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  284. [ '00', '01', '02', '03' ],
  285. [ '10', 'aa', 'ab', '13' ],
  286. [ '20', 'ba', 'bb', '23' ],
  287. [ '30', '31', '32', '33' ]
  288. ] ) );
  289. assertSelectedCells( model, [
  290. [ 0, 0, 0, 0 ],
  291. [ 0, 1, 1, 0 ],
  292. [ 0, 1, 1, 0 ],
  293. [ 0, 0, 0, 0 ]
  294. ] );
  295. } );
  296. it( 'handles simple row paste to a simple row fragment - in the middle of a table', () => {
  297. tableSelection.setCellSelection(
  298. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  299. modelRoot.getNodeByPath( [ 0, 1, 2 ] )
  300. );
  301. pasteTable( [
  302. [ 'aa', 'ab' ]
  303. ] );
  304. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  305. [ '00', '01', '02', '03' ],
  306. [ '10', 'aa', 'ab', '13' ],
  307. [ '20', '21', '22', '23' ],
  308. [ '30', '31', '32', '33' ]
  309. ] ) );
  310. assertSelectedCells( model, [
  311. [ 0, 0, 0, 0 ],
  312. [ 0, 1, 1, 0 ],
  313. [ 0, 0, 0, 0 ],
  314. [ 0, 0, 0, 0 ]
  315. ] );
  316. } );
  317. it( 'handles simple column paste to a simple column fragment - in the middle of a table', () => {
  318. tableSelection.setCellSelection(
  319. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  320. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  321. );
  322. pasteTable( [
  323. [ 'aa' ],
  324. [ 'ba' ]
  325. ] );
  326. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  327. [ '00', '01', '02', '03' ],
  328. [ '10', 'aa', '12', '13' ],
  329. [ '20', 'ba', '22', '23' ],
  330. [ '30', '31', '32', '33' ]
  331. ] ) );
  332. assertSelectedCells( model, [
  333. [ 0, 0, 0, 0 ],
  334. [ 0, 1, 0, 0 ],
  335. [ 0, 1, 0, 0 ],
  336. [ 0, 0, 0, 0 ]
  337. ] );
  338. } );
  339. it( 'handles simple table paste to a simple table fragment - whole table selected', () => {
  340. tableSelection.setCellSelection(
  341. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  342. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  343. );
  344. pasteTable( [
  345. [ 'aa', 'ab', 'ac', 'ad' ],
  346. [ 'ba', 'bb', 'bc', 'bd' ],
  347. [ 'ca', 'cb', 'cc', 'cd' ],
  348. [ 'da', 'db', 'dc', 'dd' ]
  349. ] );
  350. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  351. [ 'aa', 'ab', 'ac', 'ad' ],
  352. [ 'ba', 'bb', 'bc', 'bd' ],
  353. [ 'ca', 'cb', 'cc', 'cd' ],
  354. [ 'da', 'db', 'dc', 'dd' ]
  355. ] ) );
  356. assertSelectedCells( model, [
  357. [ 1, 1, 1, 1 ],
  358. [ 1, 1, 1, 1 ],
  359. [ 1, 1, 1, 1 ],
  360. [ 1, 1, 1, 1 ]
  361. ] );
  362. } );
  363. } );
  364. describe( 'pasted table has spans', () => {
  365. it( 'handles pasting table that has cell with colspan', () => {
  366. tableSelection.setCellSelection(
  367. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  368. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  369. );
  370. pasteTable( [
  371. [ { colspan: 2, contents: 'aa' } ],
  372. [ 'ba', 'bb' ]
  373. ] );
  374. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  375. [ '00', '01', '02', '03' ],
  376. [ '10', { colspan: 2, contents: 'aa' }, '13' ],
  377. [ '20', 'ba', 'bb', '23' ],
  378. [ '30', '31', '32', '33' ]
  379. ] ) );
  380. /* eslint-disable no-multi-spaces */
  381. assertSelectedCells( model, [
  382. [ 0, 0, 0, 0 ],
  383. [ 0, 1, 0 ],
  384. [ 0, 1, 1, 0 ],
  385. [ 0, 0, 0, 0 ]
  386. ] );
  387. /* eslint-enable no-multi-spaces */
  388. } );
  389. it( 'handles pasting table that has many cells with various colspan', () => {
  390. tableSelection.setCellSelection(
  391. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  392. modelRoot.getNodeByPath( [ 0, 3, 2 ] )
  393. );
  394. pasteTable( [
  395. [ 'aa', { colspan: 2, contents: 'ab' } ],
  396. [ { colspan: 3, contents: 'ba' } ],
  397. [ 'ca', 'cb', 'cc' ],
  398. [ { colspan: 2, contents: 'da' }, 'dc' ]
  399. ] );
  400. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  401. [ 'aa', { colspan: 2, contents: 'ab' }, '03' ],
  402. [ { colspan: 3, contents: 'ba' }, '13' ],
  403. [ 'ca', 'cb', 'cc', '23' ],
  404. [ { colspan: 2, contents: 'da' }, 'dc', '33' ]
  405. ] ) );
  406. /* eslint-disable no-multi-spaces */
  407. assertSelectedCells( model, [
  408. [ 1, 1, 0 ],
  409. [ 1, 0 ],
  410. [ 1, 1, 1, 0 ],
  411. [ 1, 1, 0 ]
  412. ] );
  413. /* eslint-enable no-multi-spaces */
  414. } );
  415. it( 'handles pasting table that has cell with rowspan', () => {
  416. tableSelection.setCellSelection(
  417. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  418. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  419. );
  420. pasteTable( [
  421. [ { rowspan: 2, contents: 'aa' }, 'ab' ],
  422. [ 'bb' ]
  423. ] );
  424. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  425. [ '00', '01', '02', '03' ],
  426. [ '10', { rowspan: 2, contents: 'aa' }, 'ab', '13' ],
  427. [ '20', 'bb', '23' ],
  428. [ '30', '31', '32', '33' ]
  429. ] ) );
  430. /* eslint-disable no-multi-spaces */
  431. assertSelectedCells( model, [
  432. [ 0, 0, 0, 0 ],
  433. [ 0, 1, 1, 0 ],
  434. [ 0, 1, 0 ],
  435. [ 0, 0, 0, 0 ]
  436. ] );
  437. /* eslint-enable no-multi-spaces */
  438. } );
  439. it( 'handles pasting table that has many cells with various rowspan', () => {
  440. tableSelection.setCellSelection(
  441. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  442. modelRoot.getNodeByPath( [ 0, 2, 3 ] )
  443. );
  444. pasteTable( [
  445. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  446. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  447. [ 'cc', 'cd' ]
  448. ] );
  449. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  450. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  451. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  452. [ 'cc', 'cd' ],
  453. [ '30', '31', '32', '33' ]
  454. ] ) );
  455. /* eslint-disable no-multi-spaces */
  456. assertSelectedCells( model, [
  457. [ 1, 1, 1, 1 ],
  458. [ 1, 1 ],
  459. [ 1, 1 ],
  460. [ 0, 0, 0, 0 ]
  461. ] );
  462. /* eslint-enable no-multi-spaces */
  463. } );
  464. it( 'handles pasting multi-spanned table', () => {
  465. setModelData( model, modelTable( [
  466. [ '00', '01', '02', '03', '04', '05' ],
  467. [ '10', '11', '12', '13', '14', '15' ],
  468. [ '20', '21', '22', '23', '24', '25' ],
  469. [ '30', '31', '32', '33', '34', '35' ],
  470. [ '40', '41', '42', '43', '44', '45' ]
  471. ] ) );
  472. tableSelection.setCellSelection(
  473. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  474. modelRoot.getNodeByPath( [ 0, 3, 4 ] )
  475. );
  476. // +----+----+----+----+----+
  477. // | aa | ac | ad | ae |
  478. // +----+----+----+----+ +
  479. // | ba | bb | |
  480. // +----+ +----+
  481. // | ca | | ce |
  482. // + +----+----+----+----+
  483. // | | db | dc | dd |
  484. // +----+----+----+----+----+
  485. pasteTable( [
  486. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 } ],
  487. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 } ],
  488. [ { contents: 'ca', rowspan: 2 }, 'ce' ],
  489. [ 'db', 'dc', { contents: 'dd', colspan: 2 } ]
  490. ] );
  491. // +----+----+----+----+----+----+
  492. // | aa | ac | ad | ae | 05 |
  493. // +----+----+----+----+ +----+
  494. // | ba | bb | | 15 |
  495. // +----+ +----+----+
  496. // | ca | | ce | 25 |
  497. // + +----+----+----+----+----+
  498. // | | db | dc | dd | 35 |
  499. // +----+----+----+----+----+----+
  500. // | 40 | 41 | 42 | 43 | 44 | 45 |
  501. // +----+----+----+----+----+----+
  502. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  503. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 }, '05' ],
  504. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 }, '15' ],
  505. [ { contents: 'ca', rowspan: 2 }, 'ce', '25' ],
  506. [ 'db', 'dc', { contents: 'dd', colspan: 2 }, '35' ],
  507. [ '40', '41', '42', '43', '44', '45' ]
  508. ] ) );
  509. /* eslint-disable no-multi-spaces */
  510. assertSelectedCells( model, [
  511. [ 1, 1, 1, 1, 0 ],
  512. [ 1, 1, 0 ],
  513. [ 1, 1, 0 ],
  514. [ 1, 1, 1, 0 ],
  515. [ 0, 0, 0, 0, 0, 0 ]
  516. ] );
  517. /* eslint-enable no-multi-spaces */
  518. } );
  519. } );
  520. describe( 'content table has spans', () => {
  521. it( 'handles pasting simple table over a table with colspans (no colspan exceeds selection)', () => {
  522. setModelData( model, modelTable( [
  523. [ '00[]', '01', '02', '03' ],
  524. [ { colspan: 3, contents: '10' }, '13' ],
  525. [ { colspan: 2, contents: '20' }, '22', '23' ],
  526. [ '30', '31', { colspan: 2, contents: '31' } ]
  527. ] ) );
  528. tableSelection.setCellSelection(
  529. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  530. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  531. );
  532. pasteTable( [
  533. [ 'aa', 'ab', 'ac' ],
  534. [ 'ba', 'bb', 'bc' ],
  535. [ 'ca', 'cb', 'cc' ]
  536. ] );
  537. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  538. [ 'aa', 'ab', 'ac', '03' ],
  539. [ 'ba', 'bb', 'bc', '13' ],
  540. [ 'ca', 'cb', 'cc', '23' ],
  541. [ '30', '31', { colspan: 2, contents: '31' } ]
  542. ] ) );
  543. /* eslint-disable no-multi-spaces */
  544. assertSelectedCells( model, [
  545. [ 1, 1, 1, 0 ],
  546. [ 1, 1, 1, 0 ],
  547. [ 1, 1, 1, 0 ],
  548. [ 0, 0, 0 ]
  549. ] );
  550. /* eslint-enable no-multi-spaces */
  551. } );
  552. it( 'handles pasting simple table over a table with rowspans (no rowspan exceeds selection)', () => {
  553. setModelData( model, modelTable( [
  554. [ '00', { rowspan: 3, contents: '01' }, { rowspan: 2, contents: '02' }, '03' ],
  555. [ { rowspan: 2, contents: '10' }, '13' ],
  556. [ '22', '23' ],
  557. [ '30', '31', '32', '33' ]
  558. ] ) );
  559. tableSelection.setCellSelection(
  560. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  561. modelRoot.getNodeByPath( [ 0, 2, 0 ] )
  562. );
  563. pasteTable( [
  564. [ 'aa', 'ab', 'ac' ],
  565. [ 'ba', 'bb', 'bc' ],
  566. [ 'ca', 'cb', 'cc' ]
  567. ] );
  568. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  569. [ 'aa', 'ab', 'ac', '03' ],
  570. [ 'ba', 'bb', 'bc', '13' ],
  571. [ 'ca', 'cb', 'cc', '23' ],
  572. [ '30', '31', '32', '33' ]
  573. ] ) );
  574. assertSelectedCells( model, [
  575. [ 1, 1, 1, 0 ],
  576. [ 1, 1, 1, 0 ],
  577. [ 1, 1, 1, 0 ],
  578. [ 0, 0, 0, 0 ]
  579. ] );
  580. } );
  581. it( 'handles pasting simple table over table with multi-spans (no span exceeds selection)', () => {
  582. // +----+----+----+----+----+----+
  583. // | 00 | 02 | 03 | 05 |
  584. // + + + +----+
  585. // | | | | 15 |
  586. // +----+----+----+ +----+
  587. // | 20 | 21 | | 25 |
  588. // + +----+----+----+----+----+
  589. // | | 31 | 32 | 34 | 35 |
  590. // +----+----+----+----+----+----+
  591. // | 40 | 41 | 42 | 43 | 44 | 45 |
  592. // +----+----+----+----+----+----+
  593. setModelData( model, modelTable( [
  594. [
  595. { contents: '00', colspan: 2, rowspan: 2 },
  596. { contents: '02', rowspan: 2 },
  597. { contents: '03', colspan: 2, rowspan: 3 },
  598. '05'
  599. ],
  600. [ '15' ],
  601. [ { contents: '20', rowspan: 2 }, { contents: '21', colspan: 2 }, '25' ],
  602. [ '31', { contents: '32', colspan: 2 }, '34', '35' ],
  603. [ '40', '41', '42', '43', '44', '45' ]
  604. ] ) );
  605. tableSelection.setCellSelection(
  606. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  607. modelRoot.getNodeByPath( [ 0, 3, 2 ] ) // Cell 34.
  608. );
  609. pasteTable( [
  610. [ 'aa', 'ab', 'ac', 'ad', 'ae' ],
  611. [ 'ba', 'bb', 'bc', 'bd', 'be' ],
  612. [ 'ca', 'cb', 'cc', 'cd', 'ce' ],
  613. [ 'da', 'db', 'dc', 'dd', 'de' ]
  614. ] );
  615. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  616. [ 'aa', 'ab', 'ac', 'ad', 'ae', '05' ],
  617. [ 'ba', 'bb', 'bc', 'bd', 'be', '15' ],
  618. [ 'ca', 'cb', 'cc', 'cd', 'ce', '25' ],
  619. [ 'da', 'db', 'dc', 'dd', 'de', '35' ],
  620. [ '40', '41', '42', '43', '44', '45' ]
  621. ] ) );
  622. assertSelectedCells( model, [
  623. [ 1, 1, 1, 1, 1, 0 ],
  624. [ 1, 1, 1, 1, 1, 0 ],
  625. [ 1, 1, 1, 1, 1, 0 ],
  626. [ 1, 1, 1, 1, 1, 0 ],
  627. [ 0, 0, 0, 0, 0, 0 ]
  628. ] );
  629. } );
  630. it( 'handles pasting simple table over a table with rowspan (rowspan before selection)', () => {
  631. // +----+----+----+----+----+
  632. // | 00 | 01 | 02 | 03 | 04 |
  633. // +----+----+----+----+----+
  634. // | 10 | 11 | 12 | 13 | 14 |
  635. // +----+ +----+----+----+
  636. // | 20 | | 22 | 23 | 24 |
  637. // +----+ +----+----+----+
  638. // | 30 | | 32 | 33 | 34 |
  639. // +----+----+----+----+----+
  640. // | 40 | 41 | 42 | 43 | 44 |
  641. // +----+----+----+----+----+
  642. setModelData( model, modelTable( [
  643. [ '00', '01', '02', '03', '04' ],
  644. [ '10', { contents: '11', rowspan: 3 }, '12', '13', '14' ],
  645. [ '20', '22', '23', '24' ],
  646. [ '30', '32', '33', '34' ],
  647. [ '40', '41', '42', '43', '44' ]
  648. ] ) );
  649. tableSelection.setCellSelection(
  650. modelRoot.getNodeByPath( [ 0, 1, 2 ] ),
  651. modelRoot.getNodeByPath( [ 0, 3, 2 ] ) // Cell 33.
  652. );
  653. pasteTable( [
  654. [ 'aa', 'ab' ],
  655. [ 'ba', 'bb' ],
  656. [ 'ca', 'cb' ]
  657. ] );
  658. // +----+----+----+----+----+
  659. // | 00 | 01 | 02 | 03 | 04 |
  660. // +----+----+----+----+----+
  661. // | 10 | 11 | aa | ab | 14 |
  662. // +----+ +----+----+----+
  663. // | 20 | | ba | bb | 24 |
  664. // +----+ +----+----+----+
  665. // | 30 | | ca | cb | 34 |
  666. // +----+----+----+----+----+
  667. // | 40 | 41 | 42 | 43 | 44 |
  668. // +----+----+----+----+----+
  669. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  670. [ '00', '01', '02', '03', '04' ],
  671. [ '10', { contents: '11', rowspan: 3 }, 'aa', 'ab', '14' ],
  672. [ '20', 'ba', 'bb', '24' ],
  673. [ '30', 'ca', 'cb', '34' ],
  674. [ '40', '41', '42', '43', '44' ]
  675. ] ) );
  676. /* eslint-disable no-multi-spaces */
  677. assertSelectedCells( model, [
  678. [ 0, 0, 0, 0, 0 ],
  679. [ 0, 0, 1, 1, 0 ],
  680. [ 0, 1, 1, 0 ],
  681. [ 0, 1, 1, 0 ],
  682. [ 0, 0, 0, 0, 0 ]
  683. ] );
  684. /* eslint-enable no-multi-spaces */
  685. } );
  686. it( 'handles pasting simple table over a table with rowspans (rowspan before selection)', () => {
  687. // +----+----+----+----+----+----+
  688. // | 00 | 01 | 02 | 03 | 04 | 05 |
  689. // +----+----+----+----+----+----+
  690. // | 10 | 12 | 13 | 14 | 15 |
  691. // +----+----+----+----+----+----+
  692. // | 20 | 23 | 24 | 25 |
  693. // +----+----+----+----+----+----+
  694. // | 30 | 31 | 32 | 33 | 34 | 35 |
  695. // +----+----+----+----+----+----+
  696. setModelData( model, modelTable( [
  697. [ '00', '01', '02', '03', '04', '05' ],
  698. [ { contents: '10', colspan: 2 }, '12', '13', '14', '15' ],
  699. [ { contents: '20', colspan: 3 }, '23', '24', '25' ],
  700. [ '30', '31', '32', '33', '34', '35' ]
  701. ] ) );
  702. tableSelection.setCellSelection(
  703. modelRoot.getNodeByPath( [ 0, 1, 2 ] ), // Cell 13.
  704. modelRoot.getNodeByPath( [ 0, 2, 2 ] ) // Cell 24.
  705. );
  706. pasteTable( [
  707. [ 'aa', 'ab' ],
  708. [ 'ba', 'bb' ]
  709. ] );
  710. // +----+----+----+----+----+----+
  711. // | 00 | 01 | 02 | 03 | 04 | 05 |
  712. // +----+----+----+----+----+----+
  713. // | 10 | 12 | aa | ab | 15 |
  714. // +----+----+----+----+----+----+
  715. // | 20 | ba | bb | 25 |
  716. // +----+----+----+----+----+----+
  717. // | 30 | 31 | 32 | 33 | 34 | 35 |
  718. // +----+----+----+----+----+----+
  719. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  720. [ '00', '01', '02', '03', '04', '05' ],
  721. [ { contents: '10', colspan: 2 }, '12', 'aa', 'ab', '15' ],
  722. [ { contents: '20', colspan: 3 }, 'ba', 'bb', '25' ],
  723. [ '30', '31', '32', '33', '34', '35' ]
  724. ] ) );
  725. /* eslint-disable no-multi-spaces */
  726. assertSelectedCells( model, [
  727. [ 0, 0, 0, 0, 0, 0 ],
  728. [ 0, 0, 1, 1, 0 ],
  729. [ 0, 1, 1, 0 ],
  730. [ 0, 0, 0, 0, 0, 0 ]
  731. ] );
  732. /* eslint-enable no-multi-spaces */
  733. } );
  734. // TODO: Skipped case - should allow pasting but no tools to compare areas (like in MergeCellsCommand).
  735. it.skip( 'handles pasting table that has cell with colspan (last row in selection is spanned)', () => {
  736. // +----+----+----+----+
  737. // | 00 | 01 | 02 | 03 |
  738. // +----+----+----+----+
  739. // | 10 | 11 | 13 |
  740. // + + +----+
  741. // | | | 23 |
  742. // +----+----+----+----+
  743. // | 30 | 31 | 32 | 33 |
  744. // +----+----+----+----+
  745. setModelData( model, modelTable( [
  746. [ '00', '01', '02', '03' ],
  747. [ { contents: '10', rowspan: 2 }, { contents: '11', colspan: 2, rowspan: 2 }, '13' ],
  748. [ '23' ],
  749. [ '30', '31', '32', '33' ]
  750. ] ) );
  751. tableSelection.setCellSelection(
  752. modelRoot.getNodeByPath( [ 0, 0, 2 ] ),
  753. modelRoot.getNodeByPath( [ 0, 1, 0 ] )
  754. );
  755. pasteTable( [
  756. [ 'aa', 'ab', 'ac' ],
  757. [ 'ba', 'bb', 'bc' ],
  758. [ 'ca', 'cb', 'cc' ]
  759. ] );
  760. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  761. [ 'aa', 'ab', 'ac', '03' ],
  762. [ 'ba', 'bb', 'bc', '13' ],
  763. [ 'ca', 'cb', 'cc', '23' ],
  764. [ '30', '31', '32', '33' ]
  765. ] ) );
  766. assertSelectedCells( model, [
  767. [ 1, 1, 1, 0 ],
  768. [ 1, 1, 1, 0 ],
  769. [ 1, 1, 1, 0 ],
  770. [ 0, 0, 0, 0 ]
  771. ] );
  772. } );
  773. } );
  774. describe( 'content and paste tables have spans', () => {
  775. it( 'handles pasting colspanned table over table with colspans (no colspan exceeds selection)', () => {
  776. setModelData( model, modelTable( [
  777. [ '00[]', '01', '02', '03' ],
  778. [ { colspan: 3, contents: '10' }, '13' ],
  779. [ { colspan: 2, contents: '20' }, '22', '23' ],
  780. [ '30', '31', { colspan: 2, contents: '31' } ]
  781. ] ) );
  782. tableSelection.setCellSelection(
  783. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  784. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  785. );
  786. pasteTable( [
  787. [ 'aa', { colspan: 2, contents: 'ab' } ],
  788. [ { colspan: 3, contents: 'ba' } ],
  789. [ 'ca', 'cb', 'cc' ]
  790. ] );
  791. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  792. [ 'aa', { colspan: 2, contents: 'ab' }, '03' ],
  793. [ { colspan: 3, contents: 'ba' }, '13' ],
  794. [ 'ca', 'cb', 'cc', '23' ],
  795. [ '30', '31', { colspan: 2, contents: '31' } ]
  796. ] ) );
  797. /* eslint-disable no-multi-spaces */
  798. assertSelectedCells( model, [
  799. [ 1, 1, 0 ],
  800. [ 1, 0 ],
  801. [ 1, 1, 1, 0 ],
  802. [ 0, 0, 0 ]
  803. ] );
  804. /* eslint-enable no-multi-spaces */
  805. } );
  806. it( 'handles pasting rowspanned table over table with rowspans (no rowspan exceeds selection)', () => {
  807. setModelData( model, modelTable( [
  808. [ { rowspan: 3, contents: '00' }, { rowspan: 2, contents: '01' }, '02', '03' ],
  809. [ { rowspan: 2, contents: '12' }, '13' ],
  810. [ '21', '23' ],
  811. [ '30', '31', '32', '33' ]
  812. ] ) );
  813. tableSelection.setCellSelection(
  814. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  815. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  816. );
  817. pasteTable( [
  818. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  819. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  820. [ 'cc', 'cd' ]
  821. ] );
  822. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  823. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  824. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  825. [ 'cc', 'cd' ],
  826. [ '30', '31', '32', '33' ]
  827. ] ) );
  828. /* eslint-disable no-multi-spaces */
  829. assertSelectedCells( model, [
  830. [ 1, 1, 1, 1 ],
  831. [ 1, 1 ],
  832. [ 1, 1 ],
  833. [ 0, 0, 0, 0 ]
  834. ] );
  835. /* eslint-enable no-multi-spaces */
  836. } );
  837. it( 'handles pasting multi-spanned table over table with multi-spans (no span exceeds selection)', () => {
  838. // +----+----+----+----+----+----+
  839. // | 00 | 02 | 03 | 05 |
  840. // + + + +----+
  841. // | | | | 15 |
  842. // +----+----+----+ +----+
  843. // | 20 | 21 | | 25 |
  844. // + +----+----+----+----+----+
  845. // | | 31 | 32 | 34 | 35 |
  846. // +----+----+----+----+----+----+
  847. // | 40 | 41 | 42 | 43 | 44 | 45 |
  848. // +----+----+----+----+----+----+
  849. setModelData( model, modelTable( [
  850. [
  851. { contents: '00', colspan: 2, rowspan: 2 },
  852. { contents: '02', rowspan: 2 },
  853. { contents: '03', colspan: 2, rowspan: 3 },
  854. '05'
  855. ],
  856. [ '15' ],
  857. [ { contents: '20', rowspan: 2 }, { contents: '21', colspan: 2 }, '25' ],
  858. [ '31', { contents: '32', colspan: 2 }, '34', '35' ],
  859. [ '40', '41', '42', '43', '44', '45' ]
  860. ] ) );
  861. tableSelection.setCellSelection(
  862. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  863. modelRoot.getNodeByPath( [ 0, 3, 2 ] )
  864. );
  865. // +----+----+----+----+----+
  866. // | aa | ac | ad | ae |
  867. // +----+----+----+----+ +
  868. // | ba | bb | |
  869. // +----+ +----+
  870. // | ca | | ce |
  871. // + +----+----+----+----+
  872. // | | db | dc | dd |
  873. // +----+----+----+----+----+
  874. pasteTable( [
  875. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 } ],
  876. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 } ],
  877. [ { contents: 'ca', rowspan: 2 }, 'ce' ],
  878. [ 'db', 'dc', { contents: 'dd', colspan: 2 } ]
  879. ] );
  880. // +----+----+----+----+----+----+
  881. // | aa | ac | ad | ae | 05 |
  882. // +----+----+----+----+ +----+
  883. // | ba | bb | | 15 |
  884. // +----+ +----+----+
  885. // | ca | | ce | 25 |
  886. // + +----+----+----+----+----+
  887. // | | db | dc | dd | 35 |
  888. // +----+----+----+----+----+----+
  889. // | 40 | 41 | 42 | 43 | 44 | 45 |
  890. // +----+----+----+----+----+----+
  891. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  892. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 }, '05' ],
  893. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 }, '15' ],
  894. [ { contents: 'ca', rowspan: 2 }, 'ce', '25' ],
  895. [ 'db', 'dc', { contents: 'dd', colspan: 2 }, '35' ],
  896. [ '40', '41', '42', '43', '44', '45' ]
  897. ] ) );
  898. /* eslint-disable no-multi-spaces */
  899. assertSelectedCells( model, [
  900. [ 1, 1, 1, 1, 0 ],
  901. [ 1, 1, 0 ],
  902. [ 1, 1, 0 ],
  903. [ 1, 1, 1, 0 ],
  904. [ 0, 0, 0, 0, 0, 0 ]
  905. ] );
  906. /* eslint-enable no-multi-spaces */
  907. } );
  908. // TODO: Skipped case - should allow pasting but no tools to compare areas (like in MergeCellsCommand).
  909. it.skip( 'handles pasting table that has cell with colspan (last row in selection is spanned)', () => {
  910. // +----+----+----+----+
  911. // | 00 | 01 | 02 | 03 |
  912. // +----+----+----+----+
  913. // | 10 | 11 | 13 |
  914. // + + +----+
  915. // | | | 23 |
  916. // +----+----+----+----+
  917. // | 30 | 31 | 32 | 33 |
  918. // +----+----+----+----+
  919. setModelData( model, modelTable( [
  920. [ '00', '01', '02', '03' ],
  921. [ { contents: '10', rowspan: 2 }, { contents: '11', colspan: 2, rowspan: 2 }, '13' ],
  922. [ '23' ],
  923. [ '30', '31', '32', '33' ]
  924. ] ) );
  925. tableSelection.setCellSelection(
  926. modelRoot.getNodeByPath( [ 0, 0, 2 ] ),
  927. modelRoot.getNodeByPath( [ 0, 1, 0 ] )
  928. );
  929. // +----+----+----+
  930. // | aa | ab | ac |
  931. // +----+----+----+
  932. // | ba | bc |
  933. // + +----+
  934. // | | cc |
  935. // +----+----+----+
  936. pasteTable( [
  937. [ 'aa', 'ab', 'ac' ],
  938. [ { contents: 'ba', colspan: 2, rowspan: 2 }, 'bc' ],
  939. [ 'cc' ]
  940. ] );
  941. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  942. [ '00', '01', '02', '03' ],
  943. [ '10', { colspan: 2, contents: 'aa' }, '13' ],
  944. [ '20', 'ba', 'bb', '23' ],
  945. [ '30', '31', '32', '33' ]
  946. ] ) );
  947. /* eslint-disable no-multi-spaces */
  948. assertSelectedCells( model, [
  949. [ 0, 0, 0, 0 ],
  950. [ 0, 1, 0 ],
  951. [ 0, 1, 1, 0 ],
  952. [ 0, 0, 0, 0 ]
  953. ] );
  954. /* eslint-enable no-multi-spaces */
  955. } );
  956. } );
  957. describe( 'non-rectangular content table', () => {
  958. it( 'should block non-rectangular selection', () => {
  959. setModelData( model, modelTable( [
  960. [ { contents: '00', colspan: 3 } ],
  961. [ '10', '11', '12' ],
  962. [ '20', '21', '22' ]
  963. ] ) );
  964. tableSelection.setCellSelection(
  965. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  966. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  967. );
  968. // Catches the temporary console log in the CK_DEBUG mode.
  969. sinon.stub( console, 'log' );
  970. pasteTable( [
  971. [ 'aa', 'ab' ],
  972. [ 'ba', 'bb' ]
  973. ] );
  974. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  975. [ { contents: '00', colspan: 3 } ],
  976. [ '10', '11', '12' ],
  977. [ '20', '21', '22' ]
  978. ] ) );
  979. } );
  980. } );
  981. } );
  982. describe( 'pasted table is bigger than the selected area', () => {
  983. describe( 'no spans', () => {
  984. it( 'handles simple table paste to a simple table fragment - at the beginning of a table', () => {
  985. tableSelection.setCellSelection(
  986. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  987. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  988. );
  989. pasteTable( [
  990. [ 'aa', 'ab', 'ac' ],
  991. [ 'ba', 'bb', 'bc' ],
  992. [ 'ca', 'cb', 'cc' ]
  993. ] );
  994. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  995. [ 'aa', 'ab', '02', '03' ],
  996. [ 'ba', 'bb', '12', '13' ],
  997. [ '20', '21', '22', '23' ],
  998. [ '30', '31', '32', '33' ]
  999. ] ) );
  1000. assertSelectedCells( model, [
  1001. [ 1, 1, 0, 0 ],
  1002. [ 1, 1, 0, 0 ],
  1003. [ 0, 0, 0, 0 ],
  1004. [ 0, 0, 0, 0 ]
  1005. ] );
  1006. } );
  1007. it( 'handles simple table paste to a simple table fragment - at the end of a table', () => {
  1008. tableSelection.setCellSelection(
  1009. modelRoot.getNodeByPath( [ 0, 2, 2 ] ),
  1010. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  1011. );
  1012. pasteTable( [
  1013. [ 'aa', 'ab', 'ac' ],
  1014. [ 'ba', 'bb', 'bc' ],
  1015. [ 'ca', 'cb', 'cc' ]
  1016. ] );
  1017. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1018. [ '00', '01', '02', '03' ],
  1019. [ '10', '11', '12', '13' ],
  1020. [ '20', '21', 'aa', 'ab' ],
  1021. [ '30', '31', 'ba', 'bb' ]
  1022. ] ) );
  1023. assertSelectedCells( model, [
  1024. [ 0, 0, 0, 0 ],
  1025. [ 0, 0, 0, 0 ],
  1026. [ 0, 0, 1, 1 ],
  1027. [ 0, 0, 1, 1 ]
  1028. ] );
  1029. } );
  1030. it( 'handles simple table paste to a simple table fragment - in the middle of a table', () => {
  1031. tableSelection.setCellSelection(
  1032. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1033. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  1034. );
  1035. pasteTable( [
  1036. [ 'aa', 'ab', 'ac' ],
  1037. [ 'ba', 'bb', 'bc' ],
  1038. [ 'ca', 'cb', 'cc' ]
  1039. ] );
  1040. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1041. [ '00', '01', '02', '03' ],
  1042. [ '10', 'aa', 'ab', '13' ],
  1043. [ '20', 'ba', 'bb', '23' ],
  1044. [ '30', '31', '32', '33' ]
  1045. ] ) );
  1046. assertSelectedCells( model, [
  1047. [ 0, 0, 0, 0 ],
  1048. [ 0, 1, 1, 0 ],
  1049. [ 0, 1, 1, 0 ],
  1050. [ 0, 0, 0, 0 ]
  1051. ] );
  1052. } );
  1053. it( 'handles paste to a simple row fragment - in the middle of a table', () => {
  1054. tableSelection.setCellSelection(
  1055. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1056. modelRoot.getNodeByPath( [ 0, 1, 2 ] )
  1057. );
  1058. pasteTable( [
  1059. [ 'aa', 'ab', 'ac' ],
  1060. [ 'ba', 'bb', 'bc' ],
  1061. [ 'ca', 'cb', 'cc' ]
  1062. ] );
  1063. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1064. [ '00', '01', '02', '03' ],
  1065. [ '10', 'aa', 'ab', '13' ],
  1066. [ '20', '21', '22', '23' ],
  1067. [ '30', '31', '32', '33' ]
  1068. ] ) );
  1069. assertSelectedCells( model, [
  1070. [ 0, 0, 0, 0 ],
  1071. [ 0, 1, 1, 0 ],
  1072. [ 0, 0, 0, 0 ],
  1073. [ 0, 0, 0, 0 ]
  1074. ] );
  1075. } );
  1076. it( 'handles paste to a simple column fragment - in the middle of a table', () => {
  1077. tableSelection.setCellSelection(
  1078. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1079. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  1080. );
  1081. pasteTable( [
  1082. [ 'aa', 'ab', 'ac' ],
  1083. [ 'ba', 'bb', 'bc' ],
  1084. [ 'ca', 'cb', 'cc' ]
  1085. ] );
  1086. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1087. [ '00', '01', '02', '03' ],
  1088. [ '10', 'aa', '12', '13' ],
  1089. [ '20', 'ba', '22', '23' ],
  1090. [ '30', '31', '32', '33' ]
  1091. ] ) );
  1092. assertSelectedCells( model, [
  1093. [ 0, 0, 0, 0 ],
  1094. [ 0, 1, 0, 0 ],
  1095. [ 0, 1, 0, 0 ],
  1096. [ 0, 0, 0, 0 ]
  1097. ] );
  1098. } );
  1099. it( 'handles simple table paste to a simple table fragment - whole table selected', () => {
  1100. tableSelection.setCellSelection(
  1101. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1102. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  1103. );
  1104. pasteTable( [
  1105. [ 'aa', 'ab', 'ac', 'ad', 'ae' ],
  1106. [ 'ba', 'bb', 'bc', 'bd', 'be' ],
  1107. [ 'ca', 'cb', 'cc', 'cd', 'ce' ],
  1108. [ 'da', 'db', 'dc', 'dd', 'de' ],
  1109. [ 'ea', 'eb', 'ec', 'ed', 'ee' ]
  1110. ] );
  1111. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1112. [ 'aa', 'ab', 'ac', 'ad' ],
  1113. [ 'ba', 'bb', 'bc', 'bd' ],
  1114. [ 'ca', 'cb', 'cc', 'cd' ],
  1115. [ 'da', 'db', 'dc', 'dd' ]
  1116. ] ) );
  1117. assertSelectedCells( model, [
  1118. [ 1, 1, 1, 1 ],
  1119. [ 1, 1, 1, 1 ],
  1120. [ 1, 1, 1, 1 ],
  1121. [ 1, 1, 1, 1 ]
  1122. ] );
  1123. } );
  1124. } );
  1125. describe( 'pasted table has spans', () => {
  1126. it( 'handles pasting table that has cell with colspan', () => {
  1127. tableSelection.setCellSelection(
  1128. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1129. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  1130. );
  1131. pasteTable( [
  1132. [ { colspan: 3, contents: 'aa' } ],
  1133. [ 'ba', 'bb', 'bc' ]
  1134. ] );
  1135. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1136. [ '00', '01', '02', '03' ],
  1137. [ '10', { colspan: 2, contents: 'aa' }, '13' ],
  1138. [ '20', 'ba', 'bb', '23' ],
  1139. [ '30', '31', '32', '33' ]
  1140. ] ) );
  1141. /* eslint-disable no-multi-spaces */
  1142. assertSelectedCells( model, [
  1143. [ 0, 0, 0, 0 ],
  1144. [ 0, 1, 0 ],
  1145. [ 0, 1, 1, 0 ],
  1146. [ 0, 0, 0, 0 ]
  1147. ] );
  1148. /* eslint-enable no-multi-spaces */
  1149. } );
  1150. it( 'handles pasting table that has many cells with various colspan', () => {
  1151. tableSelection.setCellSelection(
  1152. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1153. modelRoot.getNodeByPath( [ 0, 3, 2 ] )
  1154. );
  1155. pasteTable( [
  1156. [ 'aa', { colspan: 3, contents: 'ab' } ],
  1157. [ { colspan: 4, contents: 'ba' } ],
  1158. [ 'ca', 'cb', 'cc', 'cd' ],
  1159. [ { colspan: 2, contents: 'da' }, 'dc', 'dd' ]
  1160. ] );
  1161. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1162. [ 'aa', { colspan: 2, contents: 'ab' }, '03' ],
  1163. [ { colspan: 3, contents: 'ba' }, '13' ],
  1164. [ 'ca', 'cb', 'cc', '23' ],
  1165. [ { colspan: 2, contents: 'da' }, 'dc', '33' ]
  1166. ] ) );
  1167. /* eslint-disable no-multi-spaces */
  1168. assertSelectedCells( model, [
  1169. [ 1, 1, 0 ],
  1170. [ 1, 0 ],
  1171. [ 1, 1, 1, 0 ],
  1172. [ 1, 1, 0 ]
  1173. ] );
  1174. /* eslint-enable no-multi-spaces */
  1175. } );
  1176. it( 'handles pasting table that has cell with rowspan', () => {
  1177. tableSelection.setCellSelection(
  1178. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1179. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  1180. );
  1181. pasteTable( [
  1182. [ { rowspan: 3, contents: 'aa' }, 'ab' ],
  1183. [ 'bb' ],
  1184. [ 'cb' ]
  1185. ] );
  1186. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1187. [ '00', '01', '02', '03' ],
  1188. [ '10', { rowspan: 2, contents: 'aa' }, 'ab', '13' ],
  1189. [ '20', 'bb', '23' ],
  1190. [ '30', '31', '32', '33' ]
  1191. ] ) );
  1192. /* eslint-disable no-multi-spaces */
  1193. assertSelectedCells( model, [
  1194. [ 0, 0, 0, 0 ],
  1195. [ 0, 1, 1, 0 ],
  1196. [ 0, 1, 0 ],
  1197. [ 0, 0, 0, 0 ]
  1198. ] );
  1199. /* eslint-enable no-multi-spaces */
  1200. } );
  1201. it( 'handles pasting table that has many cells with various rowspan', () => {
  1202. tableSelection.setCellSelection(
  1203. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1204. modelRoot.getNodeByPath( [ 0, 2, 3 ] )
  1205. );
  1206. pasteTable( [
  1207. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad', 'ae' ],
  1208. [ { rowspan: 3, contents: 'ba' }, 'bd', 'be' ],
  1209. [ 'cc', 'cd', 'ce' ],
  1210. [ 'da', 'db', 'dc', 'dd' ]
  1211. ] );
  1212. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1213. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  1214. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  1215. [ 'cc', 'cd' ],
  1216. [ '30', '31', '32', '33' ]
  1217. ] ) );
  1218. /* eslint-disable no-multi-spaces */
  1219. assertSelectedCells( model, [
  1220. [ 1, 1, 1, 1 ],
  1221. [ 1, 1 ],
  1222. [ 1, 1 ],
  1223. [ 0, 0, 0, 0 ]
  1224. ] );
  1225. /* eslint-enable no-multi-spaces */
  1226. } );
  1227. it( 'handles pasting multi-spanned table', () => {
  1228. setModelData( model, modelTable( [
  1229. [ '00', '01', '02', '03', '04', '05' ],
  1230. [ '10', '11', '12', '13', '14', '15' ],
  1231. [ '20', '21', '22', '23', '24', '25' ],
  1232. [ '30', '31', '32', '33', '34', '35' ],
  1233. [ '40', '41', '42', '43', '44', '45' ]
  1234. ] ) );
  1235. tableSelection.setCellSelection(
  1236. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1237. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  1238. );
  1239. // +----+----+----+----+----+
  1240. // | aa | ac | ad | ae |
  1241. // +----+----+----+----+ +
  1242. // | ba | bb | |
  1243. // +----+ +----+
  1244. // | ca | | ce |
  1245. // + +----+----+----+----+
  1246. // | | db | dc | dd |
  1247. // +----+----+----+----+----+
  1248. pasteTable( [
  1249. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 } ],
  1250. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 } ],
  1251. [ { contents: 'ca', rowspan: 2 }, 'ce' ],
  1252. [ 'db', 'dc', { contents: 'dd', colspan: 2 } ]
  1253. ] );
  1254. // +----+----+----+----+----+----+
  1255. // | 00 | 01 | 02 | 03 | 04 | 05 |
  1256. // +----+----+----+----+----+----+
  1257. // | 10 | aa | ac | 14 | 15 |
  1258. // +----+----+----+----+----+----+
  1259. // | 20 | ba | bb | 24 | 25 |
  1260. // +----+----+ +----+----+
  1261. // | 30 | ca | | 34 | 35 |
  1262. // +----+----+----+----+----+----+
  1263. // | 40 | 41 | 42 | 43 | 44 | 45 |
  1264. // +----+----+----+----+----+----+
  1265. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1266. [ '00', '01', '02', '03', '04', '05' ],
  1267. [ '10', { contents: 'aa', colspan: 2 }, 'ac', '14', '15' ],
  1268. [ '20', 'ba', { contents: 'bb', colspan: 2, rowspan: 2 }, '24', '25' ],
  1269. [ '30', 'ca', '34', '35' ],
  1270. [ '40', '41', '42', '43', '44', '45' ]
  1271. ] ) );
  1272. /* eslint-disable no-multi-spaces */
  1273. assertSelectedCells( model, [
  1274. [ 0, 0, 0, 0, 0, 0 ],
  1275. [ 0, 1, 1, 0, 0 ],
  1276. [ 0, 1, 1, 0, 0 ],
  1277. [ 0, 1, 0, 0 ],
  1278. [ 0, 0, 0, 0, 0, 0 ]
  1279. ] );
  1280. /* eslint-enable no-multi-spaces */
  1281. } );
  1282. } );
  1283. } );
  1284. describe( 'pasted table is smaller than the selected area', () => {
  1285. it( 'blocks this case', () => {
  1286. tableSelection.setCellSelection(
  1287. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1288. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  1289. );
  1290. // Catches the temporary console log in the CK_DEBUG mode.
  1291. sinon.stub( console, 'log' );
  1292. pasteTable( [
  1293. [ 'aa', 'ab' ],
  1294. [ 'ba', 'bb' ]
  1295. ] );
  1296. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1297. [ '00', '01', '02', '03' ],
  1298. [ '10', '11', '12', '13' ],
  1299. [ '20', '21', '22', '23' ],
  1300. [ '30', '31', '32', '33' ]
  1301. ] ) );
  1302. assertSelectedCells( model, [
  1303. [ 1, 1, 1, 1 ],
  1304. [ 1, 1, 1, 1 ],
  1305. [ 1, 1, 1, 1 ],
  1306. [ 1, 1, 1, 1 ]
  1307. ] );
  1308. } );
  1309. } );
  1310. } );
  1311. describe( 'Clipboard integration - paste (content scenarios)', () => {
  1312. it( 'handles multiple paragraphs in table cell', async () => {
  1313. await createEditor();
  1314. setModelData( model, modelTable( [
  1315. [ '00', '01', '02' ],
  1316. [ '01', '11', '12' ],
  1317. [ '02', '21', '22' ]
  1318. ] ) );
  1319. tableSelection.setCellSelection(
  1320. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1321. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1322. );
  1323. pasteTable( [
  1324. [ '<p>a</p><p>a</p><p>a</p>', 'ab' ],
  1325. [ 'ba', 'bb' ]
  1326. ] );
  1327. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1328. [ '<paragraph>a</paragraph><paragraph>a</paragraph><paragraph>a</paragraph>', 'ab', '02' ],
  1329. [ 'ba', 'bb', '12' ],
  1330. [ '02', '21', '22' ]
  1331. ] ) );
  1332. } );
  1333. it( 'handles image in table cell', async () => {
  1334. await createEditor( [ ImageEditing, ImageCaptionEditing ] );
  1335. setModelData( model, modelTable( [
  1336. [ '00', '01', '02' ],
  1337. [ '01', '11', '12' ],
  1338. [ '02', '21', '22' ]
  1339. ] ) );
  1340. tableSelection.setCellSelection(
  1341. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1342. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1343. );
  1344. pasteTable( [
  1345. [ '<img src="/assets/sample.jpg">', 'ab' ],
  1346. [ 'ba', 'bb' ]
  1347. ] );
  1348. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1349. [ '<image src="/assets/sample.jpg"><caption></caption></image>', 'ab', '02' ],
  1350. [ 'ba', 'bb', '12' ],
  1351. [ '02', '21', '22' ]
  1352. ] ) );
  1353. } );
  1354. it( 'handles mixed nested content in table cell', async () => {
  1355. await createEditor( [ ImageEditing, ImageCaptionEditing, BlockQuoteEditing, HorizontalLineEditing, ListEditing ] );
  1356. setModelData( model, modelTable( [
  1357. [ '00', '01', '02' ],
  1358. [ '01', '11', '12' ],
  1359. [ '02', '21', '22' ]
  1360. ] ) );
  1361. tableSelection.setCellSelection(
  1362. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1363. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1364. );
  1365. const img = '<img src="/assets/sample.jpg">';
  1366. const list = '<ul><li>foo</li><li>bar</li></ul>';
  1367. const blockquote = `<blockquote><p>baz</p>${ list }</blockquote>`;
  1368. pasteTable( [
  1369. [ `${ img }${ list }${ blockquote }`, 'ab' ],
  1370. [ 'ba', 'bb' ]
  1371. ] );
  1372. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1373. [
  1374. '<image src="/assets/sample.jpg"><caption></caption></image>' +
  1375. '<listItem listIndent="0" listType="bulleted">foo</listItem>' +
  1376. '<listItem listIndent="0" listType="bulleted">bar</listItem>' +
  1377. '<blockQuote>' +
  1378. '<paragraph>baz</paragraph>' +
  1379. '<listItem listIndent="0" listType="bulleted">foo</listItem>' +
  1380. '<listItem listIndent="0" listType="bulleted">bar</listItem>' +
  1381. '</blockQuote>',
  1382. 'ab',
  1383. '02' ],
  1384. [ 'ba', 'bb', '12' ],
  1385. [ '02', '21', '22' ]
  1386. ] ) );
  1387. } );
  1388. it( 'handles table cell properties', async () => {
  1389. await createEditor( [ TableCellPropertiesEditing ] );
  1390. setModelData( model, modelTable( [
  1391. [ '00', '01', '02' ],
  1392. [ '01', '11', '12' ],
  1393. [ '02', '21', '22' ]
  1394. ] ) );
  1395. tableSelection.setCellSelection(
  1396. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1397. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1398. );
  1399. pasteTable( [
  1400. [ { contents: 'aa', style: 'border:1px solid #f00;background:#ba7;width:1337px' }, 'ab' ],
  1401. [ 'ba', 'bb' ]
  1402. ] );
  1403. const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
  1404. expect( tableCell.getAttribute( 'borderColor' ) ).to.deep.equal( {
  1405. top: '#f00',
  1406. right: '#f00',
  1407. bottom: '#f00',
  1408. left: '#f00'
  1409. } );
  1410. expect( tableCell.getAttribute( 'borderStyle' ) ).to.deep.equal( {
  1411. top: 'solid',
  1412. right: 'solid',
  1413. bottom: 'solid',
  1414. left: 'solid'
  1415. } );
  1416. expect( tableCell.getAttribute( 'borderWidth' ) ).to.deep.equal( {
  1417. top: '1px',
  1418. right: '1px',
  1419. bottom: '1px',
  1420. left: '1px'
  1421. } );
  1422. expect( tableCell.getAttribute( 'backgroundColor' ) ).to.equal( '#ba7' );
  1423. expect( tableCell.getAttribute( 'width' ) ).to.equal( '1337px' );
  1424. } );
  1425. it( 'discards table properties', async () => {
  1426. await createEditor( [ TableCellPropertiesEditing ] );
  1427. setModelData( model, modelTable( [
  1428. [ '00', '01', '02' ],
  1429. [ '01', '11', '12' ],
  1430. [ '02', '21', '22' ]
  1431. ] ) );
  1432. tableSelection.setCellSelection(
  1433. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1434. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1435. );
  1436. const tableStyle = 'border:1px solid #f00;background:#ba7;width:1337px';
  1437. const pastedTable = `<table style="${ tableStyle }"><tr><td>aa</td><td>ab</td></tr><tr><td>ba</td><td>bb</td></tr></table>`;
  1438. const data = {
  1439. dataTransfer: createDataTransfer(),
  1440. preventDefault: sinon.spy(),
  1441. stopPropagation: sinon.spy()
  1442. };
  1443. data.dataTransfer.setData( 'text/html', pastedTable );
  1444. viewDocument.fire( 'paste', data );
  1445. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1446. [ 'aa', 'ab', '02' ],
  1447. [ 'ba', 'bb', '12' ],
  1448. [ '02', '21', '22' ]
  1449. ] ) );
  1450. } );
  1451. } );
  1452. async function createEditor( extraPlugins = [] ) {
  1453. editor = await ClassicTestEditor.create( element, {
  1454. plugins: [ TableEditing, TableClipboard, Paragraph, Clipboard, ...extraPlugins ]
  1455. } );
  1456. model = editor.model;
  1457. modelRoot = model.document.getRoot();
  1458. viewDocument = editor.editing.view.document;
  1459. tableSelection = editor.plugins.get( 'TableSelection' );
  1460. }
  1461. function pasteTable( tableData ) {
  1462. const data = {
  1463. dataTransfer: createDataTransfer(),
  1464. preventDefault: sinon.spy(),
  1465. stopPropagation: sinon.spy()
  1466. };
  1467. data.dataTransfer.setData( 'text/html', viewTable( tableData ) );
  1468. viewDocument.fire( 'paste', data );
  1469. return data;
  1470. }
  1471. function createDataTransfer() {
  1472. const store = new Map();
  1473. return {
  1474. setData( type, data ) {
  1475. store.set( type, data );
  1476. },
  1477. getData( type ) {
  1478. return store.get( type );
  1479. }
  1480. };
  1481. }
  1482. } );