8
0

tableclipboard-paste.js 51 KB

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