tablenavigation.js 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284
  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. import TableNavigation from '../src/tablenavigation';
  6. import Table from '../src/table';
  7. import TableEditing from '../src/tableediting';
  8. import TableSelection from '../src/tableselection';
  9. import { modelTable } from './_utils/utils';
  10. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  11. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  12. import ImageEditing from '@ckeditor/ckeditor5-image/src/image/imageediting';
  13. import MediaEmbedEditing from '@ckeditor/ckeditor5-media-embed/src/mediaembedediting';
  14. import ImageCaptionEditing from '@ckeditor/ckeditor5-image/src/imagecaption/imagecaptionediting';
  15. import HorizontalLineEditing from '@ckeditor/ckeditor5-horizontal-line/src/horizontallineediting';
  16. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  17. import Image from '@ckeditor/ckeditor5-image/src/image';
  18. import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
  19. import HorizontalLine from '@ckeditor/ckeditor5-horizontal-line/src/horizontalline';
  20. import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
  21. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  22. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  23. import global from '@ckeditor/ckeditor5-utils/src/dom/global';
  24. import env from '@ckeditor/ckeditor5-utils/src/env';
  25. describe( 'TableNavigation', () => {
  26. let editor, model, modelRoot, tableSelection;
  27. const imageUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAUCAQAAADRyVAeAAAAKklEQVR42u3PAQ0AAAwCI' +
  28. 'O0f+u/hoAHNZUJFRERERERERERERERERLYiD9N4FAFj2iK6AAAAAElFTkSuQmCC';
  29. beforeEach( () => {
  30. return VirtualTestEditor
  31. .create( {
  32. plugins: [ TableEditing, TableNavigation, TableSelection, Paragraph, ImageEditing, ImageCaptionEditing, MediaEmbedEditing,
  33. HorizontalLineEditing ]
  34. } )
  35. .then( newEditor => {
  36. editor = newEditor;
  37. model = editor.model;
  38. modelRoot = model.document.getRoot();
  39. tableSelection = editor.plugins.get( TableSelection );
  40. } );
  41. } );
  42. afterEach( () => {
  43. editor.destroy();
  44. } );
  45. it( 'should have pluginName', () => {
  46. expect( TableNavigation.pluginName ).to.equal( 'TableNavigation' );
  47. } );
  48. describe( 'Tab key handling', () => {
  49. let domEvtDataStub;
  50. beforeEach( () => {
  51. domEvtDataStub = {
  52. keyCode: getCode( 'Tab' ),
  53. preventDefault: sinon.spy(),
  54. stopPropagation: sinon.spy()
  55. };
  56. } );
  57. it( 'should do nothing if pressed other key', () => {
  58. setModelData( model, modelTable( [
  59. [ '11', '12[]' ]
  60. ] ) );
  61. domEvtDataStub.keyCode = getCode( 'a' );
  62. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  63. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  64. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  65. assertEqualMarkup( getModelData( model ), modelTable( [
  66. [ '11', '12[]' ]
  67. ] ) );
  68. } );
  69. it( 'should do nothing if Ctrl+Tab is pressed', () => {
  70. setModelData( model, modelTable( [
  71. [ '11', '12[]' ]
  72. ] ) );
  73. domEvtDataStub.ctrlKey = true;
  74. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  75. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  76. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  77. assertEqualMarkup( getModelData( model ), modelTable( [
  78. [ '11', '12[]' ]
  79. ] ) );
  80. } );
  81. describe( 'on Tab key press', () => {
  82. it( 'should do nothing if the selection is not in a table', () => {
  83. setModelData( model, '<paragraph>[]</paragraph>' + modelTable( [ [ '11', '12' ] ] ) );
  84. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  85. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  86. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  87. assertEqualMarkup( getModelData( model ), '<paragraph>[]</paragraph>' + modelTable( [
  88. [ '11', '12' ]
  89. ] ) );
  90. } );
  91. it( 'should move to the next cell', () => {
  92. setModelData( model, modelTable( [
  93. [ '11[]', '12' ]
  94. ] ) );
  95. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  96. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  97. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  98. assertEqualMarkup( getModelData( model ), modelTable( [
  99. [ '11', '[12]' ]
  100. ] ) );
  101. } );
  102. it( 'should create another row and move to the first cell in a new row', () => {
  103. setModelData( model, modelTable( [
  104. [ '11', '[12]' ]
  105. ] ) );
  106. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  107. assertEqualMarkup( getModelData( model ), modelTable( [
  108. [ '11', '12' ],
  109. [ '[]', '' ]
  110. ] ) );
  111. } );
  112. it( 'should not create another row and not move the caret if the "insertTableRowBelow" command is disabled', () => {
  113. setModelData( model, modelTable( [
  114. [ '11', '12[]' ]
  115. ] ) );
  116. const insertTableRowBelowCommand = editor.commands.get( 'insertTableRowBelow' );
  117. insertTableRowBelowCommand.forceDisabled( 'test' );
  118. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  119. assertEqualMarkup( getModelData( model ), modelTable( [
  120. [ '11', '12[]' ]
  121. ] ) );
  122. } );
  123. it( 'should move to the first cell of the next row if at the end of a row', () => {
  124. setModelData( model, modelTable( [
  125. [ '11', '12[]' ],
  126. [ '21', '22' ]
  127. ] ) );
  128. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  129. assertEqualMarkup( getModelData( model ), modelTable( [
  130. [ '11', '12' ],
  131. [ '[21]', '22' ]
  132. ] ) );
  133. } );
  134. it( 'should move to the next table cell if the block content is partially selected', () => {
  135. setModelData( model, modelTable( [
  136. [ '11', '<paragraph>12</paragraph><paragraph>[foo]</paragraph><paragraph>bar</paragraph>', '13' ]
  137. ] ) );
  138. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  139. assertEqualMarkup( getModelData( model ), modelTable( [
  140. [
  141. '11',
  142. '<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>',
  143. '[13]'
  144. ]
  145. ] ) );
  146. } );
  147. it( 'should move to the next cell containing an image', () => {
  148. setModelData( model, modelTable( [
  149. [ '11[]', '<paragraph>foo</paragraph><image><caption></caption></image>' ]
  150. ] ) );
  151. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  152. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  153. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  154. assertEqualMarkup( getModelData( model ), modelTable( [
  155. [ '11', '<paragraph>[foo</paragraph><image><caption></caption></image>]' ]
  156. ] ) );
  157. } );
  158. it( 'should move to the next cell containing a block quote', () => {
  159. model.schema.register( 'blockQuote', {
  160. allowWhere: '$block',
  161. allowContentOf: '$root'
  162. } );
  163. editor.conversion.elementToElement( { model: 'blockQuote', view: 'blockquote' } );
  164. setModelData( model, modelTable( [
  165. [ '11[]', '<blockQuote><paragraph>foo</paragraph></blockQuote>' ]
  166. ] ) );
  167. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  168. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  169. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  170. assertEqualMarkup( getModelData( model ), modelTable( [
  171. [ '11', '<blockQuote><paragraph>[foo]</paragraph></blockQuote>' ]
  172. ] ) );
  173. } );
  174. it( 'should listen with the lower priority than its children', () => {
  175. // Cancel TAB event.
  176. editor.keystrokes.set( 'Tab', ( data, cancel ) => cancel() );
  177. setModelData( model, modelTable( [
  178. [ '11[]', '12' ]
  179. ] ) );
  180. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  181. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  182. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  183. assertEqualMarkup( getModelData( model ), modelTable( [
  184. [ '11[]', '12' ]
  185. ] ) );
  186. } );
  187. describe( 'on table widget selected', () => {
  188. beforeEach( () => {
  189. editor.model.schema.register( 'block', {
  190. allowWhere: '$block',
  191. allowContentOf: '$block',
  192. isObject: true
  193. } );
  194. editor.conversion.elementToElement( { model: 'block', view: 'block' } );
  195. } );
  196. it( 'should move caret to the first table cell on TAB', () => {
  197. const spy = sinon.spy();
  198. editor.keystrokes.set( 'Tab', spy, { priority: 'lowest' } );
  199. setModelData( model, '[' + modelTable( [
  200. [ '11', '12' ]
  201. ] ) + ']' );
  202. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  203. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  204. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  205. assertEqualMarkup( getModelData( model ), modelTable( [
  206. [ '[11]', '12' ]
  207. ] ) );
  208. // Should cancel event - so no other tab handler is called.
  209. sinon.assert.notCalled( spy );
  210. } );
  211. it( 'shouldn\'t do anything on other blocks', () => {
  212. const spy = sinon.spy();
  213. editor.editing.view.document.on( 'keydown', spy );
  214. setModelData( model, '[<block>foo</block>]' );
  215. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  216. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  217. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  218. assertEqualMarkup( getModelData( model ), '[<block>foo</block>]' );
  219. // Should not cancel event.
  220. sinon.assert.calledOnce( spy );
  221. } );
  222. } );
  223. } );
  224. describe( 'on Shift+Tab key press', () => {
  225. beforeEach( () => {
  226. domEvtDataStub.shiftKey = true;
  227. } );
  228. it( 'should do nothing if the selection is not in a table', () => {
  229. setModelData( model, '<paragraph>[]</paragraph>' + modelTable( [
  230. [ '11', '12' ]
  231. ] ) );
  232. domEvtDataStub.keyCode = getCode( 'Tab' );
  233. domEvtDataStub.shiftKey = true;
  234. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  235. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  236. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  237. assertEqualMarkup( getModelData( model ), '<paragraph>[]</paragraph>' + modelTable( [
  238. [ '11', '12' ]
  239. ] ) );
  240. } );
  241. it( 'should move to the previous cell', () => {
  242. setModelData( model, modelTable( [
  243. [ '11', '12[]' ]
  244. ] ) );
  245. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  246. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  247. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  248. assertEqualMarkup( getModelData( model ), modelTable( [
  249. [ '[11]', '12' ]
  250. ] ) );
  251. } );
  252. it( 'should not move if the caret is in the first table cell', () => {
  253. setModelData( model, '<paragraph>foo</paragraph>' + modelTable( [
  254. [ '[]11', '12' ]
  255. ] ) );
  256. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  257. assertEqualMarkup( getModelData( model ),
  258. '<paragraph>foo</paragraph>' + modelTable( [ [ '[]11', '12' ] ] )
  259. );
  260. } );
  261. it( 'should move to the last cell of a previous row if at the beginning of a row', () => {
  262. setModelData( model, modelTable( [
  263. [ '11', '12' ],
  264. [ '[]21', '22' ]
  265. ] ) );
  266. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  267. assertEqualMarkup( getModelData( model ), modelTable( [
  268. [ '11', '[12]' ],
  269. [ '21', '22' ]
  270. ] ) );
  271. } );
  272. it( 'should move to the previous table cell if the block content is partially selected', () => {
  273. setModelData( model, modelTable( [
  274. [ '11', '<paragraph>12</paragraph><paragraph>[foo]</paragraph><paragraph>bar</paragraph>', '13' ]
  275. ] ) );
  276. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  277. assertEqualMarkup( getModelData( model ), modelTable( [
  278. [
  279. '[11]',
  280. '<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>',
  281. '13'
  282. ]
  283. ] ) );
  284. } );
  285. it( 'should move to the previous cell containing an image', () => {
  286. setModelData( model, modelTable( [
  287. [ '<paragraph>foo</paragraph><image><caption></caption></image>', 'bar[]' ]
  288. ] ) );
  289. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  290. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  291. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  292. assertEqualMarkup( getModelData( model ), modelTable( [
  293. [ '<paragraph>[foo</paragraph><image><caption></caption></image>]', 'bar' ]
  294. ] ) );
  295. } );
  296. } );
  297. } );
  298. describe( 'Arrow keys handling', () => {
  299. let leftArrowDomEvtDataStub, rightArrowDomEvtDataStub, upArrowDomEvtDataStub, downArrowDomEvtDataStub;
  300. beforeEach( () => {
  301. leftArrowDomEvtDataStub = {
  302. keyCode: getCode( 'ArrowLeft' ),
  303. preventDefault: sinon.spy(),
  304. stopPropagation: sinon.spy(),
  305. domTarget: global.document.body
  306. };
  307. rightArrowDomEvtDataStub = {
  308. keyCode: getCode( 'ArrowRight' ),
  309. preventDefault: sinon.spy(),
  310. stopPropagation: sinon.spy(),
  311. domTarget: global.document.body
  312. };
  313. upArrowDomEvtDataStub = {
  314. keyCode: getCode( 'ArrowUp' ),
  315. preventDefault: sinon.spy(),
  316. stopPropagation: sinon.spy(),
  317. domTarget: global.document.body
  318. };
  319. downArrowDomEvtDataStub = {
  320. keyCode: getCode( 'ArrowDown' ),
  321. preventDefault: sinon.spy(),
  322. stopPropagation: sinon.spy(),
  323. domTarget: global.document.body
  324. };
  325. } );
  326. it( 'should do nothing if pressed some non-arrow key', () => {
  327. setModelData( model, modelTable( [
  328. [ '00', '01[]' ]
  329. ] ) );
  330. leftArrowDomEvtDataStub.keyCode = getCode( 'a' );
  331. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  332. sinon.assert.notCalled( leftArrowDomEvtDataStub.preventDefault );
  333. sinon.assert.notCalled( leftArrowDomEvtDataStub.stopPropagation );
  334. assertEqualMarkup( getModelData( model ), modelTable( [
  335. [ '00', '01[]' ]
  336. ] ) );
  337. } );
  338. it( 'should do nothing if the selection is not in a table', () => {
  339. const modelData = '<paragraph>[]foobar</paragraph>' + modelTable( [ [ '00', '01' ] ] );
  340. setModelData( model, modelData );
  341. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  342. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  343. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  344. assertEqualMarkup( getModelData( model ), modelData );
  345. } );
  346. describe( '#_navigateFromCellInDirection (finding a proper cell to move the selection to)', () => {
  347. let tableNavigation;
  348. beforeEach( () => {
  349. tableNavigation = editor.plugins.get( TableNavigation );
  350. } );
  351. describe( 'with no col/row-spanned cells', () => {
  352. beforeEach( () => {
  353. setModelData( model, '<paragraph>foo</paragraph>' + modelTable( [
  354. [ '00', '01', '02' ],
  355. [ '10', '11', '12' ],
  356. [ '20', '21', '22' ]
  357. ] ) + '<paragraph>bar</paragraph>' );
  358. } );
  359. describe( 'from the first table cell', () => {
  360. let tableCell;
  361. beforeEach( () => {
  362. tableCell = modelRoot.getNodeByPath( [ 1, 0, 0 ] );
  363. } );
  364. it( 'should navigate to the start position of the cell on the right when the direction is "right"', () => {
  365. tableNavigation._navigateFromCellInDirection( tableCell, 'right' );
  366. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  367. [ '00', '[]01', '02' ],
  368. [ '10', '11', '12' ],
  369. [ '20', '21', '22' ]
  370. ] ) + '<paragraph>bar</paragraph>' );
  371. } );
  372. it( 'should navigate to the start position of the cell below when the direction is "down"', () => {
  373. tableNavigation._navigateFromCellInDirection( tableCell, 'down' );
  374. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  375. [ '00', '01', '02' ],
  376. [ '[]10', '11', '12' ],
  377. [ '20', '21', '22' ]
  378. ] ) + '<paragraph>bar</paragraph>' );
  379. } );
  380. it( 'should select a whole table when the direction is "up"', () => {
  381. tableNavigation._navigateFromCellInDirection( tableCell, 'up' );
  382. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>[' + modelTable( [
  383. [ '00', '01', '02' ],
  384. [ '10', '11', '12' ],
  385. [ '20', '21', '22' ]
  386. ] ) + ']<paragraph>bar</paragraph>' );
  387. } );
  388. it( 'should select a whole table when the direction is "left"', () => {
  389. tableNavigation._navigateFromCellInDirection( tableCell, 'left' );
  390. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>[' + modelTable( [
  391. [ '00', '01', '02' ],
  392. [ '10', '11', '12' ],
  393. [ '20', '21', '22' ]
  394. ] ) + ']<paragraph>bar</paragraph>' );
  395. } );
  396. } );
  397. describe( 'from the last table cell', () => {
  398. let tableCell;
  399. beforeEach( () => {
  400. tableCell = modelRoot.getNodeByPath( [ 1, 2, 2 ] );
  401. } );
  402. it( 'should navigate to the end position of the cell on the left when the direction is "left"', () => {
  403. tableNavigation._navigateFromCellInDirection( tableCell, 'left' );
  404. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  405. [ '00', '01', '02' ],
  406. [ '10', '11', '12' ],
  407. [ '20', '21[]', '22' ]
  408. ] ) + '<paragraph>bar</paragraph>' );
  409. } );
  410. it( 'should navigate to the end position of the cell above when the direction is "up"', () => {
  411. tableNavigation._navigateFromCellInDirection( tableCell, 'up' );
  412. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  413. [ '00', '01', '02' ],
  414. [ '10', '11', '12[]' ],
  415. [ '20', '21', '22' ]
  416. ] ) + '<paragraph>bar</paragraph>' );
  417. } );
  418. it( 'should select a whole table when the direction is "down"', () => {
  419. tableNavigation._navigateFromCellInDirection( tableCell, 'down' );
  420. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>[' + modelTable( [
  421. [ '00', '01', '02' ],
  422. [ '10', '11', '12' ],
  423. [ '20', '21', '22' ]
  424. ] ) + ']<paragraph>bar</paragraph>' );
  425. } );
  426. it( 'should select a whole table when the direction is "right"', () => {
  427. tableNavigation._navigateFromCellInDirection( tableCell, 'right' );
  428. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>[' + modelTable( [
  429. [ '00', '01', '02' ],
  430. [ '10', '11', '12' ],
  431. [ '20', '21', '22' ]
  432. ] ) + ']<paragraph>bar</paragraph>' );
  433. } );
  434. } );
  435. describe( 'from a cell in the first column (but not first row)', () => {
  436. let tableCell;
  437. beforeEach( () => {
  438. tableCell = modelRoot.getNodeByPath( [ 1, 1, 0 ] );
  439. } );
  440. it( 'should navigate to start position of the cell on the right when the direction is "right"', () => {
  441. tableNavigation._navigateFromCellInDirection( tableCell, 'right' );
  442. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  443. [ '00', '01', '02' ],
  444. [ '10', '[]11', '12' ],
  445. [ '20', '21', '22' ]
  446. ] ) + '<paragraph>bar</paragraph>' );
  447. } );
  448. it( 'should navigate to the end position of the cell above when the direction is "up"', () => {
  449. tableNavigation._navigateFromCellInDirection( tableCell, 'up' );
  450. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  451. [ '00[]', '01', '02' ],
  452. [ '10', '11', '12' ],
  453. [ '20', '21', '22' ]
  454. ] ) + '<paragraph>bar</paragraph>' );
  455. } );
  456. it( 'should navigate to the start position of the cell below when the direction is "down"', () => {
  457. tableNavigation._navigateFromCellInDirection( tableCell, 'down' );
  458. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  459. [ '00', '01', '02' ],
  460. [ '10', '11', '12' ],
  461. [ '[]20', '21', '22' ]
  462. ] ) + '<paragraph>bar</paragraph>' );
  463. } );
  464. it( 'should navigate to the end position of the last cell in the previous row when the direction is "left"', () => {
  465. tableNavigation._navigateFromCellInDirection( tableCell, 'left' );
  466. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  467. [ '00', '01', '02[]' ],
  468. [ '10', '11', '12' ],
  469. [ '20', '21', '22' ]
  470. ] ) + '<paragraph>bar</paragraph>' );
  471. } );
  472. } );
  473. describe( 'from a cell in the last column (but not the last row)', () => {
  474. let tableCell;
  475. beforeEach( () => {
  476. tableCell = modelRoot.getNodeByPath( [ 1, 1, 2 ] );
  477. } );
  478. it( 'should navigate to the end position of the cell on the left when the direction is "left"', () => {
  479. tableNavigation._navigateFromCellInDirection( tableCell, 'left' );
  480. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  481. [ '00', '01', '02' ],
  482. [ '10', '11[]', '12' ],
  483. [ '20', '21', '22' ]
  484. ] ) + '<paragraph>bar</paragraph>' );
  485. } );
  486. it( 'should navigate to the end position the cell above when the direction is "up"', () => {
  487. tableNavigation._navigateFromCellInDirection( tableCell, 'up' );
  488. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  489. [ '00', '01', '02[]' ],
  490. [ '10', '11', '12' ],
  491. [ '20', '21', '22' ]
  492. ] ) + '<paragraph>bar</paragraph>' );
  493. } );
  494. it( 'should navigate to the start position of the cell below when the direction is "down"', () => {
  495. tableNavigation._navigateFromCellInDirection( tableCell, 'down' );
  496. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  497. [ '00', '01', '02' ],
  498. [ '10', '11', '12' ],
  499. [ '20', '21', '[]22' ]
  500. ] ) + '<paragraph>bar</paragraph>' );
  501. } );
  502. it( 'should navigate to the start position of the first cell in the next row when the direction is "right"', () => {
  503. tableNavigation._navigateFromCellInDirection( tableCell, 'right' );
  504. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  505. [ '00', '01', '02' ],
  506. [ '10', '11', '12' ],
  507. [ '[]20', '21', '22' ]
  508. ] ) + '<paragraph>bar</paragraph>' );
  509. } );
  510. } );
  511. } );
  512. describe( 'with col/row-spanned cells', () => {
  513. beforeEach( () => {
  514. // +----+----+----+----+----+
  515. // | 00 | 01 | 02 | 03 | 04 |
  516. // +----+----+----+----+----+
  517. // | 10 | 11 | 13 | 14 |
  518. // +----+ + +----+
  519. // | 20 | | | 24 |
  520. // +----+----+----+----+----+
  521. // | 30 | 31 | 33 | 34 |
  522. // +----+----+----+----+----+
  523. // | 40 | 41 | 42 | 43 | 44 |
  524. // +----+----+----+----+----+
  525. setModelData( model, modelTable( [
  526. [ '00', '01', '02', '03', '04' ],
  527. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  528. [ '20', '24' ],
  529. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  530. [ '40', '41', '42', '43', '44' ]
  531. ] ) );
  532. } );
  533. describe( 'when navigating to the right', () => {
  534. it( 'should navigate to the row-col-spanned cell when approaching from the upper-spanned row', () => {
  535. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 0 ] );
  536. tableNavigation._navigateFromCellInDirection( tableCell, 'right' );
  537. assertEqualMarkup( getModelData( model ), modelTable( [
  538. [ '00', '01', '02', '03', '04' ],
  539. [ '10', { contents: '[]11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  540. [ '20', '24' ],
  541. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  542. [ '40', '41', '42', '43', '44' ]
  543. ] ) );
  544. } );
  545. it( 'should navigate to the row-col-spanned cell when approaching from the lower-spanned row', () => {
  546. const tableCell = modelRoot.getNodeByPath( [ 0, 2, 0 ] );
  547. tableNavigation._navigateFromCellInDirection( tableCell, 'right' );
  548. assertEqualMarkup( getModelData( model ), modelTable( [
  549. [ '00', '01', '02', '03', '04' ],
  550. [ '10', { contents: '[]11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  551. [ '20', '24' ],
  552. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  553. [ '40', '41', '42', '43', '44' ]
  554. ] ) );
  555. } );
  556. it( 'should navigate to the row-spanned cell when approaching from the other row-spanned cell', () => {
  557. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  558. tableNavigation._navigateFromCellInDirection( tableCell, 'right' );
  559. assertEqualMarkup( getModelData( model ), modelTable( [
  560. [ '00', '01', '02', '03', '04' ],
  561. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '[]13', rowspan: 2 }, '14' ],
  562. [ '20', '24' ],
  563. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  564. [ '40', '41', '42', '43', '44' ]
  565. ] ) );
  566. } );
  567. it( 'should navigate to the cell in the upper-spanned row when approaching from the row-spanned cell', () => {
  568. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 2 ] ); // Cell 13.
  569. tableNavigation._navigateFromCellInDirection( tableCell, 'right' );
  570. assertEqualMarkup( getModelData( model ), modelTable( [
  571. [ '00', '01', '02', '03', '04' ],
  572. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '[]14' ],
  573. [ '20', '24' ],
  574. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  575. [ '40', '41', '42', '43', '44' ]
  576. ] ) );
  577. } );
  578. it( 'should navigate to the col-spanned cell', () => {
  579. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 0 ] );
  580. tableNavigation._navigateFromCellInDirection( tableCell, 'right' );
  581. assertEqualMarkup( getModelData( model ), modelTable( [
  582. [ '00', '01', '02', '03', '04' ],
  583. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  584. [ '20', '24' ],
  585. [ '30', { contents: '[]31', colspan: 2 }, '33', '34' ],
  586. [ '40', '41', '42', '43', '44' ]
  587. ] ) );
  588. } );
  589. it( 'should navigate from the col-spanned cell', () => {
  590. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 1 ] );
  591. tableNavigation._navigateFromCellInDirection( tableCell, 'right' );
  592. assertEqualMarkup( getModelData( model ), modelTable( [
  593. [ '00', '01', '02', '03', '04' ],
  594. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  595. [ '20', '24' ],
  596. [ '30', { contents: '31', colspan: 2 }, '[]33', '34' ],
  597. [ '40', '41', '42', '43', '44' ]
  598. ] ) );
  599. } );
  600. } );
  601. describe( 'when navigating to the left', () => {
  602. it( 'should navigate to the row-spanned cell when approaching from the upper-spanned row', () => {
  603. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 3 ] ); // Cell 14.
  604. tableNavigation._navigateFromCellInDirection( tableCell, 'left' );
  605. assertEqualMarkup( getModelData( model ), modelTable( [
  606. [ '00', '01', '02', '03', '04' ],
  607. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13[]', rowspan: 2 }, '14' ],
  608. [ '20', '24' ],
  609. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  610. [ '40', '41', '42', '43', '44' ]
  611. ] ) );
  612. } );
  613. it( 'should navigate to the row-spanned cell when approaching from the lower-spanned row', () => {
  614. const tableCell = modelRoot.getNodeByPath( [ 0, 2, 1 ] ); // Cell 24.
  615. tableNavigation._navigateFromCellInDirection( tableCell, 'left' );
  616. assertEqualMarkup( getModelData( model ), modelTable( [
  617. [ '00', '01', '02', '03', '04' ],
  618. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13[]', rowspan: 2 }, '14' ],
  619. [ '20', '24' ],
  620. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  621. [ '40', '41', '42', '43', '44' ]
  622. ] ) );
  623. } );
  624. it( 'should navigate to the row-spanned cell when approaching from the other row-spanned cell', () => {
  625. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 2 ] ); // Cell 13.
  626. tableNavigation._navigateFromCellInDirection( tableCell, 'left' );
  627. assertEqualMarkup( getModelData( model ), modelTable( [
  628. [ '00', '01', '02', '03', '04' ],
  629. [ '10', { contents: '11[]', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  630. [ '20', '24' ],
  631. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  632. [ '40', '41', '42', '43', '44' ]
  633. ] ) );
  634. } );
  635. it( 'should navigate to the cell in the upper-spanned row when approaching from the row-spanned cell', () => {
  636. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] ); // Cell 11.
  637. tableNavigation._navigateFromCellInDirection( tableCell, 'left' );
  638. assertEqualMarkup( getModelData( model ), modelTable( [
  639. [ '00', '01', '02', '03', '04' ],
  640. [ '10[]', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  641. [ '20', '24' ],
  642. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  643. [ '40', '41', '42', '43', '44' ]
  644. ] ) );
  645. } );
  646. it( 'should navigate to the col-spanned cell', () => {
  647. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 2 ] ); // Cell 33.
  648. tableNavigation._navigateFromCellInDirection( tableCell, 'left' );
  649. assertEqualMarkup( getModelData( model ), modelTable( [
  650. [ '00', '01', '02', '03', '04' ],
  651. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  652. [ '20', '24' ],
  653. [ '30', { contents: '31[]', colspan: 2 }, '33', '34' ],
  654. [ '40', '41', '42', '43', '44' ]
  655. ] ) );
  656. } );
  657. it( 'should navigate from the col-spanned cell', () => {
  658. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 1 ] );
  659. tableNavigation._navigateFromCellInDirection( tableCell, 'left' );
  660. assertEqualMarkup( getModelData( model ), modelTable( [
  661. [ '00', '01', '02', '03', '04' ],
  662. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  663. [ '20', '24' ],
  664. [ '30[]', { contents: '31', colspan: 2 }, '33', '34' ],
  665. [ '40', '41', '42', '43', '44' ]
  666. ] ) );
  667. } );
  668. } );
  669. describe( 'when navigating down', () => {
  670. it( 'should navigate to the row-col-spanned cell when approaching from the first spanned column', () => {
  671. const tableCell = modelRoot.getNodeByPath( [ 0, 0, 1 ] );
  672. tableNavigation._navigateFromCellInDirection( tableCell, 'down' );
  673. assertEqualMarkup( getModelData( model ), modelTable( [
  674. [ '00', '01', '02', '03', '04' ],
  675. [ '10', { contents: '[]11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  676. [ '20', '24' ],
  677. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  678. [ '40', '41', '42', '43', '44' ]
  679. ] ) );
  680. } );
  681. it( 'should navigate to the row-col-spanned cell when approaching from the last spanned column', () => {
  682. const tableCell = modelRoot.getNodeByPath( [ 0, 0, 2 ] );
  683. tableNavigation._navigateFromCellInDirection( tableCell, 'down' );
  684. assertEqualMarkup( getModelData( model ), modelTable( [
  685. [ '00', '01', '02', '03', '04' ],
  686. [ '10', { contents: '[]11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  687. [ '20', '24' ],
  688. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  689. [ '40', '41', '42', '43', '44' ]
  690. ] ) );
  691. } );
  692. it( 'should navigate to the row-spanned cell when approaching from the other col-spanned cell', () => {
  693. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  694. tableNavigation._navigateFromCellInDirection( tableCell, 'down' );
  695. assertEqualMarkup( getModelData( model ), modelTable( [
  696. [ '00', '01', '02', '03', '04' ],
  697. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  698. [ '20', '24' ],
  699. [ '30', { contents: '[]31', colspan: 2 }, '33', '34' ],
  700. [ '40', '41', '42', '43', '44' ]
  701. ] ) );
  702. } );
  703. it( 'should navigate to the cell in the first spanned column when approaching from the col-spanned cell', () => {
  704. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] ); // Cell 11.
  705. tableNavigation._navigateFromCellInDirection( tableCell, 'down' );
  706. assertEqualMarkup( getModelData( model ), modelTable( [
  707. [ '00', '01', '02', '03', '04' ],
  708. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  709. [ '20', '24' ],
  710. [ '30', { contents: '[]31', colspan: 2 }, '33', '34' ],
  711. [ '40', '41', '42', '43', '44' ]
  712. ] ) );
  713. } );
  714. it( 'should navigate to the row-spanned cell', () => {
  715. const tableCell = modelRoot.getNodeByPath( [ 0, 0, 3 ] );
  716. tableNavigation._navigateFromCellInDirection( tableCell, 'down' );
  717. assertEqualMarkup( getModelData( model ), modelTable( [
  718. [ '00', '01', '02', '03', '04' ],
  719. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '[]13', rowspan: 2 }, '14' ],
  720. [ '20', '24' ],
  721. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  722. [ '40', '41', '42', '43', '44' ]
  723. ] ) );
  724. } );
  725. it( 'should navigate from the row-spanned cell', () => {
  726. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 2 ] ); // Cell 13.
  727. tableNavigation._navigateFromCellInDirection( tableCell, 'down' );
  728. assertEqualMarkup( getModelData( model ), modelTable( [
  729. [ '00', '01', '02', '03', '04' ],
  730. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  731. [ '20', '24' ],
  732. [ '30', { contents: '31', colspan: 2 }, '[]33', '34' ],
  733. [ '40', '41', '42', '43', '44' ]
  734. ] ) );
  735. } );
  736. } );
  737. describe( 'when navigating up', () => {
  738. it( 'should navigate to the col-spanned cell when approaching from the first spanned column', () => {
  739. const tableCell = modelRoot.getNodeByPath( [ 0, 4, 1 ] );
  740. tableNavigation._navigateFromCellInDirection( tableCell, 'up' );
  741. assertEqualMarkup( getModelData( model ), modelTable( [
  742. [ '00', '01', '02', '03', '04' ],
  743. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  744. [ '20', '24' ],
  745. [ '30', { contents: '31[]', colspan: 2 }, '33', '34' ],
  746. [ '40', '41', '42', '43', '44' ]
  747. ] ) );
  748. } );
  749. it( 'should navigate to the col-spanned cell when approaching from the last spanned column', () => {
  750. const tableCell = modelRoot.getNodeByPath( [ 0, 4, 2 ] );
  751. tableNavigation._navigateFromCellInDirection( tableCell, 'up' );
  752. assertEqualMarkup( getModelData( model ), modelTable( [
  753. [ '00', '01', '02', '03', '04' ],
  754. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  755. [ '20', '24' ],
  756. [ '30', { contents: '31[]', colspan: 2 }, '33', '34' ],
  757. [ '40', '41', '42', '43', '44' ]
  758. ] ) );
  759. } );
  760. it( 'should navigate to the row-col-spanned cell when approaching from the other col-spanned cell', () => {
  761. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 1 ] );
  762. tableNavigation._navigateFromCellInDirection( tableCell, 'up' );
  763. assertEqualMarkup( getModelData( model ), modelTable( [
  764. [ '00', '01', '02', '03', '04' ],
  765. [ '10', { contents: '11[]', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  766. [ '20', '24' ],
  767. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  768. [ '40', '41', '42', '43', '44' ]
  769. ] ) );
  770. } );
  771. it( 'should navigate to the cell in the first spanned column when approaching from the col-spanned cell', () => {
  772. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  773. tableNavigation._navigateFromCellInDirection( tableCell, 'up' );
  774. assertEqualMarkup( getModelData( model ), modelTable( [
  775. [ '00', '01[]', '02', '03', '04' ],
  776. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  777. [ '20', '24' ],
  778. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  779. [ '40', '41', '42', '43', '44' ]
  780. ] ) );
  781. } );
  782. it( 'should navigate to the row-spanned cell', () => {
  783. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 2 ] ); // Cell 33.
  784. tableNavigation._navigateFromCellInDirection( tableCell, 'up' );
  785. assertEqualMarkup( getModelData( model ), modelTable( [
  786. [ '00', '01', '02', '03', '04' ],
  787. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13[]', rowspan: 2 }, '14' ],
  788. [ '20', '24' ],
  789. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  790. [ '40', '41', '42', '43', '44' ]
  791. ] ) );
  792. } );
  793. it( 'should navigate from the row-spanned cell', () => {
  794. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 2 ] ); // Cell 13.
  795. tableNavigation._navigateFromCellInDirection( tableCell, 'up' );
  796. assertEqualMarkup( getModelData( model ), modelTable( [
  797. [ '00', '01', '02', '03[]', '04' ],
  798. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  799. [ '20', '24' ],
  800. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  801. [ '40', '41', '42', '43', '44' ]
  802. ] ) );
  803. } );
  804. } );
  805. } );
  806. } );
  807. describe( 'with the table cells selected from outside', () => {
  808. describe( 'on a single table cell selected', () => {
  809. beforeEach( () => {
  810. setModelData( model, modelTable( [
  811. [ '00', '01', '02' ],
  812. [ '10', '11', '12' ],
  813. [ '20', '21', '22' ]
  814. ] ) );
  815. tableSelection._setCellSelection(
  816. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  817. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  818. );
  819. } );
  820. it( 'should move to the cell on the left', () => {
  821. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  822. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  823. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  824. assertEqualMarkup( getModelData( model ), modelTable( [
  825. [ '00', '01', '02' ],
  826. [ '10[]', '11', '12' ],
  827. [ '20', '21', '22' ]
  828. ] ) );
  829. } );
  830. it( 'should move to the cell on the right', () => {
  831. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  832. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  833. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  834. assertEqualMarkup( getModelData( model ), modelTable( [
  835. [ '00', '01', '02' ],
  836. [ '10', '11', '[]12' ],
  837. [ '20', '21', '22' ]
  838. ] ) );
  839. } );
  840. it( 'should move to the cell above the selection', () => {
  841. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  842. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  843. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  844. assertEqualMarkup( getModelData( model ), modelTable( [
  845. [ '00', '01[]', '02' ],
  846. [ '10', '11', '12' ],
  847. [ '20', '21', '22' ]
  848. ] ) );
  849. } );
  850. it( 'should move to the cell below the selection', () => {
  851. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  852. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  853. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  854. assertEqualMarkup( getModelData( model ), modelTable( [
  855. [ '00', '01', '02' ],
  856. [ '10', '11', '12' ],
  857. [ '20', '[]21', '22' ]
  858. ] ) );
  859. } );
  860. } );
  861. describe( 'on multiple table cells selected vertically', () => {
  862. beforeEach( () => {
  863. setModelData( model, modelTable( [
  864. [ '00', '01', '02', '03' ],
  865. [ '10', '11', '12', '13' ],
  866. [ '20', '21', '22', '23' ],
  867. [ '30', '31', '32', '33' ]
  868. ] ) );
  869. tableSelection._setCellSelection(
  870. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  871. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  872. );
  873. } );
  874. it( 'should move to the cell on the top left of the selection', () => {
  875. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  876. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  877. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  878. assertEqualMarkup( getModelData( model ), modelTable( [
  879. [ '00', '01', '02', '03' ],
  880. [ '10[]', '11', '12', '13' ],
  881. [ '20', '21', '22', '23' ],
  882. [ '30', '31', '32', '33' ]
  883. ] ) );
  884. } );
  885. it( 'should move to the cell on the bottom right of the selection', () => {
  886. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  887. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  888. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  889. assertEqualMarkup( getModelData( model ), modelTable( [
  890. [ '00', '01', '02', '03' ],
  891. [ '10', '11', '12', '13' ],
  892. [ '20', '21', '[]22', '23' ],
  893. [ '30', '31', '32', '33' ]
  894. ] ) );
  895. } );
  896. it( 'should move to the cell above the selection', () => {
  897. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  898. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  899. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  900. assertEqualMarkup( getModelData( model ), modelTable( [
  901. [ '00', '01[]', '02', '03' ],
  902. [ '10', '11', '12', '13' ],
  903. [ '20', '21', '22', '23' ],
  904. [ '30', '31', '32', '33' ]
  905. ] ) );
  906. } );
  907. it( 'should move to the cell below the selection', () => {
  908. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  909. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  910. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  911. assertEqualMarkup( getModelData( model ), modelTable( [
  912. [ '00', '01', '02', '03' ],
  913. [ '10', '11', '12', '13' ],
  914. [ '20', '21', '22', '23' ],
  915. [ '30', '[]31', '32', '33' ]
  916. ] ) );
  917. } );
  918. } );
  919. describe( 'on multiple table cell selected horizontally', () => {
  920. beforeEach( () => {
  921. setModelData( model, modelTable( [
  922. [ '00', '01', '02', '03' ],
  923. [ '10', '11', '12', '13' ],
  924. [ '20', '21', '22', '23' ],
  925. [ '30', '31', '32', '33' ]
  926. ] ) );
  927. // Note that this also tests that selection direction doesn't matter.
  928. tableSelection._setCellSelection(
  929. modelRoot.getNodeByPath( [ 0, 1, 2 ] ),
  930. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  931. );
  932. } );
  933. it( 'should move to the cell on the top left of the selection', () => {
  934. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  935. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  936. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  937. assertEqualMarkup( getModelData( model ), modelTable( [
  938. [ '00', '01', '02', '03' ],
  939. [ '10[]', '11', '12', '13' ],
  940. [ '20', '21', '22', '23' ],
  941. [ '30', '31', '32', '33' ]
  942. ] ) );
  943. } );
  944. it( 'should move to the cell on the bottom right of the selection', () => {
  945. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  946. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  947. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  948. assertEqualMarkup( getModelData( model ), modelTable( [
  949. [ '00', '01', '02', '03' ],
  950. [ '10', '11', '12', '[]13' ],
  951. [ '20', '21', '22', '23' ],
  952. [ '30', '31', '32', '33' ]
  953. ] ) );
  954. } );
  955. it( 'should move to the cell above the selection', () => {
  956. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  957. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  958. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  959. assertEqualMarkup( getModelData( model ), modelTable( [
  960. [ '00', '01[]', '02', '03' ],
  961. [ '10', '11', '12', '13' ],
  962. [ '20', '21', '22', '23' ],
  963. [ '30', '31', '32', '33' ]
  964. ] ) );
  965. } );
  966. it( 'should move to the cell below the selection', () => {
  967. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  968. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  969. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  970. assertEqualMarkup( getModelData( model ), modelTable( [
  971. [ '00', '01', '02', '03' ],
  972. [ '10', '11', '12', '13' ],
  973. [ '20', '21', '[]22', '23' ],
  974. [ '30', '31', '32', '33' ]
  975. ] ) );
  976. } );
  977. } );
  978. describe( 'on multiple table cell selected diagonally', () => {
  979. beforeEach( () => {
  980. setModelData( model, modelTable( [
  981. [ '00', '01', '02', '03' ],
  982. [ '10', '11', '12', '13' ],
  983. [ '20', '21', '22', '23' ],
  984. [ '30', '31', '32', '33' ]
  985. ] ) );
  986. tableSelection._setCellSelection(
  987. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  988. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  989. );
  990. } );
  991. it( 'should move to the cell on the top left of selection', () => {
  992. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  993. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  994. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  995. assertEqualMarkup( getModelData( model ), modelTable( [
  996. [ '00', '01', '02', '03' ],
  997. [ '10[]', '11', '12', '13' ],
  998. [ '20', '21', '22', '23' ],
  999. [ '30', '31', '32', '33' ]
  1000. ] ) );
  1001. } );
  1002. it( 'should move to the cell on the bottom right of selection', () => {
  1003. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1004. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1005. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1006. assertEqualMarkup( getModelData( model ), modelTable( [
  1007. [ '00', '01', '02', '03' ],
  1008. [ '10', '11', '12', '13' ],
  1009. [ '20', '21', '22', '[]23' ],
  1010. [ '30', '31', '32', '33' ]
  1011. ] ) );
  1012. } );
  1013. it( 'should move to the cell above selection', () => {
  1014. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1015. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1016. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1017. assertEqualMarkup( getModelData( model ), modelTable( [
  1018. [ '00', '01[]', '02', '03' ],
  1019. [ '10', '11', '12', '13' ],
  1020. [ '20', '21', '22', '23' ],
  1021. [ '30', '31', '32', '33' ]
  1022. ] ) );
  1023. } );
  1024. it( 'should move to the cell below selection', () => {
  1025. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1026. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1027. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1028. assertEqualMarkup( getModelData( model ), modelTable( [
  1029. [ '00', '01', '02', '03' ],
  1030. [ '10', '11', '12', '13' ],
  1031. [ '20', '21', '22', '23' ],
  1032. [ '30', '31', '[]32', '33' ]
  1033. ] ) );
  1034. } );
  1035. } );
  1036. } );
  1037. describe( 'with the selection inside a table cell', () => {
  1038. describe( 'with the selection at the boundary of a cell', () => {
  1039. describe( 'simple cell text content', () => {
  1040. it( 'should navigate to the cell on the left', () => {
  1041. setModelData( model, modelTable( [
  1042. [ '00', '01', '02' ],
  1043. [ '10', '[]11', '12' ],
  1044. [ '20', '21', '22' ]
  1045. ] ) );
  1046. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1047. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1048. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1049. assertEqualMarkup( getModelData( model ), modelTable( [
  1050. [ '00', '01', '02' ],
  1051. [ '10[]', '11', '12' ],
  1052. [ '20', '21', '22' ]
  1053. ] ) );
  1054. } );
  1055. it( 'should navigate to the cell on the right', () => {
  1056. setModelData( model, modelTable( [
  1057. [ '00', '01', '02' ],
  1058. [ '10', '11[]', '12' ],
  1059. [ '20', '21', '22' ]
  1060. ] ) );
  1061. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1062. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1063. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1064. assertEqualMarkup( getModelData( model ), modelTable( [
  1065. [ '00', '01', '02' ],
  1066. [ '10', '11', '[]12' ],
  1067. [ '20', '21', '22' ]
  1068. ] ) );
  1069. } );
  1070. it( 'should navigate to the cell above', () => {
  1071. setModelData( model, modelTable( [
  1072. [ '00', '01', '02' ],
  1073. [ '10', '[]11', '12' ],
  1074. [ '20', '21', '22' ]
  1075. ] ) );
  1076. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1077. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1078. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1079. assertEqualMarkup( getModelData( model ), modelTable( [
  1080. [ '00', '01[]', '02' ],
  1081. [ '10', '11', '12' ],
  1082. [ '20', '21', '22' ]
  1083. ] ) );
  1084. } );
  1085. it( 'should navigate to the cell below', () => {
  1086. setModelData( model, modelTable( [
  1087. [ '00', '01', '02' ],
  1088. [ '10', '11[]', '12' ],
  1089. [ '20', '21', '22' ]
  1090. ] ) );
  1091. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1092. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1093. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1094. assertEqualMarkup( getModelData( model ), modelTable( [
  1095. [ '00', '01', '02' ],
  1096. [ '10', '11', '12' ],
  1097. [ '20', '[]21', '22' ]
  1098. ] ) );
  1099. } );
  1100. } );
  1101. describe( 'multiple paragraphs in the cell content', () => {
  1102. it( 'should navigate to the cell on the left', () => {
  1103. setModelData( model, modelTable( [
  1104. [ '00', '01', '02' ],
  1105. [ '10', '<paragraph>[]11</paragraph><paragraph>x</paragraph>', '12' ],
  1106. [ '20', '21', '22' ]
  1107. ] ) );
  1108. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1109. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1110. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1111. assertEqualMarkup( getModelData( model ), modelTable( [
  1112. [ '00', '01', '02' ],
  1113. [ '10[]', '<paragraph>11</paragraph><paragraph>x</paragraph>', '12' ],
  1114. [ '20', '21', '22' ]
  1115. ] ) );
  1116. } );
  1117. it( 'should navigate to the cell on the right', () => {
  1118. setModelData( model, modelTable( [
  1119. [ '00', '01', '02' ],
  1120. [ '10', '<paragraph>11</paragraph><paragraph>x[]</paragraph>', '12' ],
  1121. [ '20', '21', '22' ]
  1122. ] ) );
  1123. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1124. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1125. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1126. assertEqualMarkup( getModelData( model ), modelTable( [
  1127. [ '00', '01', '02' ],
  1128. [ '10', '<paragraph>11</paragraph><paragraph>x</paragraph>', '[]12' ],
  1129. [ '20', '21', '22' ]
  1130. ] ) );
  1131. } );
  1132. it( 'should navigate to the cell above', () => {
  1133. setModelData( model, modelTable( [
  1134. [ '00', '01', '02' ],
  1135. [ '10', '<paragraph>[]11</paragraph><paragraph>x</paragraph>', '12' ],
  1136. [ '20', '21', '22' ]
  1137. ] ) );
  1138. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1139. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1140. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1141. assertEqualMarkup( getModelData( model ), modelTable( [
  1142. [ '00', '01[]', '02' ],
  1143. [ '10', '<paragraph>11</paragraph><paragraph>x</paragraph>', '12' ],
  1144. [ '20', '21', '22' ]
  1145. ] ) );
  1146. } );
  1147. it( 'should navigate to the cell below', () => {
  1148. setModelData( model, modelTable( [
  1149. [ '00', '01', '02' ],
  1150. [ '10', '<paragraph>11</paragraph><paragraph>x[]</paragraph>', '12' ],
  1151. [ '20', '21', '22' ]
  1152. ] ) );
  1153. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1154. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1155. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1156. assertEqualMarkup( getModelData( model ), modelTable( [
  1157. [ '00', '01', '02' ],
  1158. [ '10', '<paragraph>11</paragraph><paragraph>x</paragraph>', '12' ],
  1159. [ '20', '[]21', '22' ]
  1160. ] ) );
  1161. } );
  1162. } );
  1163. describe( 'image widget with caption as only cell content', () => {
  1164. it( 'should navigate to the cell on the left', () => {
  1165. setModelData( model, modelTable( [
  1166. [ '00', '01', '02' ],
  1167. [ '10', `<image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  1168. [ '20', '21', '22' ]
  1169. ] ) );
  1170. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1171. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1172. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1173. assertEqualMarkup( getModelData( model ), modelTable( [
  1174. [ '00', '01', '02' ],
  1175. [ '10[]', `<image src="${ imageUrl }"><caption>11</caption></image>`, '12' ],
  1176. [ '20', '21', '22' ]
  1177. ] ) );
  1178. } );
  1179. it( 'should navigate to the cell on the right', () => {
  1180. setModelData( model, modelTable( [
  1181. [ '00', '01', '02' ],
  1182. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image>`, '12' ],
  1183. [ '20', '21', '22' ]
  1184. ] ) );
  1185. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1186. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1187. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1188. assertEqualMarkup( getModelData( model ), modelTable( [
  1189. [ '00', '01', '02' ],
  1190. [ '10', `<image src="${ imageUrl }"><caption>11</caption></image>`, '[]12' ],
  1191. [ '20', '21', '22' ]
  1192. ] ) );
  1193. } );
  1194. it( 'should navigate to the cell above', () => {
  1195. setModelData( model, modelTable( [
  1196. [ '00', '01', '02' ],
  1197. [ '10', `<image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  1198. [ '20', '21', '22' ]
  1199. ] ) );
  1200. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1201. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1202. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1203. assertEqualMarkup( getModelData( model ), modelTable( [
  1204. [ '00', '01[]', '02' ],
  1205. [ '10', `<image src="${ imageUrl }"><caption>11</caption></image>`, '12' ],
  1206. [ '20', '21', '22' ]
  1207. ] ) );
  1208. } );
  1209. it( 'should navigate to the cell below', () => {
  1210. setModelData( model, modelTable( [
  1211. [ '00', '01', '02' ],
  1212. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image>`, '12' ],
  1213. [ '20', '21', '22' ]
  1214. ] ) );
  1215. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1216. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1217. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1218. assertEqualMarkup( getModelData( model ), modelTable( [
  1219. [ '00', '01', '02' ],
  1220. [ '10', `<image src="${ imageUrl }"><caption>11</caption></image>`, '12' ],
  1221. [ '20', '[]21', '22' ]
  1222. ] ) );
  1223. } );
  1224. } );
  1225. describe( 'horizontal line as only cell content (widget without $text positions)', () => {
  1226. beforeEach( () => {
  1227. setModelData( model, modelTable( [
  1228. [ '00', '01', '02' ],
  1229. [ '10', '[<horizontalLine></horizontalLine>]', '12' ],
  1230. [ '20', '21', '22' ]
  1231. ] ) );
  1232. } );
  1233. it( 'should navigate to the cell on the left', () => {
  1234. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1235. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1236. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1237. assertEqualMarkup( getModelData( model ), modelTable( [
  1238. [ '00', '01', '02' ],
  1239. [ '10[]', '<horizontalLine></horizontalLine>', '12' ],
  1240. [ '20', '21', '22' ]
  1241. ] ) );
  1242. } );
  1243. it( 'should navigate to the cell on the right', () => {
  1244. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1245. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1246. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1247. assertEqualMarkup( getModelData( model ), modelTable( [
  1248. [ '00', '01', '02' ],
  1249. [ '10', '<horizontalLine></horizontalLine>', '[]12' ],
  1250. [ '20', '21', '22' ]
  1251. ] ) );
  1252. } );
  1253. it( 'should navigate to the cell above', () => {
  1254. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1255. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1256. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1257. assertEqualMarkup( getModelData( model ), modelTable( [
  1258. [ '00', '01[]', '02' ],
  1259. [ '10', '<horizontalLine></horizontalLine>', '12' ],
  1260. [ '20', '21', '22' ]
  1261. ] ) );
  1262. } );
  1263. it( 'should navigate to the cell below', () => {
  1264. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1265. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1266. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1267. assertEqualMarkup( getModelData( model ), modelTable( [
  1268. [ '00', '01', '02' ],
  1269. [ '10', '<horizontalLine></horizontalLine>', '12' ],
  1270. [ '20', '[]21', '22' ]
  1271. ] ) );
  1272. } );
  1273. } );
  1274. describe( 'two horizontal lines as only cell content (widget without $text positions)', () => {
  1275. it( 'should navigate to the cell on the left', () => {
  1276. setModelData( model, modelTable( [
  1277. [ '00', '01', '02' ],
  1278. [ '10', '[<horizontalLine></horizontalLine>]<horizontalLine></horizontalLine>', '12' ],
  1279. [ '20', '21', '22' ]
  1280. ] ) );
  1281. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1282. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1283. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1284. assertEqualMarkup( getModelData( model ), modelTable( [
  1285. [ '00', '01', '02' ],
  1286. [ '10[]', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '12' ],
  1287. [ '20', '21', '22' ]
  1288. ] ) );
  1289. } );
  1290. it( 'should navigate to the cell on the right', () => {
  1291. setModelData( model, modelTable( [
  1292. [ '00', '01', '02' ],
  1293. [ '10', '<horizontalLine></horizontalLine>[<horizontalLine></horizontalLine>]', '12' ],
  1294. [ '20', '21', '22' ]
  1295. ] ) );
  1296. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1297. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1298. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1299. assertEqualMarkup( getModelData( model ), modelTable( [
  1300. [ '00', '01', '02' ],
  1301. [ '10', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '[]12' ],
  1302. [ '20', '21', '22' ]
  1303. ] ) );
  1304. } );
  1305. it( 'should navigate to the cell above', () => {
  1306. setModelData( model, modelTable( [
  1307. [ '00', '01', '02' ],
  1308. [ '10', '[<horizontalLine></horizontalLine>]<horizontalLine></horizontalLine>', '12' ],
  1309. [ '20', '21', '22' ]
  1310. ] ) );
  1311. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1312. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1313. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1314. assertEqualMarkup( getModelData( model ), modelTable( [
  1315. [ '00', '01[]', '02' ],
  1316. [ '10', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '12' ],
  1317. [ '20', '21', '22' ]
  1318. ] ) );
  1319. } );
  1320. it( 'should navigate to the cell below', () => {
  1321. setModelData( model, modelTable( [
  1322. [ '00', '01', '02' ],
  1323. [ '10', '<horizontalLine></horizontalLine>[<horizontalLine></horizontalLine>]', '12' ],
  1324. [ '20', '21', '22' ]
  1325. ] ) );
  1326. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1327. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1328. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1329. assertEqualMarkup( getModelData( model ), modelTable( [
  1330. [ '00', '01', '02' ],
  1331. [ '10', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '12' ],
  1332. [ '20', '[]21', '22' ]
  1333. ] ) );
  1334. } );
  1335. } );
  1336. } );
  1337. describe( 'with selection not at the boundary of a cell', () => {
  1338. let editorElement, editor, model, styleElement;
  1339. beforeEach( async () => {
  1340. editorElement = global.document.createElement( 'div' );
  1341. global.document.body.appendChild( editorElement );
  1342. editor = await ClassicTestEditor.create( editorElement, {
  1343. plugins: [ Table, Paragraph, Image, ImageCaption, HorizontalLine ]
  1344. } );
  1345. model = editor.model;
  1346. styleElement = global.document.createElement( 'style' );
  1347. styleElement.type = 'text/css';
  1348. styleElement.appendChild( global.document.createTextNode(
  1349. `
  1350. * {
  1351. font-size: 12px !important;
  1352. font-family: serif !important;
  1353. margin: 0 !important;
  1354. padding: 0 !important;
  1355. border: 0 !important
  1356. }
  1357. td { width: 30px !important; }
  1358. tr:nth-child(2) td:nth-child(2) { width: 300px !important; }
  1359. `
  1360. ) );
  1361. global.document.querySelector( 'head' ).appendChild( styleElement );
  1362. } );
  1363. afterEach( async () => {
  1364. editorElement.remove();
  1365. styleElement.remove();
  1366. await editor.destroy();
  1367. } );
  1368. describe( 'simple cell text content', () => {
  1369. it( 'should not navigate to the cell on the left', () => {
  1370. setModelData( model, modelTable( [
  1371. [ '00', '01', '02' ],
  1372. [ '10', '1[]1', '12' ],
  1373. [ '20', '21', '22' ]
  1374. ] ) );
  1375. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1376. sinon.assert.notCalled( leftArrowDomEvtDataStub.preventDefault );
  1377. sinon.assert.notCalled( leftArrowDomEvtDataStub.stopPropagation );
  1378. } );
  1379. it( 'should not navigate to the cell on the right', () => {
  1380. setModelData( model, modelTable( [
  1381. [ '00', '01', '02' ],
  1382. [ '10', '1[]1', '12' ],
  1383. [ '20', '21', '22' ]
  1384. ] ) );
  1385. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1386. sinon.assert.notCalled( rightArrowDomEvtDataStub.preventDefault );
  1387. sinon.assert.notCalled( rightArrowDomEvtDataStub.stopPropagation );
  1388. } );
  1389. it( 'should not navigate to the cell above', () => {
  1390. setModelData( model, modelTable( [
  1391. [ '00', '01', '02' ],
  1392. [ '10', '1[]1', '12' ],
  1393. [ '20', '21', '22' ]
  1394. ] ) );
  1395. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1396. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1397. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1398. assertEqualMarkup( getModelData( model ), modelTable( [
  1399. [ '00', '01', '02' ],
  1400. [ '10', '[]11', '12' ],
  1401. [ '20', '21', '22' ]
  1402. ] ) );
  1403. } );
  1404. it( 'should not navigate to the cell below', () => {
  1405. setModelData( model, modelTable( [
  1406. [ '00', '01', '02' ],
  1407. [ '10', '1[]1', '12' ],
  1408. [ '20', '21', '22' ]
  1409. ] ) );
  1410. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1411. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1412. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1413. assertEqualMarkup( getModelData( model ), modelTable( [
  1414. [ '00', '01', '02' ],
  1415. [ '10', '11[]', '12' ],
  1416. [ '20', '21', '22' ]
  1417. ] ) );
  1418. } );
  1419. } );
  1420. describe( 'selection inside paragraph', () => {
  1421. const text = new Array( 20 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  1422. it( 'should not navigate if caret is in the middle line of a text', () => {
  1423. setModelData( model, modelTable( [
  1424. [ '00', '01', '02' ],
  1425. [ '10', text + '[] ' + text, '12' ],
  1426. [ '20', '21', '22' ]
  1427. ] ) );
  1428. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1429. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  1430. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  1431. } );
  1432. it( 'should move caret to beginning of cell content if caret is in the first line of a text', () => {
  1433. setModelData( model, modelTable( [
  1434. [ '00', '01', '02' ],
  1435. [ '10', 'word[] word' + text, '12' ],
  1436. [ '20', '21', '22' ]
  1437. ] ) );
  1438. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1439. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1440. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1441. assertEqualMarkup( getModelData( model ), modelTable( [
  1442. [ '00', '01', '02' ],
  1443. [ '10', '[]word word' + text, '12' ],
  1444. [ '20', '21', '22' ]
  1445. ] ) );
  1446. } );
  1447. it( 'should move caret to end of cell content if caret is in the last line of a text', () => {
  1448. setModelData( model, modelTable( [
  1449. [ '00', '01', '02' ],
  1450. [ '10', text + 'word[] word', '12' ],
  1451. [ '20', '21', '22' ]
  1452. ] ) );
  1453. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1454. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1455. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1456. assertEqualMarkup( getModelData( model ), modelTable( [
  1457. [ '00', '01', '02' ],
  1458. [ '10', text + 'word word[]', '12' ],
  1459. [ '20', '21', '22' ]
  1460. ] ) );
  1461. } );
  1462. } );
  1463. if ( !env.isGecko ) {
  1464. // These tests fails on Travis. They work correctly when started on local machine.
  1465. // Issue is probably related to text rendering and wrapping.
  1466. describe( 'with selection in the wrap area', () => {
  1467. const text = new Array( 10 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  1468. it( 'should move the caret to end if the caret is after the last space in the line next to the last one', () => {
  1469. // This is also first position in the last line.
  1470. setModelData( model, modelTable( [
  1471. [ '00', '01', '02' ],
  1472. [ '10', text + ' []word word word', '12' ],
  1473. [ '20', '21', '22' ]
  1474. ] ) );
  1475. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1476. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1477. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1478. assertEqualMarkup( getModelData( model ), modelTable( [
  1479. [ '00', '01', '02' ],
  1480. [ '10', text + ' word word word[]', '12' ],
  1481. [ '20', '21', '22' ]
  1482. ] ) );
  1483. } );
  1484. it( 'should move the caret to end if ther caret is at the last space in the line next to last one', () => {
  1485. setModelData( model, modelTable( [
  1486. [ '00', '01', '02' ],
  1487. [ '10', text + '[] word word word', '12' ],
  1488. [ '20', '21', '22' ]
  1489. ] ) );
  1490. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1491. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1492. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1493. assertEqualMarkup( getModelData( model ), modelTable( [
  1494. [ '00', '01', '02' ],
  1495. [ '10', text + ' word word word[]', '12' ],
  1496. [ '20', '21', '22' ]
  1497. ] ) );
  1498. } );
  1499. it( 'should not move the caret if it\'s just before the last space in the line next to last one', () => {
  1500. setModelData( model, modelTable( [
  1501. [ '00', '01', '02' ],
  1502. [ '10', text.substring( 0, text.length - 1 ) + '[]d word word word', '12' ],
  1503. [ '20', '21', '22' ]
  1504. ] ) );
  1505. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1506. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  1507. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  1508. } );
  1509. } );
  1510. }
  1511. describe( 'with multiple paragraphs of text', () => {
  1512. const text = new Array( 100 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  1513. it( 'should not navigate if caret is in the middle of a line of text', () => {
  1514. setModelData( model, modelTable( [
  1515. [ '00', '01', '02' ],
  1516. [ '10', `<paragraph>${ text }[]${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  1517. [ '20', '21', '22' ]
  1518. ] ) );
  1519. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1520. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  1521. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  1522. } );
  1523. it( 'should move the caret to the beginning of a cell content if the caret is in the first line of text', () => {
  1524. setModelData( model, modelTable( [
  1525. [ '00', '01', '02' ],
  1526. [ '10', `<paragraph>word[]${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  1527. [ '20', '21', '22' ]
  1528. ] ) );
  1529. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1530. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1531. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1532. assertEqualMarkup( getModelData( model ), modelTable( [
  1533. [ '00', '01', '02' ],
  1534. [ '10', `<paragraph>[]word${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  1535. [ '20', '21', '22' ]
  1536. ] ) );
  1537. } );
  1538. it( 'should not move the caret to the end of a cell content if the caret is not in the last line of text', () => {
  1539. setModelData( model, modelTable( [
  1540. [ '00', '01', '02' ],
  1541. [ '10', `<paragraph>${ text }word []word</paragraph><paragraph>foobar</paragraph>`, '12' ],
  1542. [ '20', '21', '22' ]
  1543. ] ) );
  1544. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1545. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  1546. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  1547. } );
  1548. it( 'should move the caret to end of a cell content if the caret is in the last line of text', () => {
  1549. setModelData( model, modelTable( [
  1550. [ '00', '01', '02' ],
  1551. [ '10', `<paragraph>foobar</paragraph><paragraph>${ text }word []word</paragraph>`, '12' ],
  1552. [ '20', '21', '22' ]
  1553. ] ) );
  1554. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1555. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1556. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1557. assertEqualMarkup( getModelData( model ), modelTable( [
  1558. [ '00', '01', '02' ],
  1559. [ '10', `<paragraph>foobar</paragraph><paragraph>${ text }word word[]</paragraph>`, '12' ],
  1560. [ '20', '21', '22' ]
  1561. ] ) );
  1562. } );
  1563. } );
  1564. describe( 'with horizontal line widget', () => {
  1565. const text = new Array( 100 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  1566. it( 'should not navigate if the caret is in the middle line of text', () => {
  1567. setModelData( model, modelTable( [
  1568. [ '00', '01', '02' ],
  1569. [ '10', `<horizontalLine></horizontalLine><paragraph>${ text }[]${ text }</paragraph>`, '12' ],
  1570. [ '20', '21', '22' ]
  1571. ] ) );
  1572. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1573. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  1574. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  1575. } );
  1576. it( 'should move the caret to the beginning of cell content if the caret is in the first line of text', () => {
  1577. setModelData( model, modelTable( [
  1578. [ '00', '01', '02' ],
  1579. [ '10', `<horizontalLine></horizontalLine><paragraph>word[] ${ text }</paragraph>`, '12' ],
  1580. [ '20', '21', '22' ]
  1581. ] ) );
  1582. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1583. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1584. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1585. assertEqualMarkup( getModelData( model ), modelTable( [
  1586. [ '00', '01', '02' ],
  1587. [ '10', `[<horizontalLine></horizontalLine>]<paragraph>word ${ text }</paragraph>`, '12' ],
  1588. [ '20', '21', '22' ]
  1589. ] ) );
  1590. } );
  1591. it( 'should move the caret to the end of cell content if the caret is in the last line of text', () => {
  1592. setModelData( model, modelTable( [
  1593. [ '00', '01', '02' ],
  1594. [ '10', `<paragraph>${ text } word []word</paragraph><horizontalLine></horizontalLine>`, '12' ],
  1595. [ '20', '21', '22' ]
  1596. ] ) );
  1597. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1598. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1599. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1600. assertEqualMarkup( getModelData( model ), modelTable( [
  1601. [ '00', '01', '02' ],
  1602. [ '10', `<paragraph>${ text } word word</paragraph>[<horizontalLine></horizontalLine>]`, '12' ],
  1603. [ '20', '21', '22' ]
  1604. ] ) );
  1605. } );
  1606. it( 'should not move the caret to the end of cell content if widget is selected in middle of a cell content', () => {
  1607. const paragraph = `<paragraph>${ text }</paragraph>`;
  1608. const hr = '<horizontalLine></horizontalLine>';
  1609. setModelData( model, modelTable( [
  1610. [ '00', '01', '02' ],
  1611. [ '10', `${ paragraph }[${ hr }]${ paragraph }${ hr }`, '12' ],
  1612. [ '20', '21', '22' ]
  1613. ] ) );
  1614. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1615. assertEqualMarkup( getModelData( model ), modelTable( [
  1616. [ '00', '01', '02' ],
  1617. [ '10', `${ paragraph }${ hr }<paragraph>[]${ text }</paragraph>${ hr }`, '12' ],
  1618. [ '20', '21', '22' ]
  1619. ] ) );
  1620. } );
  1621. it( 'should not move the caret to the end of cell content if widget is next to the selection', () => {
  1622. const paragraph = `<paragraph>${ text }</paragraph>`;
  1623. const hr = '<horizontalLine></horizontalLine>';
  1624. setModelData( model, modelTable( [
  1625. [ '00', '01', '02' ],
  1626. [ '10', `${ paragraph }[]${ hr }`, '12' ],
  1627. [ '20', '21', '22' ]
  1628. ] ) );
  1629. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1630. assertEqualMarkup( getModelData( model ), modelTable( [
  1631. [ '00', '01', '02' ],
  1632. [ '10', `${ paragraph }[${ hr }]`, '12' ],
  1633. [ '20', '21', '22' ]
  1634. ] ) );
  1635. } );
  1636. } );
  1637. describe( 'contains image widget with caption and selection inside the caption', () => {
  1638. it( 'should not navigate to the cell on the left', () => {
  1639. setModelData( model, modelTable( [
  1640. [ '00', '01', '02' ],
  1641. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  1642. [ '20', '21', '22' ]
  1643. ] ) );
  1644. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1645. sinon.assert.notCalled( leftArrowDomEvtDataStub.preventDefault );
  1646. sinon.assert.notCalled( leftArrowDomEvtDataStub.stopPropagation );
  1647. } );
  1648. it( 'should not navigate to the cell on the right', () => {
  1649. setModelData( model, modelTable( [
  1650. [ '00', '01', '02' ],
  1651. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image><paragraph>foo</paragraph>`, '12' ],
  1652. [ '20', '21', '22' ]
  1653. ] ) );
  1654. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1655. sinon.assert.notCalled( rightArrowDomEvtDataStub.preventDefault );
  1656. sinon.assert.notCalled( rightArrowDomEvtDataStub.stopPropagation );
  1657. } );
  1658. it( 'should not navigate to the cell above', () => {
  1659. setModelData( model, modelTable( [
  1660. [ '00', '01', '02' ],
  1661. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>1[]1</caption></image>`, '12' ],
  1662. [ '20', '21', '22' ]
  1663. ] ) );
  1664. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1665. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  1666. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  1667. } );
  1668. it( 'should not navigate to the cell above but should select the image widget', () => {
  1669. setModelData( model, modelTable( [
  1670. [ '00', '01', '02' ],
  1671. [ '10', `<image src="${ imageUrl }"><caption>1[]1</caption></image><paragraph>foo</paragraph>`, '12' ],
  1672. [ '20', '21', '22' ]
  1673. ] ) );
  1674. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1675. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1676. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1677. assertEqualMarkup( getModelData( model ), modelTable( [
  1678. [ '00', '01', '02' ],
  1679. [ '10', `[<image src="${ imageUrl }"><caption>11</caption></image>]<paragraph>foo</paragraph>`, '12' ],
  1680. [ '20', '21', '22' ]
  1681. ] ) );
  1682. } );
  1683. it( 'should not navigate to the cell below when followed by a paragraph', () => {
  1684. setModelData( model, modelTable( [
  1685. [ '00', '01', '02' ],
  1686. [ '10', `<image src="${ imageUrl }"><caption>1[]1</caption></image><paragraph>foo</paragraph>`, '12' ],
  1687. [ '20', '21', '22' ]
  1688. ] ) );
  1689. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1690. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  1691. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  1692. } );
  1693. it( 'should not navigate to the cell below but should select the image widget', () => {
  1694. setModelData( model, modelTable( [
  1695. [ '00', '01', '02' ],
  1696. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>1[]1</caption></image>`, '12' ],
  1697. [ '20', '21', '22' ]
  1698. ] ) );
  1699. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1700. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1701. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1702. assertEqualMarkup( getModelData( model ), modelTable( [
  1703. [ '00', '01', '02' ],
  1704. [ '10', `<paragraph>foo</paragraph>[<image src="${ imageUrl }"><caption>11</caption></image>]`, '12' ],
  1705. [ '20', '21', '22' ]
  1706. ] ) );
  1707. } );
  1708. it( 'should not navigate to the cell above but should select the image widget without caption', () => {
  1709. setModelData( model, modelTable( [
  1710. [ '00', '01', '02' ],
  1711. [ '10', `<image src="${ imageUrl }"><caption></caption></image><paragraph>f[]oo</paragraph>`, '12' ],
  1712. [ '20', '21', '22' ]
  1713. ] ) );
  1714. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1715. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1716. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1717. assertEqualMarkup( getModelData( model ), modelTable( [
  1718. [ '00', '01', '02' ],
  1719. [ '10', `[<image src="${ imageUrl }"><caption></caption></image>]<paragraph>foo</paragraph>`, '12' ],
  1720. [ '20', '21', '22' ]
  1721. ] ) );
  1722. } );
  1723. it( 'should not navigate to the cell below but should select the image widget without caption', () => {
  1724. setModelData( model, modelTable( [
  1725. [ '00', '01', '02' ],
  1726. [ '10', `<paragraph>f[]oo</paragraph><image src="${ imageUrl }"><caption></caption></image>`, '12' ],
  1727. [ '20', '21', '22' ]
  1728. ] ) );
  1729. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1730. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1731. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1732. assertEqualMarkup( getModelData( model ), modelTable( [
  1733. [ '00', '01', '02' ],
  1734. [ '10', `<paragraph>foo</paragraph>[<image src="${ imageUrl }"><caption></caption></image>]`, '12' ],
  1735. [ '20', '21', '22' ]
  1736. ] ) );
  1737. } );
  1738. } );
  1739. } );
  1740. } );
  1741. describe( 'for right-to-left content language', () => {
  1742. beforeEach( () => {
  1743. return VirtualTestEditor
  1744. .create( {
  1745. plugins: [ TableEditing, TableNavigation, TableSelection, Paragraph, ImageEditing, MediaEmbedEditing ],
  1746. language: 'ar'
  1747. } )
  1748. .then( newEditor => {
  1749. editor = newEditor;
  1750. model = editor.model;
  1751. modelRoot = model.document.getRoot();
  1752. tableSelection = editor.plugins.get( TableSelection );
  1753. } );
  1754. } );
  1755. describe( 'with the table cell selected from outside', () => {
  1756. beforeEach( () => {
  1757. setModelData( model, modelTable( [
  1758. [ '00', '01', '02' ],
  1759. [ '10', '11', '12' ],
  1760. [ '20', '21', '22' ]
  1761. ] ) );
  1762. tableSelection._setCellSelection(
  1763. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1764. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  1765. );
  1766. } );
  1767. it( 'should move to the cell on the right (visually flipped by the browser)', () => {
  1768. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1769. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1770. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1771. assertEqualMarkup( getModelData( model ), modelTable( [
  1772. [ '00', '01', '02' ],
  1773. [ '10', '11', '[]12' ],
  1774. [ '20', '21', '22' ]
  1775. ] ) );
  1776. } );
  1777. it( 'should move to the cell on the left (visually flipped by the browser)', () => {
  1778. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1779. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1780. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1781. assertEqualMarkup( getModelData( model ), modelTable( [
  1782. [ '00', '01', '02' ],
  1783. [ '10[]', '11', '12' ],
  1784. [ '20', '21', '22' ]
  1785. ] ) );
  1786. } );
  1787. it( 'should move to the cell above the selection', () => {
  1788. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1789. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1790. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1791. assertEqualMarkup( getModelData( model ), modelTable( [
  1792. [ '00', '01[]', '02' ],
  1793. [ '10', '11', '12' ],
  1794. [ '20', '21', '22' ]
  1795. ] ) );
  1796. } );
  1797. it( 'should move to the cell below the selection', () => {
  1798. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1799. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1800. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1801. assertEqualMarkup( getModelData( model ), modelTable( [
  1802. [ '00', '01', '02' ],
  1803. [ '10', '11', '12' ],
  1804. [ '20', '[]21', '22' ]
  1805. ] ) );
  1806. } );
  1807. } );
  1808. } );
  1809. } );
  1810. } );