tableediting.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Range from '@ckeditor/ckeditor5-engine/src/model/range';
  6. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  7. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  8. import { getData as getModelData, parse, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  9. import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
  10. import TableEditing from '../src/tableediting';
  11. import { formatTable, formattedModelTable, modelTable } from './_utils/utils';
  12. import InsertRowCommand from '../src/commands/insertrowcommand';
  13. import InsertTableCommand from '../src/commands/inserttablecommand';
  14. import InsertColumnCommand from '../src/commands/insertcolumncommand';
  15. import RemoveRowCommand from '../src/commands/removerowcommand';
  16. import RemoveColumnCommand from '../src/commands/removecolumncommand';
  17. import SplitCellCommand from '../src/commands/splitcellcommand';
  18. import MergeCellCommand from '../src/commands/mergecellcommand';
  19. import SetHeaderRowCommand from '../src/commands/setheaderrowcommand';
  20. import SetHeaderColumnCommand from '../src/commands/setheadercolumncommand';
  21. import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
  22. describe( 'TableEditing', () => {
  23. let editor, model;
  24. beforeEach( () => {
  25. return VirtualTestEditor
  26. .create( {
  27. plugins: [ TableEditing, Paragraph, UndoEditing ]
  28. } )
  29. .then( newEditor => {
  30. editor = newEditor;
  31. model = editor.model;
  32. } );
  33. } );
  34. afterEach( () => {
  35. editor.destroy();
  36. } );
  37. it( 'should set proper schema rules', () => {
  38. } );
  39. it( 'adds insertTable command', () => {
  40. expect( editor.commands.get( 'insertTable' ) ).to.be.instanceOf( InsertTableCommand );
  41. } );
  42. it( 'adds insertRowAbove command', () => {
  43. expect( editor.commands.get( 'insertTableRowAbove' ) ).to.be.instanceOf( InsertRowCommand );
  44. } );
  45. it( 'adds insertRowBelow command', () => {
  46. expect( editor.commands.get( 'insertTableRowBelow' ) ).to.be.instanceOf( InsertRowCommand );
  47. } );
  48. it( 'adds insertColumnBefore command', () => {
  49. expect( editor.commands.get( 'insertTableColumnBefore' ) ).to.be.instanceOf( InsertColumnCommand );
  50. } );
  51. it( 'adds insertColumnAfter command', () => {
  52. expect( editor.commands.get( 'insertTableColumnAfter' ) ).to.be.instanceOf( InsertColumnCommand );
  53. } );
  54. it( 'adds removeRow command', () => {
  55. expect( editor.commands.get( 'removeTableRow' ) ).to.be.instanceOf( RemoveRowCommand );
  56. } );
  57. it( 'adds removeColumn command', () => {
  58. expect( editor.commands.get( 'removeTableColumn' ) ).to.be.instanceOf( RemoveColumnCommand );
  59. } );
  60. it( 'adds splitCellVertically command', () => {
  61. expect( editor.commands.get( 'splitTableCellVertically' ) ).to.be.instanceOf( SplitCellCommand );
  62. } );
  63. it( 'adds splitCellHorizontally command', () => {
  64. expect( editor.commands.get( 'splitTableCellHorizontally' ) ).to.be.instanceOf( SplitCellCommand );
  65. } );
  66. it( 'adds mergeCellRight command', () => {
  67. expect( editor.commands.get( 'mergeTableCellRight' ) ).to.be.instanceOf( MergeCellCommand );
  68. } );
  69. it( 'adds mergeCellLeft command', () => {
  70. expect( editor.commands.get( 'mergeTableCellLeft' ) ).to.be.instanceOf( MergeCellCommand );
  71. } );
  72. it( 'adds mergeCellDown command', () => {
  73. expect( editor.commands.get( 'mergeTableCellDown' ) ).to.be.instanceOf( MergeCellCommand );
  74. } );
  75. it( 'adds mergeCellUp command', () => {
  76. expect( editor.commands.get( 'mergeTableCellUp' ) ).to.be.instanceOf( MergeCellCommand );
  77. } );
  78. it( 'adds setColumnHeader command', () => {
  79. expect( editor.commands.get( 'setTableColumnHeader' ) ).to.be.instanceOf( SetHeaderColumnCommand );
  80. } );
  81. it( 'adds setRowHeader command', () => {
  82. expect( editor.commands.get( 'setTableRowHeader' ) ).to.be.instanceOf( SetHeaderRowCommand );
  83. } );
  84. describe( 'conversion in data pipeline', () => {
  85. describe( 'model to view', () => {
  86. it( 'should create tbody section', () => {
  87. setModelData( model, '<table><tableRow><tableCell>foo[]</tableCell></tableRow></table>' );
  88. expect( editor.getData() ).to.equal(
  89. '<figure class="table">' +
  90. '<table>' +
  91. '<tbody>' +
  92. '<tr><td>foo</td></tr>' +
  93. '</tbody>' +
  94. '</table>' +
  95. '</figure>'
  96. );
  97. } );
  98. it( 'should create thead section', () => {
  99. setModelData( model, '<table headingRows="1"><tableRow><tableCell>foo[]</tableCell></tableRow></table>' );
  100. expect( editor.getData() ).to.equal(
  101. '<figure class="table">' +
  102. '<table>' +
  103. '<thead>' +
  104. '<tr><th>foo</th></tr>' +
  105. '</thead>' +
  106. '</table>' +
  107. '</figure>'
  108. );
  109. } );
  110. } );
  111. describe( 'view to model', () => {
  112. it( 'should convert table', () => {
  113. editor.setData( '<table><tbody><tr><td>foo</td></tr></tbody></table>' );
  114. expect( getModelData( model, { withoutSelection: true } ) )
  115. .to.equal( '<table><tableRow><tableCell>foo</tableCell></tableRow></table>' );
  116. } );
  117. } );
  118. } );
  119. describe( 'caret movement', () => {
  120. let domEvtDataStub;
  121. beforeEach( () => {
  122. domEvtDataStub = {
  123. keyCode: getCode( 'Tab' ),
  124. preventDefault: sinon.spy(),
  125. stopPropagation: sinon.spy()
  126. };
  127. } );
  128. it( 'should do nothing if not tab pressed', () => {
  129. setModelData( model, modelTable( [
  130. [ '11', '12[]' ]
  131. ] ) );
  132. domEvtDataStub.keyCode = getCode( 'a' );
  133. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  134. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  135. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  136. expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
  137. [ '11', '12[]' ]
  138. ] ) );
  139. } );
  140. it( 'should do nothing if Ctrl+Tab is pressed', () => {
  141. setModelData( model, modelTable( [
  142. [ '11', '12[]' ]
  143. ] ) );
  144. domEvtDataStub.ctrlKey = true;
  145. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  146. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  147. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  148. expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
  149. [ '11', '12[]' ]
  150. ] ) );
  151. } );
  152. describe( 'on TAB', () => {
  153. it( 'should do nothing if selection is not in a table', () => {
  154. setModelData( model, '[]' + modelTable( [
  155. [ '11', '12' ]
  156. ] ) );
  157. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  158. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  159. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  160. expect( formatTable( getModelData( model ) ) ).to.equal( '[]' + formattedModelTable( [
  161. [ '11', '12' ]
  162. ] ) );
  163. } );
  164. it( 'should move to next cell', () => {
  165. setModelData( model, modelTable( [
  166. [ '11[]', '12' ]
  167. ] ) );
  168. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  169. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  170. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  171. expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
  172. [ '11', '[12]' ]
  173. ] ) );
  174. } );
  175. it( 'should create another row and move to first cell in new row', () => {
  176. setModelData( model, modelTable( [
  177. [ '11', '[12]' ]
  178. ] ) );
  179. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  180. expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
  181. [ '11', '12' ],
  182. [ '[]', '' ]
  183. ] ) );
  184. } );
  185. it( 'should move to the first cell of next row if on end of a row', () => {
  186. setModelData( model, modelTable( [
  187. [ '11', '12[]' ],
  188. [ '21', '22' ]
  189. ] ) );
  190. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  191. expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
  192. [ '11', '12' ],
  193. [ '[21]', '22' ]
  194. ] ) );
  195. } );
  196. describe( 'on table widget selected', () => {
  197. beforeEach( () => {
  198. editor.model.schema.register( 'block', {
  199. allowWhere: '$block',
  200. allowContentOf: '$block',
  201. isObject: true
  202. } );
  203. editor.conversion.elementToElement( { model: 'block', view: 'block' } );
  204. } );
  205. it( 'should move caret to the first table cell on TAB', () => {
  206. const spy = sinon.spy();
  207. editor.editing.view.document.on( 'keydown', spy );
  208. setModelData( model, '[' + modelTable( [
  209. [ '11', '12' ]
  210. ] ) + ']' );
  211. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  212. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  213. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  214. expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
  215. [ '[11]', '12' ]
  216. ] ) );
  217. // Should cancel event - so no other tab handler is called.
  218. sinon.assert.notCalled( spy );
  219. } );
  220. it( 'shouldn\'t do anything on other blocks', () => {
  221. const spy = sinon.spy();
  222. editor.editing.view.document.on( 'keydown', spy );
  223. setModelData( model, '[<block>foo</block>]' );
  224. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  225. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  226. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  227. expect( formatTable( getModelData( model ) ) ).to.equal( '[<block>foo</block>]' );
  228. // Should not cancel event.
  229. sinon.assert.calledOnce( spy );
  230. } );
  231. } );
  232. } );
  233. describe( 'on SHIFT+TAB', () => {
  234. beforeEach( () => {
  235. domEvtDataStub.shiftKey = true;
  236. } );
  237. it( 'should do nothing if selection is not in a table', () => {
  238. setModelData( model, '[]' + modelTable( [
  239. [ '11', '12' ]
  240. ] ) );
  241. domEvtDataStub.keyCode = getCode( 'Tab' );
  242. domEvtDataStub.shiftKey = true;
  243. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  244. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  245. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  246. expect( formatTable( getModelData( model ) ) ).to.equal( '[]' + formattedModelTable( [
  247. [ '11', '12' ]
  248. ] ) );
  249. } );
  250. it( 'should move to previous cell', () => {
  251. setModelData( model, modelTable( [
  252. [ '11', '12[]' ]
  253. ] ) );
  254. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  255. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  256. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  257. expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
  258. [ '[11]', '12' ]
  259. ] ) );
  260. } );
  261. it( 'should not move if caret is in first table cell', () => {
  262. setModelData( model, '<paragraph>foo</paragraph>' + modelTable( [
  263. [ '[]11', '12' ]
  264. ] ) );
  265. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  266. expect( formatTable( getModelData( model ) ) ).to.equal(
  267. '<paragraph>foo</paragraph>' + formattedModelTable( [ [ '[]11', '12' ] ] )
  268. );
  269. } );
  270. it( 'should move to the last cell of previous row if on beginning of a row', () => {
  271. setModelData( model, modelTable( [
  272. [ '11', '12' ],
  273. [ '[]21', '22' ]
  274. ] ) );
  275. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  276. expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
  277. [ '11', '[12]' ],
  278. [ '21', '22' ]
  279. ] ) );
  280. } );
  281. } );
  282. } );
  283. describe( 'post-fixer', () => {
  284. let root;
  285. beforeEach( () => {
  286. root = model.document.getRoot();
  287. } );
  288. it( 'should add missing columns to a tableRows that are shorter then longest table row', () => {
  289. const parsed = parse( modelTable( [
  290. [ '00' ],
  291. [ '10', '11', '12' ],
  292. [ '20', '21' ]
  293. ] ), model.schema );
  294. model.change( writer => {
  295. writer.remove( Range.createIn( root ) );
  296. writer.insert( parsed, root );
  297. } );
  298. expect( formatTable( getModelData( model, { withoutSelection: true } ) ) ).to.equal( formattedModelTable( [
  299. [ '00', '', '' ],
  300. [ '10', '11', '12' ],
  301. [ '20', '21', '' ]
  302. ] ) );
  303. } );
  304. it( 'should add missing columns to a tableRows that are shorter then longest table row (complex)', () => {
  305. const parsed = parse( modelTable( [
  306. [ { colspan: 6, contents: '00' } ],
  307. [ { rowspan: 2, contents: '10' }, '11', { colspan: 3, contents: '12' } ],
  308. [ '21', '22' ]
  309. ] ), model.schema );
  310. model.change( writer => {
  311. writer.remove( Range.createIn( root ) );
  312. writer.insert( parsed, root );
  313. } );
  314. expect( formatTable( getModelData( model, { withoutSelection: true } ) ) ).to.equal( formattedModelTable( [
  315. [ { colspan: 6, contents: '00' } ],
  316. [ { rowspan: 2, contents: '10' }, '11', { colspan: 3, contents: '12' }, '' ],
  317. [ '21', '22', '', '', '' ]
  318. ] ) );
  319. } );
  320. it( 'should fix wrong rowspan attribute on table header', () => {
  321. const parsed = parse( modelTable( [
  322. [ { rowspan: 2, contents: '00' }, { rowspan: 3, contents: '01' }, '02' ],
  323. [ { rowspan: 8, contents: '12' } ],
  324. [ '20', '21', '22' ]
  325. ], { headingRows: 2 } ), model.schema );
  326. model.change( writer => {
  327. writer.remove( Range.createIn( root ) );
  328. writer.insert( parsed, root );
  329. } );
  330. expect( formatTable( getModelData( model, { withoutSelection: true } ) ) ).to.equal( formattedModelTable( [
  331. [ { rowspan: 2, contents: '00' }, { rowspan: 2, contents: '01' }, '02' ],
  332. [ '12' ],
  333. [ '20', '21', '22' ]
  334. ], { headingRows: 2 } ) );
  335. } );
  336. it( 'should fix wrong rowspan attribute on table body', () => {
  337. const parsed = parse( modelTable( [
  338. [ '00', '01', '02' ],
  339. [ { rowspan: 2, contents: '10' }, { rowspan: 3, contents: '11' }, '12' ],
  340. [ { rowspan: 8, contents: '22' } ]
  341. ], { headingRows: 1 } ), model.schema );
  342. model.change( writer => {
  343. writer.remove( Range.createIn( root ) );
  344. writer.insert( parsed, root );
  345. } );
  346. expect( formatTable( getModelData( model, { withoutSelection: true } ) ) ).to.equal( formattedModelTable( [
  347. [ '00', '01', '02' ],
  348. [ { rowspan: 2, contents: '10' }, { rowspan: 2, contents: '11' }, '12' ],
  349. [ '22' ]
  350. ], { headingRows: 1 } ) );
  351. } );
  352. it( 'collab remove column vs insert row', () => {
  353. _testExternal(
  354. modelTable( [
  355. [ '00[]', '01' ],
  356. [ '10', '11' ]
  357. ] ),
  358. writer => _removeColumn( writer, 1, [ 0, 1 ] ),
  359. writer => _insertRow( writer, 1, [ 'a', 'b' ] ),
  360. formattedModelTable( [
  361. [ '00', '' ],
  362. [ 'a', 'b' ],
  363. [ '10', '' ]
  364. ] ),
  365. formattedModelTable( [
  366. [ '00', '01', '' ],
  367. [ 'a', 'b', '' ],
  368. [ '10', '11', '' ]
  369. ] ) );
  370. } );
  371. it( 'collab insert row vs remove column', () => {
  372. _testExternal(
  373. modelTable( [
  374. [ '00[]', '01' ],
  375. [ '10', '11' ]
  376. ] ),
  377. writer => _insertRow( writer, 1, [ 'a', 'b' ] ),
  378. writer => _removeColumn( writer, 1, [ 0, 2 ] ),
  379. formattedModelTable( [
  380. [ '00', '' ],
  381. [ 'a', 'b' ],
  382. [ '10', '' ]
  383. ] ),
  384. formattedModelTable( [
  385. [ '00', '' ],
  386. [ '10', '' ]
  387. ] ) );
  388. } );
  389. it( 'collab insert row vs insert column', () => {
  390. _testExternal(
  391. modelTable( [
  392. [ '00[]', '01' ],
  393. [ '10', '11' ]
  394. ] ),
  395. writer => _insertRow( writer, 1, [ 'a', 'b' ] ),
  396. writer => _insertColumn( writer, 1, [ 0, 2 ] ),
  397. formattedModelTable( [
  398. [ '00', '', '01' ],
  399. [ 'a', 'b', '' ],
  400. [ '10', '', '11' ]
  401. ] ),
  402. formattedModelTable( [
  403. [ '00', '', '01' ],
  404. [ '10', '', '11' ]
  405. ] ) );
  406. } );
  407. it( 'collab insert column vs insert row', () => {
  408. _testExternal(
  409. modelTable( [
  410. [ '00[]', '01' ],
  411. [ '10', '11' ]
  412. ] ),
  413. writer => _insertColumn( writer, 1, [ 0, 1 ] ),
  414. writer => _insertRow( writer, 1, [ 'a', 'b' ] ),
  415. formattedModelTable( [
  416. [ '00', '', '01' ],
  417. [ 'a', 'b', '' ],
  418. [ '10', '', '11' ]
  419. ] ),
  420. formattedModelTable( [
  421. [ '00', '01', '' ],
  422. [ 'a', 'b', '' ],
  423. [ '10', '11', '' ]
  424. ] ) );
  425. } );
  426. it( 'collab insert column vs insert column - other row has spanned cell', () => {
  427. _testExternal(
  428. modelTable( [
  429. [ { colspan: 3, contents: '00' } ],
  430. [ '10', '11', '12' ]
  431. ] ),
  432. writer => {
  433. _setAttribute( writer, 'colspan', 4, [ 0, 0 ] );
  434. _insertColumn( writer, 2, [ 1 ] );
  435. },
  436. writer => {
  437. _setAttribute( writer, 'colspan', 4, [ 0, 0 ] );
  438. _insertColumn( writer, 1, [ 1 ] );
  439. },
  440. formattedModelTable( [
  441. [ { colspan: 4, contents: '00' }, '' ],
  442. [ '10', '', '11', '', '12' ]
  443. ] ),
  444. formattedModelTable( [
  445. [ { colspan: 3, contents: '00' }, '' ],
  446. [ '10', '', '11', '12' ]
  447. ] ) );
  448. } );
  449. it( 'collab insert column vs insert column - other row has spanned cell (inverted)', () => {
  450. _testExternal(
  451. modelTable( [
  452. [ { colspan: 3, contents: '00' } ],
  453. [ '10', '11', '12' ]
  454. ] ),
  455. writer => {
  456. _setAttribute( writer, 'colspan', 4, [ 0, 0 ] );
  457. _insertColumn( writer, 1, [ 1 ] );
  458. },
  459. writer => {
  460. _setAttribute( writer, 'colspan', 4, [ 0, 0 ] );
  461. _insertColumn( writer, 3, [ 1 ] );
  462. },
  463. formattedModelTable( [
  464. [ { colspan: 4, contents: '00' }, '' ],
  465. [ '10', '', '11', '', '12' ]
  466. ] ),
  467. formattedModelTable( [
  468. [ { colspan: 3, contents: '00' }, '' ],
  469. [ '10', '11', '', '12' ]
  470. ] ) );
  471. } );
  472. // Case: remove same column (undo does nothing on one client - NOOP in batch).
  473. // Case: remove same row (undo does nothing on one client - NOOP in batch).
  474. // Case: Typing over user selecting - typing in marker...
  475. function _testExternal( initialData, localCallback, externalCallback, modelAfter, modelAfterUndo ) {
  476. setModelData( model, initialData );
  477. model.change( localCallback );
  478. model.enqueueChange( 'transparent', externalCallback );
  479. expect( formatTable( getModelData( model, { withoutSelection: true } ) ), 'after operations' ).to.equal( modelAfter );
  480. editor.execute( 'undo' );
  481. expect( formatTable( getModelData( model, { withoutSelection: true } ) ), 'after undo' ).to.equal( modelAfterUndo );
  482. }
  483. function _removeColumn( writer, columnIndex, rows ) {
  484. const table = root.getChild( 0 );
  485. for ( const index of rows ) {
  486. const tableRow = table.getChild( index );
  487. writer.remove( tableRow.getChild( columnIndex ) );
  488. }
  489. }
  490. function _insertRow( writer, rowIndex, rowData ) {
  491. const table = root.getChild( 0 );
  492. const parsedTable = parse(
  493. modelTable( [ rowData ] ),
  494. model.schema
  495. );
  496. writer.insert( parsedTable.getChild( 0 ), table, rowIndex );
  497. }
  498. function _setAttribute( writer, attributeKey, attributeValue, path ) {
  499. const table = root.getChild( 0 );
  500. const node = table.getNodeByPath( path );
  501. writer.setAttribute( attributeKey, attributeValue, node );
  502. }
  503. function _insertColumn( writer, columnIndex, rows ) {
  504. const table = root.getChild( 0 );
  505. for ( const index of rows ) {
  506. const tableRow = table.getChild( index );
  507. const tableCell = writer.createElement( 'tableCell' );
  508. writer.insert( tableCell, tableRow, columnIndex );
  509. }
  510. }
  511. } );
  512. } );