tableclipboard-paste.js 50 KB

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