tableclipboard-paste.js 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212
  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. it( 'handles pasting table that has cell with colspan (last row in selection is spanned)', () => {
  735. // +----+----+----+----+
  736. // | 00 | 01 | 02 | 03 |
  737. // +----+----+----+----+
  738. // | 10 | 11 | 13 |
  739. // + + +----+
  740. // | | | 23 |
  741. // +----+----+----+----+
  742. // | 30 | 31 | 32 | 33 |
  743. // +----+----+----+----+
  744. setModelData( model, modelTable( [
  745. [ '00', '01', '02', '03' ],
  746. [ { contents: '10', rowspan: 2 }, { contents: '11', colspan: 2, rowspan: 2 }, '13' ],
  747. [ '23' ],
  748. [ '30', '31', '32', '33' ]
  749. ] ) );
  750. // Select 02 -> 10 (selection 3x3)
  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. it( 'handles pasting table that has cell with colspan (last column in selection is spanned)', () => {
  774. // +----+----+----+----+
  775. // | 00 | 01 | 03 |
  776. // +----+----+----+----+
  777. // | 10 | 11 | 13 |
  778. // +----+ +----+
  779. // | 20 | | 23 |
  780. // +----+----+----+----+
  781. // | 30 | 31 | 32 | 33 |
  782. // +----+----+----+----+
  783. setModelData( model, modelTable( [
  784. [ '00', { contents: '01', colspan: 2 }, '03' ],
  785. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, '13' ],
  786. [ '20', '23' ],
  787. [ '30', '31', '32', '33' ]
  788. ] ) );
  789. // Select 20 -> 01 (selection 3x3)
  790. tableSelection.setCellSelection(
  791. modelRoot.getNodeByPath( [ 0, 2, 0 ] ),
  792. modelRoot.getNodeByPath( [ 0, 0, 1 ] )
  793. );
  794. pasteTable( [
  795. [ 'aa', 'ab', 'ac' ],
  796. [ 'ba', 'bb', 'bc' ],
  797. [ 'ca', 'cb', 'cc' ]
  798. ] );
  799. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  800. [ 'aa', 'ab', 'ac', '03' ],
  801. [ 'ba', 'bb', 'bc', '13' ],
  802. [ 'ca', 'cb', 'cc', '23' ],
  803. [ '30', '31', '32', '33' ]
  804. ] ) );
  805. assertSelectedCells( model, [
  806. [ 1, 1, 1, 0 ],
  807. [ 1, 1, 1, 0 ],
  808. [ 1, 1, 1, 0 ],
  809. [ 0, 0, 0, 0 ]
  810. ] );
  811. } );
  812. } );
  813. describe( 'content and paste tables have spans', () => {
  814. it( 'handles pasting colspanned table over table with colspans (no colspan exceeds selection)', () => {
  815. setModelData( model, modelTable( [
  816. [ '00[]', '01', '02', '03' ],
  817. [ { colspan: 3, contents: '10' }, '13' ],
  818. [ { colspan: 2, contents: '20' }, '22', '23' ],
  819. [ '30', '31', { colspan: 2, contents: '31' } ]
  820. ] ) );
  821. tableSelection.setCellSelection(
  822. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  823. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  824. );
  825. pasteTable( [
  826. [ 'aa', { colspan: 2, contents: 'ab' } ],
  827. [ { colspan: 3, contents: 'ba' } ],
  828. [ 'ca', 'cb', 'cc' ]
  829. ] );
  830. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  831. [ 'aa', { colspan: 2, contents: 'ab' }, '03' ],
  832. [ { colspan: 3, contents: 'ba' }, '13' ],
  833. [ 'ca', 'cb', 'cc', '23' ],
  834. [ '30', '31', { colspan: 2, contents: '31' } ]
  835. ] ) );
  836. /* eslint-disable no-multi-spaces */
  837. assertSelectedCells( model, [
  838. [ 1, 1, 0 ],
  839. [ 1, 0 ],
  840. [ 1, 1, 1, 0 ],
  841. [ 0, 0, 0 ]
  842. ] );
  843. /* eslint-enable no-multi-spaces */
  844. } );
  845. it( 'handles pasting rowspanned table over table with rowspans (no rowspan exceeds selection)', () => {
  846. setModelData( model, modelTable( [
  847. [ { rowspan: 3, contents: '00' }, { rowspan: 2, contents: '01' }, '02', '03' ],
  848. [ { rowspan: 2, contents: '12' }, '13' ],
  849. [ '21', '23' ],
  850. [ '30', '31', '32', '33' ]
  851. ] ) );
  852. tableSelection.setCellSelection(
  853. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  854. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  855. );
  856. pasteTable( [
  857. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  858. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  859. [ 'cc', 'cd' ]
  860. ] );
  861. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  862. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  863. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  864. [ 'cc', 'cd' ],
  865. [ '30', '31', '32', '33' ]
  866. ] ) );
  867. /* eslint-disable no-multi-spaces */
  868. assertSelectedCells( model, [
  869. [ 1, 1, 1, 1 ],
  870. [ 1, 1 ],
  871. [ 1, 1 ],
  872. [ 0, 0, 0, 0 ]
  873. ] );
  874. /* eslint-enable no-multi-spaces */
  875. } );
  876. it( 'handles pasting multi-spanned table over table with multi-spans (no span exceeds selection)', () => {
  877. // +----+----+----+----+----+----+
  878. // | 00 | 02 | 03 | 05 |
  879. // + + + +----+
  880. // | | | | 15 |
  881. // +----+----+----+ +----+
  882. // | 20 | 21 | | 25 |
  883. // + +----+----+----+----+----+
  884. // | | 31 | 32 | 34 | 35 |
  885. // +----+----+----+----+----+----+
  886. // | 40 | 41 | 42 | 43 | 44 | 45 |
  887. // +----+----+----+----+----+----+
  888. setModelData( model, modelTable( [
  889. [
  890. { contents: '00', colspan: 2, rowspan: 2 },
  891. { contents: '02', rowspan: 2 },
  892. { contents: '03', colspan: 2, rowspan: 3 },
  893. '05'
  894. ],
  895. [ '15' ],
  896. [ { contents: '20', rowspan: 2 }, { contents: '21', colspan: 2 }, '25' ],
  897. [ '31', { contents: '32', colspan: 2 }, '34', '35' ],
  898. [ '40', '41', '42', '43', '44', '45' ]
  899. ] ) );
  900. tableSelection.setCellSelection(
  901. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  902. modelRoot.getNodeByPath( [ 0, 3, 2 ] )
  903. );
  904. // +----+----+----+----+----+
  905. // | aa | ac | ad | ae |
  906. // +----+----+----+----+ +
  907. // | ba | bb | |
  908. // +----+ +----+
  909. // | ca | | ce |
  910. // + +----+----+----+----+
  911. // | | db | dc | dd |
  912. // +----+----+----+----+----+
  913. pasteTable( [
  914. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 } ],
  915. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 } ],
  916. [ { contents: 'ca', rowspan: 2 }, 'ce' ],
  917. [ 'db', 'dc', { contents: 'dd', colspan: 2 } ]
  918. ] );
  919. // +----+----+----+----+----+----+
  920. // | aa | ac | ad | ae | 05 |
  921. // +----+----+----+----+ +----+
  922. // | ba | bb | | 15 |
  923. // +----+ +----+----+
  924. // | ca | | ce | 25 |
  925. // + +----+----+----+----+----+
  926. // | | db | dc | dd | 35 |
  927. // +----+----+----+----+----+----+
  928. // | 40 | 41 | 42 | 43 | 44 | 45 |
  929. // +----+----+----+----+----+----+
  930. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  931. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 }, '05' ],
  932. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 }, '15' ],
  933. [ { contents: 'ca', rowspan: 2 }, 'ce', '25' ],
  934. [ 'db', 'dc', { contents: 'dd', colspan: 2 }, '35' ],
  935. [ '40', '41', '42', '43', '44', '45' ]
  936. ] ) );
  937. /* eslint-disable no-multi-spaces */
  938. assertSelectedCells( model, [
  939. [ 1, 1, 1, 1, 0 ],
  940. [ 1, 1, 0 ],
  941. [ 1, 1, 0 ],
  942. [ 1, 1, 1, 0 ],
  943. [ 0, 0, 0, 0, 0, 0 ]
  944. ] );
  945. /* eslint-enable no-multi-spaces */
  946. } );
  947. it( 'handles pasting table that has cell with colspan (last row in selection is spanned)', () => {
  948. // +----+----+----+----+
  949. // | 00 | 01 | 02 | 03 |
  950. // +----+----+----+----+
  951. // | 10 | 11 | 13 |
  952. // + + +----+
  953. // | | | 23 |
  954. // +----+----+----+----+
  955. // | 30 | 31 | 32 | 33 |
  956. // +----+----+----+----+
  957. setModelData( model, modelTable( [
  958. [ '00', '01', '02', '03' ],
  959. [ { contents: '10', rowspan: 2 }, { contents: '11', colspan: 2, rowspan: 2 }, '13' ],
  960. [ '23' ],
  961. [ '30', '31', '32', '33' ]
  962. ] ) );
  963. // Select 02 -> 10 (selection 3x3)
  964. tableSelection.setCellSelection(
  965. modelRoot.getNodeByPath( [ 0, 0, 2 ] ),
  966. modelRoot.getNodeByPath( [ 0, 1, 0 ] )
  967. );
  968. // +----+----+----+
  969. // | aa | ab | ac |
  970. // +----+----+----+
  971. // | ba | bc |
  972. // + +----+
  973. // | | cc |
  974. // +----+----+----+
  975. pasteTable( [
  976. [ 'aa', 'ab', 'ac' ],
  977. [ { contents: 'ba', colspan: 2, rowspan: 2 }, 'bc' ],
  978. [ 'cc' ]
  979. ] );
  980. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  981. [ 'aa', 'ab', 'ac', '03' ],
  982. [ { contents: 'ba', colspan: 2, rowspan: 2 }, 'bc', '13' ],
  983. [ 'cc', '23' ],
  984. [ '30', '31', '32', '33' ]
  985. ] ) );
  986. /* eslint-disable no-multi-spaces */
  987. assertSelectedCells( model, [
  988. [ 1, 1, 1, 0 ],
  989. [ 1, 1, 0 ],
  990. [ 1, 0 ],
  991. [ 0, 0, 0, 0 ]
  992. ] );
  993. /* eslint-enable no-multi-spaces */
  994. } );
  995. it( 'handles pasting table that has cell with colspan (last column in selection is spanned)', () => {
  996. // +----+----+----+----+
  997. // | 00 | 01 | 03 |
  998. // +----+----+----+----+
  999. // | 10 | 11 | 13 |
  1000. // +----+ +----+
  1001. // | 20 | | 23 |
  1002. // +----+----+----+----+
  1003. // | 30 | 31 | 32 | 33 |
  1004. // +----+----+----+----+
  1005. setModelData( model, modelTable( [
  1006. [ '00', { contents: '01', colspan: 2 }, '03' ],
  1007. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, '13' ],
  1008. [ '20', '23' ],
  1009. [ '30', '31', '32', '33' ]
  1010. ] ) );
  1011. // Select 20 -> 01 (selection 3x3)
  1012. tableSelection.setCellSelection(
  1013. modelRoot.getNodeByPath( [ 0, 2, 0 ] ),
  1014. modelRoot.getNodeByPath( [ 0, 0, 1 ] )
  1015. );
  1016. // +----+----+----+
  1017. // | aa | ab | ac |
  1018. // +----+----+----+
  1019. // | ba | bc |
  1020. // + +----+
  1021. // | | cc |
  1022. // +----+----+----+
  1023. pasteTable( [
  1024. [ 'aa', 'ab', 'ac' ],
  1025. [ { contents: 'ba', colspan: 2, rowspan: 2 }, 'bc' ],
  1026. [ 'cc' ]
  1027. ] );
  1028. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1029. [ 'aa', 'ab', 'ac', '03' ],
  1030. [ { contents: 'ba', colspan: 2, rowspan: 2 }, 'bc', '13' ],
  1031. [ 'cc', '23' ],
  1032. [ '30', '31', '32', '33' ]
  1033. ] ) );
  1034. /* eslint-disable no-multi-spaces */
  1035. assertSelectedCells( model, [
  1036. [ 1, 1, 1, 0 ],
  1037. [ 1, 1, 0 ],
  1038. [ 1, 0 ],
  1039. [ 0, 0, 0, 0 ]
  1040. ] );
  1041. /* eslint-enable no-multi-spaces */
  1042. } );
  1043. } );
  1044. describe( 'non-rectangular content table selection', () => {
  1045. it( 'should split cells outside the selected area before pasting (rowspan ends in selection)', () => {
  1046. // +----+----+----+
  1047. // | 00 | 01 | 02 |
  1048. // +----+ +----+
  1049. // | 10 | | 12 |
  1050. // +----+ +----+
  1051. // | 20 | | 22 |
  1052. // +----+ +----+
  1053. // | 30 | | 32 |
  1054. // +----+----+----+
  1055. // | 40 | 41 | 42 |
  1056. // +----+----+----+
  1057. setModelData( model, modelTable( [
  1058. [ '00', { contents: '01', rowspan: 4 }, '02' ],
  1059. [ '10', '12' ],
  1060. [ '20', '22' ],
  1061. [ '30', '32' ],
  1062. [ '40', '41', '42' ]
  1063. ] ) );
  1064. // Select 20 -> 32
  1065. tableSelection.setCellSelection(
  1066. modelRoot.getNodeByPath( [ 0, 2, 0 ] ),
  1067. modelRoot.getNodeByPath( [ 0, 3, 1 ] )
  1068. );
  1069. pasteTable( [
  1070. [ 'aa', 'ab', 'ac' ],
  1071. [ 'ba', 'bb', 'bc' ]
  1072. ] );
  1073. // +----+----+----+
  1074. // | 00 | 01 | 02 |
  1075. // +----+ +----+
  1076. // | 10 | | 12 |
  1077. // +----+----+----+
  1078. // | aa | ab | ac |
  1079. // +----+----+----+
  1080. // | ba | bb | bc |
  1081. // +----+----+----+
  1082. // | 40 | 41 | 42 |
  1083. // +----+----+----+
  1084. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1085. [ '00', { contents: '01', rowspan: 2 }, '02' ],
  1086. [ '10', '12' ],
  1087. [ 'aa', 'ab', 'ac' ],
  1088. [ 'ba', 'bb', 'bc' ],
  1089. [ '40', '41', '42' ]
  1090. ] ) );
  1091. } );
  1092. it( 'should split cells outside the selected area before pasting (rowspan ends after the selection)', () => {
  1093. // +----+----+----+
  1094. // | 00 | 01 | 02 |
  1095. // +----+ +----+
  1096. // | 10 | | 12 |
  1097. // +----+ +----+
  1098. // | 20 | | 22 |
  1099. // +----+ +----+
  1100. // | 30 | | 32 |
  1101. // +----+----+----+
  1102. // | 40 | 41 | 42 |
  1103. // +----+----+----+
  1104. setModelData( model, modelTable( [
  1105. [ '00', { contents: '01', rowspan: 4 }, '02' ],
  1106. [ '10', '12' ],
  1107. [ '20', '22' ],
  1108. [ '30', '32' ],
  1109. [ '40', '41', '42' ]
  1110. ] ) );
  1111. // Select 10 -> 22
  1112. tableSelection.setCellSelection(
  1113. modelRoot.getNodeByPath( [ 0, 1, 0 ] ),
  1114. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  1115. );
  1116. pasteTable( [
  1117. [ 'aa', 'ab', 'ac' ],
  1118. [ 'ba', 'bb', 'bc' ]
  1119. ] );
  1120. // +----+----+----+
  1121. // | 00 | 01 | 02 |
  1122. // +----+----+----+
  1123. // | aa | ab | ac |
  1124. // +----+----+----+
  1125. // | ba | bb | bc |
  1126. // +----+----+----+
  1127. // | 30 | | 32 |
  1128. // +----+----+----+
  1129. // | 40 | 41 | 42 |
  1130. // +----+----+----+
  1131. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1132. [ '00', '01', '02' ],
  1133. [ 'aa', 'ab', 'ac' ],
  1134. [ 'ba', 'bb', 'bc' ],
  1135. [ '30', '', '32' ],
  1136. [ '40', '41', '42' ]
  1137. ] ) );
  1138. } );
  1139. it( 'should split cells inside the selected area before pasting (rowspan ends after the selection)', () => {
  1140. // +----+----+----+
  1141. // | 00 | 01 | 02 |
  1142. // +----+ +----+
  1143. // | 10 | | 12 |
  1144. // +----+ +----+
  1145. // | 20 | | 22 |
  1146. // +----+ +----+
  1147. // | 30 | | 32 |
  1148. // +----+----+----+
  1149. // | 40 | 41 | 42 |
  1150. // +----+----+----+
  1151. setModelData( model, modelTable( [
  1152. [ '00', { contents: '01', rowspan: 4 }, '02' ],
  1153. [ '10', '12' ],
  1154. [ '20', '22' ],
  1155. [ '30', '32' ],
  1156. [ '40', '41', '42' ]
  1157. ] ) );
  1158. // Select 00 -> 12
  1159. tableSelection.setCellSelection(
  1160. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1161. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1162. );
  1163. pasteTable( [
  1164. [ 'aa', 'ab', 'ac' ],
  1165. [ 'ba', 'bb', 'bc' ]
  1166. ] );
  1167. // +----+----+----+
  1168. // | aa | ab | ac |
  1169. // +----+----+----+
  1170. // | ba | bb | bc |
  1171. // +----+----+----+
  1172. // | 20 | | 22 |
  1173. // +----+ +----+
  1174. // | 30 | | 32 |
  1175. // +----+----+----+
  1176. // | 40 | 41 | 42 |
  1177. // +----+----+----+
  1178. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1179. [ 'aa', 'ab', 'ac' ],
  1180. [ 'ba', 'bb', 'bc' ],
  1181. [ '20', { rowspan: 2, contents: '' }, '22' ],
  1182. [ '30', '32' ],
  1183. [ '40', '41', '42' ]
  1184. ] ) );
  1185. } );
  1186. it( 'should split cells outside the selected area before pasting (colspan ends in selection)', () => {
  1187. // +----+----+----+----+----+
  1188. // | 00 | 01 | 02 | 03 | 04 |
  1189. // +----+----+----+----+----+
  1190. // | 10 | 14 |
  1191. // +----+----+----+----+----+
  1192. // | 20 | 21 | 22 | 23 | 24 |
  1193. // +----+----+----+----+----+
  1194. setModelData( model, modelTable( [
  1195. [ '00', '01', '02', '03', '04' ],
  1196. [ { contents: '10', colspan: 4 }, '14' ],
  1197. [ '20', '21', '22', '23', '24' ]
  1198. ] ) );
  1199. // Select 02 -> 23
  1200. tableSelection.setCellSelection(
  1201. modelRoot.getNodeByPath( [ 0, 0, 2 ] ),
  1202. modelRoot.getNodeByPath( [ 0, 2, 3 ] )
  1203. );
  1204. pasteTable( [
  1205. [ 'aa', 'ab' ],
  1206. [ 'ba', 'bb' ],
  1207. [ 'ca', 'cb' ]
  1208. ] );
  1209. // +----+----+----+----+----+
  1210. // | 00 | 01 | aa | ab | 04 |
  1211. // +----+----+----+----+----+
  1212. // | 10 | ba | bb | 14 |
  1213. // +----+----+----+----+----+
  1214. // | 20 | 21 | ca | cb | 24 |
  1215. // +----+----+----+----+----+
  1216. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1217. [ '00', '01', 'aa', 'ab', '04' ],
  1218. [ { contents: '10', colspan: 2 }, 'ba', 'bb', '14' ],
  1219. [ '20', '21', 'ca', 'cb', '24' ]
  1220. ] ) );
  1221. } );
  1222. it( 'should split cells outside the selected area before pasting (colspan ends after the selection)', () => {
  1223. // +----+----+----+----+----+
  1224. // | 00 | 01 | 02 | 03 | 04 |
  1225. // +----+----+----+----+----+
  1226. // | 10 | 14 |
  1227. // +----+----+----+----+----+
  1228. // | 20 | 21 | 22 | 23 | 24 |
  1229. // +----+----+----+----+----+
  1230. setModelData( model, modelTable( [
  1231. [ '00', '01', '02', '03', '04' ],
  1232. [ { contents: '10', colspan: 4 }, '14' ],
  1233. [ '20', '21', '22', '23', '24' ]
  1234. ] ) );
  1235. // Select 01 -> 22
  1236. tableSelection.setCellSelection(
  1237. modelRoot.getNodeByPath( [ 0, 0, 1 ] ),
  1238. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  1239. );
  1240. pasteTable( [
  1241. [ 'aa', 'ab' ],
  1242. [ 'ba', 'bb' ],
  1243. [ 'ca', 'cb' ]
  1244. ] );
  1245. // +----+----+----+----+----+
  1246. // | 00 | aa | ab | 03 | 04 |
  1247. // +----+----+----+----+----+
  1248. // | 10 | ba | bb | | 14 |
  1249. // +----+----+----+----+----+
  1250. // | 20 | ca | cb | 23 | 24 |
  1251. // +----+----+----+----+----+
  1252. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1253. [ '00', 'aa', 'ab', '03', '04' ],
  1254. [ '10', 'ba', 'bb', '', '14' ],
  1255. [ '20', 'ca', 'cb', '23', '24' ]
  1256. ] ) );
  1257. } );
  1258. it( 'should split cells inside the selected area before pasting (colspan ends after the selection)', () => {
  1259. // +----+----+----+----+----+
  1260. // | 00 | 01 | 02 | 03 | 04 |
  1261. // +----+----+----+----+----+
  1262. // | 10 | 14 |
  1263. // +----+----+----+----+----+
  1264. // | 20 | 21 | 22 | 23 | 24 |
  1265. // +----+----+----+----+----+
  1266. setModelData( model, modelTable( [
  1267. [ '00', '01', '02', '03', '04' ],
  1268. [ { contents: '10', colspan: 4 }, '14' ],
  1269. [ '20', '21', '22', '23', '24' ]
  1270. ] ) );
  1271. // Select 00 -> 21
  1272. tableSelection.setCellSelection(
  1273. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1274. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  1275. );
  1276. pasteTable( [
  1277. [ 'aa', 'ab' ],
  1278. [ 'ba', 'bb' ],
  1279. [ 'ca', 'cb' ]
  1280. ] );
  1281. // +----+----+----+----+----+
  1282. // | aa | ab | 02 | 03 | 04 |
  1283. // +----+----+----+----+----+
  1284. // | ba | bb | | 14 |
  1285. // +----+----+----+----+----+
  1286. // | ca | cb | 22 | 23 | 24 |
  1287. // +----+----+----+----+----+
  1288. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1289. [ 'aa', 'ab', '02', '03', '04' ],
  1290. [ 'ba', 'bb', { colspan: 2, contents: '' }, '14' ],
  1291. [ 'ca', 'cb', '22', '23', '24' ]
  1292. ] ) );
  1293. } );
  1294. it( 'should split cells anchored outside selection rectangle that overlaps selection (above selection)', () => {
  1295. // +----+----+----+
  1296. // | 00 | 02 |
  1297. // + +----+
  1298. // | | 12 |
  1299. // +----+----+----+
  1300. // | 20 | 21 | 22 |
  1301. // +----+----+----+
  1302. setModelData( model, modelTable( [
  1303. [ { contents: '00', colspan: 2, rowspan: 2 }, '02' ],
  1304. [ '12' ],
  1305. [ '20', '21', '22' ]
  1306. ] ) );
  1307. // Select 21 -> 12
  1308. tableSelection.setCellSelection(
  1309. modelRoot.getNodeByPath( [ 0, 2, 1 ] ),
  1310. modelRoot.getNodeByPath( [ 0, 1, 0 ] )
  1311. );
  1312. pasteTable( [
  1313. [ 'aa', 'ab' ],
  1314. [ 'ba', 'bb' ]
  1315. ] );
  1316. // +----+----+----+
  1317. // | 00 | | 02 |
  1318. // + +----+----+
  1319. // | | aa | ab |
  1320. // +----+----+----+
  1321. // | 20 | ba | bb |
  1322. // +----+----+----+
  1323. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1324. [ { contents: '00', rowspan: 2 }, '', '02' ],
  1325. [ 'aa', 'ab' ],
  1326. [ '20', 'ba', 'bb' ]
  1327. ] ) );
  1328. } );
  1329. it( 'should split cells anchored outside selection rectangle that overlaps selection (below selection)', () => {
  1330. // +----+----+----+
  1331. // | 00 | 01 | 02 |
  1332. // +----+----+----+
  1333. // | 10 | 12 |
  1334. // + +----+
  1335. // | | 22 |
  1336. // +----+----+----+
  1337. setModelData( model, modelTable( [
  1338. [ '00', '01', '02' ],
  1339. [ { contents: '10', colspan: 2, rowspan: 2 }, '12' ],
  1340. [ '22' ]
  1341. ] ) );
  1342. // Select 01 -> 12
  1343. tableSelection.setCellSelection(
  1344. modelRoot.getNodeByPath( [ 0, 0, 1 ] ),
  1345. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1346. );
  1347. pasteTable( [
  1348. [ 'aa', 'ab' ],
  1349. [ 'ba', 'bb' ]
  1350. ] );
  1351. // +----+----+----+
  1352. // | 00 | aa | ab |
  1353. // +----+----+----+
  1354. // | 10 | ba | bb |
  1355. // + +----+----+
  1356. // | | | 22 |
  1357. // +----+----+----+
  1358. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1359. [ '00', 'aa', 'ab' ],
  1360. [ { contents: '10', rowspan: 2 }, 'ba', 'bb' ],
  1361. [ '', '22' ]
  1362. ] ) );
  1363. } );
  1364. it( 'should properly handle complex case', () => {
  1365. // +----+----+----+----+----+----+----+
  1366. // | 00 | 03 | 04 |
  1367. // + + +----+----+----+
  1368. // | | | 14 | 15 | 16 |
  1369. // + + +----+----+----+
  1370. // | | | 24 |
  1371. // +----+----+----+----+----+----+----+
  1372. // | 30 | 31 | 33 | 34 | 35 | 36 |
  1373. // + +----+----+ +----+----+----+
  1374. // | | 41 | 42 | | 44 | 45 |
  1375. // + +----+----+ +----+ +
  1376. // | | 51 | 52 | | 54 | |
  1377. // +----+----+----+ +----+ +
  1378. // | 60 | 61 | 62 | | 64 | |
  1379. // +----+----+----+----+----+----+----+
  1380. setModelData( model, modelTable( [
  1381. [ { contents: '00', colspan: 3, rowspan: 3 }, { contents: '03', rowspan: 3 }, { colspan: 3, contents: '04' } ],
  1382. [ '14', '15', '16' ],
  1383. [ { contents: '24', colspan: 3 } ],
  1384. [
  1385. { contents: '30', rowspan: 3 },
  1386. { contents: '31', colspan: 2 },
  1387. { contents: '33', rowspan: 4 },
  1388. '34', '35', '36'
  1389. ],
  1390. [ '41', '42', '44', { contents: '45', colspan: 2, rowspan: 3 } ],
  1391. [ '51', '52', '54' ],
  1392. [ '60', '61', '62', '64' ]
  1393. ] ) );
  1394. // Select 42 -> 24 (3x3 selection)
  1395. tableSelection.setCellSelection(
  1396. modelRoot.getNodeByPath( [ 0, 4, 1 ] ),
  1397. modelRoot.getNodeByPath( [ 0, 2, 0 ] )
  1398. );
  1399. pasteTable( [
  1400. [ 'aa', 'ab', 'ac' ],
  1401. [ 'ba', 'bb', 'bc' ],
  1402. [ 'ca', 'cb', 'cc' ]
  1403. ] );
  1404. // +----+----+----+----+----+----+----+
  1405. // | 00 | | 03 | 04 |
  1406. // + + + +----+----+----+
  1407. // | | | | 14 | 15 | 16 |
  1408. // + +----+----+----+----+----+
  1409. // | | aa | ab | ac | |
  1410. // +----+----+----+----+----+----+----+
  1411. // | 30 | 31 | ba | bb | bc | 35 | 36 |
  1412. // + +----+----+----+----+----+----+
  1413. // | | 41 | ca | cb | cc | 45 |
  1414. // + +----+----+----+----+ +
  1415. // | | 51 | 52 | | 54 | |
  1416. // +----+----+----+ +----+ +
  1417. // | 60 | 61 | 62 | | 64 | |
  1418. // +----+----+----+----+----+----+----+
  1419. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1420. [
  1421. { contents: '00', colspan: 2, rowspan: 3 },
  1422. { contents: '', rowspan: 2 },
  1423. { contents: '03', rowspan: 2 },
  1424. { contents: '04', colspan: 3 }
  1425. ],
  1426. [ '14', '15', '16' ],
  1427. [ 'aa', 'ab', 'ac', { contents: '', colspan: 2 } ],
  1428. [ { contents: '30', rowspan: 3 }, '31', 'ba', 'bb', 'bc', '35', '36' ],
  1429. [ '41', 'ca', 'cb', 'cc', { contents: '45', colspan: 2, rowspan: 3 } ],
  1430. [ '51', '52', { contents: '', rowspan: 2 }, '54' ],
  1431. [ '60', '61', '62', '64' ]
  1432. ] ) );
  1433. } );
  1434. } );
  1435. } );
  1436. describe( 'pasted table is bigger than the selected area', () => {
  1437. describe( 'no spans', () => {
  1438. it( 'handles simple table paste to a simple table fragment - at the beginning of a table', () => {
  1439. tableSelection.setCellSelection(
  1440. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1441. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1442. );
  1443. pasteTable( [
  1444. [ 'aa', 'ab', 'ac' ],
  1445. [ 'ba', 'bb', 'bc' ],
  1446. [ 'ca', 'cb', 'cc' ]
  1447. ] );
  1448. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1449. [ 'aa', 'ab', '02', '03' ],
  1450. [ 'ba', 'bb', '12', '13' ],
  1451. [ '20', '21', '22', '23' ],
  1452. [ '30', '31', '32', '33' ]
  1453. ] ) );
  1454. assertSelectedCells( model, [
  1455. [ 1, 1, 0, 0 ],
  1456. [ 1, 1, 0, 0 ],
  1457. [ 0, 0, 0, 0 ],
  1458. [ 0, 0, 0, 0 ]
  1459. ] );
  1460. } );
  1461. it( 'handles simple table paste to a simple table fragment - at the end of a table', () => {
  1462. tableSelection.setCellSelection(
  1463. modelRoot.getNodeByPath( [ 0, 2, 2 ] ),
  1464. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  1465. );
  1466. pasteTable( [
  1467. [ 'aa', 'ab', 'ac' ],
  1468. [ 'ba', 'bb', 'bc' ],
  1469. [ 'ca', 'cb', 'cc' ]
  1470. ] );
  1471. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1472. [ '00', '01', '02', '03' ],
  1473. [ '10', '11', '12', '13' ],
  1474. [ '20', '21', 'aa', 'ab' ],
  1475. [ '30', '31', 'ba', 'bb' ]
  1476. ] ) );
  1477. assertSelectedCells( model, [
  1478. [ 0, 0, 0, 0 ],
  1479. [ 0, 0, 0, 0 ],
  1480. [ 0, 0, 1, 1 ],
  1481. [ 0, 0, 1, 1 ]
  1482. ] );
  1483. } );
  1484. it( 'handles simple table paste to a simple table fragment - in the middle of a table', () => {
  1485. tableSelection.setCellSelection(
  1486. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1487. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  1488. );
  1489. pasteTable( [
  1490. [ 'aa', 'ab', 'ac' ],
  1491. [ 'ba', 'bb', 'bc' ],
  1492. [ 'ca', 'cb', 'cc' ]
  1493. ] );
  1494. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1495. [ '00', '01', '02', '03' ],
  1496. [ '10', 'aa', 'ab', '13' ],
  1497. [ '20', 'ba', 'bb', '23' ],
  1498. [ '30', '31', '32', '33' ]
  1499. ] ) );
  1500. assertSelectedCells( model, [
  1501. [ 0, 0, 0, 0 ],
  1502. [ 0, 1, 1, 0 ],
  1503. [ 0, 1, 1, 0 ],
  1504. [ 0, 0, 0, 0 ]
  1505. ] );
  1506. } );
  1507. it( 'handles paste to a simple row fragment - in the middle of a table', () => {
  1508. tableSelection.setCellSelection(
  1509. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1510. modelRoot.getNodeByPath( [ 0, 1, 2 ] )
  1511. );
  1512. pasteTable( [
  1513. [ 'aa', 'ab', 'ac' ],
  1514. [ 'ba', 'bb', 'bc' ],
  1515. [ 'ca', 'cb', 'cc' ]
  1516. ] );
  1517. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1518. [ '00', '01', '02', '03' ],
  1519. [ '10', 'aa', 'ab', '13' ],
  1520. [ '20', '21', '22', '23' ],
  1521. [ '30', '31', '32', '33' ]
  1522. ] ) );
  1523. assertSelectedCells( model, [
  1524. [ 0, 0, 0, 0 ],
  1525. [ 0, 1, 1, 0 ],
  1526. [ 0, 0, 0, 0 ],
  1527. [ 0, 0, 0, 0 ]
  1528. ] );
  1529. } );
  1530. it( 'handles paste to a simple column fragment - in the middle of a table', () => {
  1531. tableSelection.setCellSelection(
  1532. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1533. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  1534. );
  1535. pasteTable( [
  1536. [ 'aa', 'ab', 'ac' ],
  1537. [ 'ba', 'bb', 'bc' ],
  1538. [ 'ca', 'cb', 'cc' ]
  1539. ] );
  1540. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1541. [ '00', '01', '02', '03' ],
  1542. [ '10', 'aa', '12', '13' ],
  1543. [ '20', 'ba', '22', '23' ],
  1544. [ '30', '31', '32', '33' ]
  1545. ] ) );
  1546. assertSelectedCells( model, [
  1547. [ 0, 0, 0, 0 ],
  1548. [ 0, 1, 0, 0 ],
  1549. [ 0, 1, 0, 0 ],
  1550. [ 0, 0, 0, 0 ]
  1551. ] );
  1552. } );
  1553. it( 'handles simple table paste to a simple table fragment - whole table selected', () => {
  1554. tableSelection.setCellSelection(
  1555. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1556. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  1557. );
  1558. pasteTable( [
  1559. [ 'aa', 'ab', 'ac', 'ad', 'ae' ],
  1560. [ 'ba', 'bb', 'bc', 'bd', 'be' ],
  1561. [ 'ca', 'cb', 'cc', 'cd', 'ce' ],
  1562. [ 'da', 'db', 'dc', 'dd', 'de' ],
  1563. [ 'ea', 'eb', 'ec', 'ed', 'ee' ]
  1564. ] );
  1565. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1566. [ 'aa', 'ab', 'ac', 'ad' ],
  1567. [ 'ba', 'bb', 'bc', 'bd' ],
  1568. [ 'ca', 'cb', 'cc', 'cd' ],
  1569. [ 'da', 'db', 'dc', 'dd' ]
  1570. ] ) );
  1571. assertSelectedCells( model, [
  1572. [ 1, 1, 1, 1 ],
  1573. [ 1, 1, 1, 1 ],
  1574. [ 1, 1, 1, 1 ],
  1575. [ 1, 1, 1, 1 ]
  1576. ] );
  1577. } );
  1578. } );
  1579. describe( 'pasted table has spans', () => {
  1580. it( 'handles pasting table that has cell with colspan', () => {
  1581. tableSelection.setCellSelection(
  1582. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1583. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  1584. );
  1585. pasteTable( [
  1586. [ { colspan: 3, contents: 'aa' } ],
  1587. [ 'ba', 'bb', 'bc' ]
  1588. ] );
  1589. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1590. [ '00', '01', '02', '03' ],
  1591. [ '10', { colspan: 2, contents: 'aa' }, '13' ],
  1592. [ '20', 'ba', 'bb', '23' ],
  1593. [ '30', '31', '32', '33' ]
  1594. ] ) );
  1595. /* eslint-disable no-multi-spaces */
  1596. assertSelectedCells( model, [
  1597. [ 0, 0, 0, 0 ],
  1598. [ 0, 1, 0 ],
  1599. [ 0, 1, 1, 0 ],
  1600. [ 0, 0, 0, 0 ]
  1601. ] );
  1602. /* eslint-enable no-multi-spaces */
  1603. } );
  1604. it( 'handles pasting table that has many cells with various colspan', () => {
  1605. tableSelection.setCellSelection(
  1606. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1607. modelRoot.getNodeByPath( [ 0, 3, 2 ] )
  1608. );
  1609. pasteTable( [
  1610. [ 'aa', { colspan: 3, contents: 'ab' } ],
  1611. [ { colspan: 4, contents: 'ba' } ],
  1612. [ 'ca', 'cb', 'cc', 'cd' ],
  1613. [ { colspan: 2, contents: 'da' }, 'dc', 'dd' ]
  1614. ] );
  1615. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1616. [ 'aa', { colspan: 2, contents: 'ab' }, '03' ],
  1617. [ { colspan: 3, contents: 'ba' }, '13' ],
  1618. [ 'ca', 'cb', 'cc', '23' ],
  1619. [ { colspan: 2, contents: 'da' }, 'dc', '33' ]
  1620. ] ) );
  1621. /* eslint-disable no-multi-spaces */
  1622. assertSelectedCells( model, [
  1623. [ 1, 1, 0 ],
  1624. [ 1, 0 ],
  1625. [ 1, 1, 1, 0 ],
  1626. [ 1, 1, 0 ]
  1627. ] );
  1628. /* eslint-enable no-multi-spaces */
  1629. } );
  1630. it( 'handles pasting table that has cell with rowspan', () => {
  1631. tableSelection.setCellSelection(
  1632. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1633. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  1634. );
  1635. pasteTable( [
  1636. [ { rowspan: 3, contents: 'aa' }, 'ab' ],
  1637. [ 'bb' ],
  1638. [ 'cb' ]
  1639. ] );
  1640. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1641. [ '00', '01', '02', '03' ],
  1642. [ '10', { rowspan: 2, contents: 'aa' }, 'ab', '13' ],
  1643. [ '20', 'bb', '23' ],
  1644. [ '30', '31', '32', '33' ]
  1645. ] ) );
  1646. /* eslint-disable no-multi-spaces */
  1647. assertSelectedCells( model, [
  1648. [ 0, 0, 0, 0 ],
  1649. [ 0, 1, 1, 0 ],
  1650. [ 0, 1, 0 ],
  1651. [ 0, 0, 0, 0 ]
  1652. ] );
  1653. /* eslint-enable no-multi-spaces */
  1654. } );
  1655. it( 'handles pasting table that has many cells with various rowspan', () => {
  1656. tableSelection.setCellSelection(
  1657. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1658. modelRoot.getNodeByPath( [ 0, 2, 3 ] )
  1659. );
  1660. pasteTable( [
  1661. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad', 'ae' ],
  1662. [ { rowspan: 3, contents: 'ba' }, 'bd', 'be' ],
  1663. [ 'cc', 'cd', 'ce' ],
  1664. [ 'da', 'db', 'dc', 'dd' ]
  1665. ] );
  1666. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1667. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  1668. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  1669. [ 'cc', 'cd' ],
  1670. [ '30', '31', '32', '33' ]
  1671. ] ) );
  1672. /* eslint-disable no-multi-spaces */
  1673. assertSelectedCells( model, [
  1674. [ 1, 1, 1, 1 ],
  1675. [ 1, 1 ],
  1676. [ 1, 1 ],
  1677. [ 0, 0, 0, 0 ]
  1678. ] );
  1679. /* eslint-enable no-multi-spaces */
  1680. } );
  1681. it( 'handles pasting multi-spanned table', () => {
  1682. setModelData( model, modelTable( [
  1683. [ '00', '01', '02', '03', '04', '05' ],
  1684. [ '10', '11', '12', '13', '14', '15' ],
  1685. [ '20', '21', '22', '23', '24', '25' ],
  1686. [ '30', '31', '32', '33', '34', '35' ],
  1687. [ '40', '41', '42', '43', '44', '45' ]
  1688. ] ) );
  1689. tableSelection.setCellSelection(
  1690. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1691. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  1692. );
  1693. // +----+----+----+----+----+
  1694. // | aa | ac | ad | ae |
  1695. // +----+----+----+----+ +
  1696. // | ba | bb | |
  1697. // +----+ +----+
  1698. // | ca | | ce |
  1699. // + +----+----+----+----+
  1700. // | | db | dc | dd |
  1701. // +----+----+----+----+----+
  1702. pasteTable( [
  1703. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 } ],
  1704. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 } ],
  1705. [ { contents: 'ca', rowspan: 2 }, 'ce' ],
  1706. [ 'db', 'dc', { contents: 'dd', colspan: 2 } ]
  1707. ] );
  1708. // +----+----+----+----+----+----+
  1709. // | 00 | 01 | 02 | 03 | 04 | 05 |
  1710. // +----+----+----+----+----+----+
  1711. // | 10 | aa | ac | 14 | 15 |
  1712. // +----+----+----+----+----+----+
  1713. // | 20 | ba | bb | 24 | 25 |
  1714. // +----+----+ +----+----+
  1715. // | 30 | ca | | 34 | 35 |
  1716. // +----+----+----+----+----+----+
  1717. // | 40 | 41 | 42 | 43 | 44 | 45 |
  1718. // +----+----+----+----+----+----+
  1719. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1720. [ '00', '01', '02', '03', '04', '05' ],
  1721. [ '10', { contents: 'aa', colspan: 2 }, 'ac', '14', '15' ],
  1722. [ '20', 'ba', { contents: 'bb', colspan: 2, rowspan: 2 }, '24', '25' ],
  1723. [ '30', 'ca', '34', '35' ],
  1724. [ '40', '41', '42', '43', '44', '45' ]
  1725. ] ) );
  1726. /* eslint-disable no-multi-spaces */
  1727. assertSelectedCells( model, [
  1728. [ 0, 0, 0, 0, 0, 0 ],
  1729. [ 0, 1, 1, 0, 0 ],
  1730. [ 0, 1, 1, 0, 0 ],
  1731. [ 0, 1, 0, 0 ],
  1732. [ 0, 0, 0, 0, 0, 0 ]
  1733. ] );
  1734. /* eslint-enable no-multi-spaces */
  1735. } );
  1736. } );
  1737. } );
  1738. describe( 'pasted table is smaller than the selected area', () => {
  1739. it( 'blocks this case', () => {
  1740. tableSelection.setCellSelection(
  1741. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1742. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  1743. );
  1744. // Catches the temporary console log in the CK_DEBUG mode.
  1745. sinon.stub( console, 'log' );
  1746. pasteTable( [
  1747. [ 'aa', 'ab' ],
  1748. [ 'ba', 'bb' ]
  1749. ] );
  1750. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1751. [ '00', '01', '02', '03' ],
  1752. [ '10', '11', '12', '13' ],
  1753. [ '20', '21', '22', '23' ],
  1754. [ '30', '31', '32', '33' ]
  1755. ] ) );
  1756. assertSelectedCells( model, [
  1757. [ 1, 1, 1, 1 ],
  1758. [ 1, 1, 1, 1 ],
  1759. [ 1, 1, 1, 1 ],
  1760. [ 1, 1, 1, 1 ]
  1761. ] );
  1762. } );
  1763. } );
  1764. } );
  1765. describe( 'Clipboard integration - paste (content scenarios)', () => {
  1766. it( 'handles multiple paragraphs in table cell', async () => {
  1767. await createEditor();
  1768. setModelData( model, modelTable( [
  1769. [ '00', '01', '02' ],
  1770. [ '01', '11', '12' ],
  1771. [ '02', '21', '22' ]
  1772. ] ) );
  1773. tableSelection.setCellSelection(
  1774. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1775. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1776. );
  1777. pasteTable( [
  1778. [ '<p>a</p><p>a</p><p>a</p>', 'ab' ],
  1779. [ 'ba', 'bb' ]
  1780. ] );
  1781. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1782. [ '<paragraph>a</paragraph><paragraph>a</paragraph><paragraph>a</paragraph>', 'ab', '02' ],
  1783. [ 'ba', 'bb', '12' ],
  1784. [ '02', '21', '22' ]
  1785. ] ) );
  1786. } );
  1787. it( 'handles image in table cell', async () => {
  1788. await createEditor( [ ImageEditing, ImageCaptionEditing ] );
  1789. setModelData( model, modelTable( [
  1790. [ '00', '01', '02' ],
  1791. [ '01', '11', '12' ],
  1792. [ '02', '21', '22' ]
  1793. ] ) );
  1794. tableSelection.setCellSelection(
  1795. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1796. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1797. );
  1798. pasteTable( [
  1799. [ '<img src="/assets/sample.jpg">', 'ab' ],
  1800. [ 'ba', 'bb' ]
  1801. ] );
  1802. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1803. [ '<image src="/assets/sample.jpg"><caption></caption></image>', 'ab', '02' ],
  1804. [ 'ba', 'bb', '12' ],
  1805. [ '02', '21', '22' ]
  1806. ] ) );
  1807. } );
  1808. it( 'handles mixed nested content in table cell', async () => {
  1809. await createEditor( [ ImageEditing, ImageCaptionEditing, BlockQuoteEditing, HorizontalLineEditing, ListEditing ] );
  1810. setModelData( model, modelTable( [
  1811. [ '00', '01', '02' ],
  1812. [ '01', '11', '12' ],
  1813. [ '02', '21', '22' ]
  1814. ] ) );
  1815. tableSelection.setCellSelection(
  1816. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1817. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1818. );
  1819. const img = '<img src="/assets/sample.jpg">';
  1820. const list = '<ul><li>foo</li><li>bar</li></ul>';
  1821. const blockquote = `<blockquote><p>baz</p>${ list }</blockquote>`;
  1822. pasteTable( [
  1823. [ `${ img }${ list }${ blockquote }`, 'ab' ],
  1824. [ 'ba', 'bb' ]
  1825. ] );
  1826. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1827. [
  1828. '<image src="/assets/sample.jpg"><caption></caption></image>' +
  1829. '<listItem listIndent="0" listType="bulleted">foo</listItem>' +
  1830. '<listItem listIndent="0" listType="bulleted">bar</listItem>' +
  1831. '<blockQuote>' +
  1832. '<paragraph>baz</paragraph>' +
  1833. '<listItem listIndent="0" listType="bulleted">foo</listItem>' +
  1834. '<listItem listIndent="0" listType="bulleted">bar</listItem>' +
  1835. '</blockQuote>',
  1836. 'ab',
  1837. '02' ],
  1838. [ 'ba', 'bb', '12' ],
  1839. [ '02', '21', '22' ]
  1840. ] ) );
  1841. } );
  1842. it( 'handles table cell properties', async () => {
  1843. await createEditor( [ TableCellPropertiesEditing ] );
  1844. setModelData( model, modelTable( [
  1845. [ '00', '01', '02' ],
  1846. [ '01', '11', '12' ],
  1847. [ '02', '21', '22' ]
  1848. ] ) );
  1849. tableSelection.setCellSelection(
  1850. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1851. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1852. );
  1853. pasteTable( [
  1854. [ { contents: 'aa', style: 'border:1px solid #f00;background:#ba7;width:1337px' }, 'ab' ],
  1855. [ 'ba', 'bb' ]
  1856. ] );
  1857. const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
  1858. expect( tableCell.getAttribute( 'borderColor' ) ).to.deep.equal( {
  1859. top: '#f00',
  1860. right: '#f00',
  1861. bottom: '#f00',
  1862. left: '#f00'
  1863. } );
  1864. expect( tableCell.getAttribute( 'borderStyle' ) ).to.deep.equal( {
  1865. top: 'solid',
  1866. right: 'solid',
  1867. bottom: 'solid',
  1868. left: 'solid'
  1869. } );
  1870. expect( tableCell.getAttribute( 'borderWidth' ) ).to.deep.equal( {
  1871. top: '1px',
  1872. right: '1px',
  1873. bottom: '1px',
  1874. left: '1px'
  1875. } );
  1876. expect( tableCell.getAttribute( 'backgroundColor' ) ).to.equal( '#ba7' );
  1877. expect( tableCell.getAttribute( 'width' ) ).to.equal( '1337px' );
  1878. } );
  1879. it( 'discards table properties', async () => {
  1880. await createEditor( [ TableCellPropertiesEditing ] );
  1881. setModelData( model, modelTable( [
  1882. [ '00', '01', '02' ],
  1883. [ '01', '11', '12' ],
  1884. [ '02', '21', '22' ]
  1885. ] ) );
  1886. tableSelection.setCellSelection(
  1887. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  1888. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1889. );
  1890. const tableStyle = 'border:1px solid #f00;background:#ba7;width:1337px';
  1891. const pastedTable = `<table style="${ tableStyle }"><tr><td>aa</td><td>ab</td></tr><tr><td>ba</td><td>bb</td></tr></table>`;
  1892. const data = {
  1893. dataTransfer: createDataTransfer(),
  1894. preventDefault: sinon.spy(),
  1895. stopPropagation: sinon.spy()
  1896. };
  1897. data.dataTransfer.setData( 'text/html', pastedTable );
  1898. viewDocument.fire( 'paste', data );
  1899. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  1900. [ 'aa', 'ab', '02' ],
  1901. [ 'ba', 'bb', '12' ],
  1902. [ '02', '21', '22' ]
  1903. ] ) );
  1904. } );
  1905. } );
  1906. async function createEditor( extraPlugins = [] ) {
  1907. editor = await ClassicTestEditor.create( element, {
  1908. plugins: [ TableEditing, TableClipboard, Paragraph, Clipboard, ...extraPlugins ]
  1909. } );
  1910. model = editor.model;
  1911. modelRoot = model.document.getRoot();
  1912. viewDocument = editor.editing.view.document;
  1913. tableSelection = editor.plugins.get( 'TableSelection' );
  1914. }
  1915. function pasteTable( tableData ) {
  1916. const data = {
  1917. dataTransfer: createDataTransfer(),
  1918. preventDefault: sinon.spy(),
  1919. stopPropagation: sinon.spy()
  1920. };
  1921. data.dataTransfer.setData( 'text/html', viewTable( tableData ) );
  1922. viewDocument.fire( 'paste', data );
  1923. return data;
  1924. }
  1925. function createDataTransfer() {
  1926. const store = new Map();
  1927. return {
  1928. setData( type, data ) {
  1929. store.set( type, data );
  1930. },
  1931. getData( type ) {
  1932. return store.get( type );
  1933. }
  1934. };
  1935. }
  1936. } );