tablenavigation.js 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282
  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 { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
  6. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  7. import { modelTable } from './_utils/utils';
  8. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  9. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  10. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  11. import ImageEditing from '@ckeditor/ckeditor5-image/src/image/imageediting';
  12. import MediaEmbedEditing from '@ckeditor/ckeditor5-media-embed/src/mediaembedediting';
  13. import TableNavigation from '../src/tablenavigation';
  14. import Table from '../src/table';
  15. import TableEditing from '../src/tableediting';
  16. import TableSelection from '../src/tableselection';
  17. import ImageCaptionEditing from '@ckeditor/ckeditor5-image/src/imagecaption/imagecaptionediting';
  18. import HorizontalLineEditing from '@ckeditor/ckeditor5-horizontal-line/src/horizontallineediting';
  19. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  20. import Image from '@ckeditor/ckeditor5-image/src/image';
  21. import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
  22. import HorizontalLine from '@ckeditor/ckeditor5-horizontal-line/src/horizontalline';
  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 not tab pressed', () => {
  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', () => {
  82. it( 'should do nothing if 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 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 first cell in 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 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 next row if on 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 part of block content is 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 next cell with 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 next cell with an blockQuote', () => {
  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 lower priority then 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', () => {
  225. beforeEach( () => {
  226. domEvtDataStub.shiftKey = true;
  227. } );
  228. it( 'should do nothing if 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 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 caret is in 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 previous row if on 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 part of block content is 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 previous cell with 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 not arrow key pressed', () => {
  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 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 proper cell to move 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 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 the cell below when 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 cell 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 left top of 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 right bottom of 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 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 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 left top of 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 right bottom of 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 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 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 left top 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 right bottom 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 selection inside a table cell', () => {
  1038. describe( 'with selection at the edge 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 edge 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. // This 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 caret to end if 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 caret to end if 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 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 line of a 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 caret to beginning of cell content if caret is in the first line of a 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 caret to end of cell content if caret is not 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 caret to end of cell content if caret is in the last line of a 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 caret is in the middle line of a 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 caret to beginning of cell content if caret is in the first line of a 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 caret to end of cell content if caret is in the last line of a 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 caret to end of cell content if widget is selected in middle of 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 caret to end of cell content if widget is next to 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 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 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 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 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 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 (it\'s visually flipped by 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 (it\'s visually flipped by 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 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 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. } );