tablenavigation.js 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062
  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 TableKeyboard from '../src/tablekeyboard';
  6. import Table from '../src/table';
  7. import TableEditing from '../src/tableediting';
  8. import TableSelection from '../src/tableselection';
  9. import { modelTable } from './_utils/utils';
  10. import { getTableCellsContainingSelection } from '../src/utils/selection';
  11. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  12. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  13. import ImageEditing from '@ckeditor/ckeditor5-image/src/image/imageediting';
  14. import MediaEmbedEditing from '@ckeditor/ckeditor5-media-embed/src/mediaembedediting';
  15. import ImageCaptionEditing from '@ckeditor/ckeditor5-image/src/imagecaption/imagecaptionediting';
  16. import HorizontalLineEditing from '@ckeditor/ckeditor5-horizontal-line/src/horizontallineediting';
  17. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  18. import Image from '@ckeditor/ckeditor5-image/src/image';
  19. import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
  20. import HorizontalLine from '@ckeditor/ckeditor5-horizontal-line/src/horizontalline';
  21. import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
  22. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  23. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  24. import global from '@ckeditor/ckeditor5-utils/src/dom/global';
  25. import env from '@ckeditor/ckeditor5-utils/src/env';
  26. describe( 'TableKeyboard', () => {
  27. let editor, model, modelRoot, tableSelection, tableKeyboard, selection;
  28. const imageUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAUCAQAAADRyVAeAAAAKklEQVR42u3PAQ0AAAwCI' +
  29. 'O0f+u/hoAHNZUJFRERERERERERERERERLYiD9N4FAFj2iK6AAAAAElFTkSuQmCC';
  30. beforeEach( () => {
  31. return VirtualTestEditor
  32. .create( {
  33. plugins: [ TableEditing, TableKeyboard, TableSelection, Paragraph, ImageEditing, ImageCaptionEditing, MediaEmbedEditing,
  34. HorizontalLineEditing ]
  35. } )
  36. .then( newEditor => {
  37. editor = newEditor;
  38. model = editor.model;
  39. selection = model.document.selection;
  40. modelRoot = model.document.getRoot();
  41. tableSelection = editor.plugins.get( TableSelection );
  42. tableKeyboard = editor.plugins.get( TableKeyboard );
  43. } );
  44. } );
  45. afterEach( () => {
  46. editor.destroy();
  47. } );
  48. it( 'should have pluginName', () => {
  49. expect( TableKeyboard.pluginName ).to.equal( 'TableKeyboard' );
  50. } );
  51. describe( 'Tab key handling', () => {
  52. let domEvtDataStub;
  53. beforeEach( () => {
  54. domEvtDataStub = {
  55. keyCode: getCode( 'Tab' ),
  56. preventDefault: sinon.spy(),
  57. stopPropagation: sinon.spy()
  58. };
  59. } );
  60. it( 'should do nothing if pressed other key', () => {
  61. setModelData( model, modelTable( [
  62. [ '11', '12[]' ]
  63. ] ) );
  64. domEvtDataStub.keyCode = getCode( 'a' );
  65. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  66. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  67. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  68. assertEqualMarkup( getModelData( model ), modelTable( [
  69. [ '11', '12[]' ]
  70. ] ) );
  71. } );
  72. it( 'should do nothing if Ctrl+Tab is pressed', () => {
  73. setModelData( model, modelTable( [
  74. [ '11', '12[]' ]
  75. ] ) );
  76. domEvtDataStub.ctrlKey = true;
  77. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  78. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  79. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  80. assertEqualMarkup( getModelData( model ), modelTable( [
  81. [ '11', '12[]' ]
  82. ] ) );
  83. } );
  84. describe( 'on Tab key press', () => {
  85. it( 'should do nothing if the selection is not in a table', () => {
  86. setModelData( model, '<paragraph>[]</paragraph>' + modelTable( [ [ '11', '12' ] ] ) );
  87. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  88. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  89. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  90. assertEqualMarkup( getModelData( model ), '<paragraph>[]</paragraph>' + modelTable( [
  91. [ '11', '12' ]
  92. ] ) );
  93. } );
  94. it( 'should move to the next cell', () => {
  95. setModelData( model, modelTable( [
  96. [ '11[]', '12' ]
  97. ] ) );
  98. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  99. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  100. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  101. assertEqualMarkup( getModelData( model ), modelTable( [
  102. [ '11', '[12]' ]
  103. ] ) );
  104. } );
  105. it( 'should create another row and move to the first cell in a new row', () => {
  106. setModelData( model, modelTable( [
  107. [ '11', '[12]' ]
  108. ] ) );
  109. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  110. assertEqualMarkup( getModelData( model ), modelTable( [
  111. [ '11', '12' ],
  112. [ '[]', '' ]
  113. ] ) );
  114. } );
  115. it( 'should not create another row and not move the caret if the "insertTableRowBelow" command is disabled', () => {
  116. setModelData( model, modelTable( [
  117. [ '11', '12[]' ]
  118. ] ) );
  119. const insertTableRowBelowCommand = editor.commands.get( 'insertTableRowBelow' );
  120. insertTableRowBelowCommand.forceDisabled( 'test' );
  121. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  122. assertEqualMarkup( getModelData( model ), modelTable( [
  123. [ '11', '12[]' ]
  124. ] ) );
  125. } );
  126. it( 'should move to the first cell of the next row if at the end of a row', () => {
  127. setModelData( model, modelTable( [
  128. [ '11', '12[]' ],
  129. [ '21', '22' ]
  130. ] ) );
  131. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  132. assertEqualMarkup( getModelData( model ), modelTable( [
  133. [ '11', '12' ],
  134. [ '[21]', '22' ]
  135. ] ) );
  136. } );
  137. it( 'should move to the next table cell if the block content is partially selected', () => {
  138. setModelData( model, modelTable( [
  139. [ '11', '<paragraph>12</paragraph><paragraph>[foo]</paragraph><paragraph>bar</paragraph>', '13' ]
  140. ] ) );
  141. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  142. assertEqualMarkup( getModelData( model ), modelTable( [
  143. [
  144. '11',
  145. '<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>',
  146. '[13]'
  147. ]
  148. ] ) );
  149. } );
  150. it( 'should move to the next cell containing an image', () => {
  151. setModelData( model, modelTable( [
  152. [ '11[]', '<paragraph>foo</paragraph><image><caption></caption></image>' ]
  153. ] ) );
  154. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  155. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  156. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  157. assertEqualMarkup( getModelData( model ), modelTable( [
  158. [ '11', '<paragraph>[foo</paragraph><image><caption></caption></image>]' ]
  159. ] ) );
  160. } );
  161. it( 'should move to the next cell containing a block quote', () => {
  162. model.schema.register( 'blockQuote', {
  163. allowWhere: '$block',
  164. allowContentOf: '$root'
  165. } );
  166. editor.conversion.elementToElement( { model: 'blockQuote', view: 'blockquote' } );
  167. setModelData( model, modelTable( [
  168. [ '11[]', '<blockQuote><paragraph>foo</paragraph></blockQuote>' ]
  169. ] ) );
  170. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  171. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  172. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  173. assertEqualMarkup( getModelData( model ), modelTable( [
  174. [ '11', '<blockQuote><paragraph>[foo]</paragraph></blockQuote>' ]
  175. ] ) );
  176. } );
  177. it( 'should listen with the lower priority than its children', () => {
  178. // Cancel TAB event.
  179. editor.keystrokes.set( 'Tab', ( data, cancel ) => cancel() );
  180. setModelData( model, modelTable( [
  181. [ '11[]', '12' ]
  182. ] ) );
  183. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  184. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  185. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  186. assertEqualMarkup( getModelData( model ), modelTable( [
  187. [ '11[]', '12' ]
  188. ] ) );
  189. } );
  190. describe( 'on table widget selected', () => {
  191. beforeEach( () => {
  192. editor.model.schema.register( 'block', {
  193. allowWhere: '$block',
  194. allowContentOf: '$block',
  195. isObject: true
  196. } );
  197. editor.conversion.elementToElement( { model: 'block', view: 'block' } );
  198. } );
  199. it( 'should move caret to the first table cell on TAB', () => {
  200. const spy = sinon.spy();
  201. editor.keystrokes.set( 'Tab', spy, { priority: 'lowest' } );
  202. setModelData( model, '[' + modelTable( [
  203. [ '11', '12' ]
  204. ] ) + ']' );
  205. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  206. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  207. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  208. assertEqualMarkup( getModelData( model ), modelTable( [
  209. [ '[11]', '12' ]
  210. ] ) );
  211. // Should cancel event - so no other tab handler is called.
  212. sinon.assert.notCalled( spy );
  213. } );
  214. it( 'shouldn\'t do anything on other blocks', () => {
  215. const spy = sinon.spy();
  216. editor.editing.view.document.on( 'keydown', spy );
  217. setModelData( model, '[<block>foo</block>]' );
  218. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  219. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  220. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  221. assertEqualMarkup( getModelData( model ), '[<block>foo</block>]' );
  222. // Should not cancel event.
  223. sinon.assert.calledOnce( spy );
  224. } );
  225. } );
  226. } );
  227. describe( 'on Shift+Tab key press', () => {
  228. beforeEach( () => {
  229. domEvtDataStub.shiftKey = true;
  230. } );
  231. it( 'should do nothing if the selection is not in a table', () => {
  232. setModelData( model, '<paragraph>[]</paragraph>' + modelTable( [
  233. [ '11', '12' ]
  234. ] ) );
  235. domEvtDataStub.keyCode = getCode( 'Tab' );
  236. domEvtDataStub.shiftKey = true;
  237. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  238. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  239. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  240. assertEqualMarkup( getModelData( model ), '<paragraph>[]</paragraph>' + modelTable( [
  241. [ '11', '12' ]
  242. ] ) );
  243. } );
  244. it( 'should move to the previous cell', () => {
  245. setModelData( model, modelTable( [
  246. [ '11', '12[]' ]
  247. ] ) );
  248. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  249. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  250. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  251. assertEqualMarkup( getModelData( model ), modelTable( [
  252. [ '[11]', '12' ]
  253. ] ) );
  254. } );
  255. it( 'should not move if the caret is in the first table cell', () => {
  256. setModelData( model, '<paragraph>foo</paragraph>' + modelTable( [
  257. [ '[]11', '12' ]
  258. ] ) );
  259. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  260. assertEqualMarkup( getModelData( model ),
  261. '<paragraph>foo</paragraph>' + modelTable( [ [ '[]11', '12' ] ] )
  262. );
  263. } );
  264. it( 'should move to the last cell of a previous row if at the beginning of a row', () => {
  265. setModelData( model, modelTable( [
  266. [ '11', '12' ],
  267. [ '[]21', '22' ]
  268. ] ) );
  269. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  270. assertEqualMarkup( getModelData( model ), modelTable( [
  271. [ '11', '[12]' ],
  272. [ '21', '22' ]
  273. ] ) );
  274. } );
  275. it( 'should move to the previous table cell if the block content is partially selected', () => {
  276. setModelData( model, modelTable( [
  277. [ '11', '<paragraph>12</paragraph><paragraph>[foo]</paragraph><paragraph>bar</paragraph>', '13' ]
  278. ] ) );
  279. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  280. assertEqualMarkup( getModelData( model ), modelTable( [
  281. [
  282. '[11]',
  283. '<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>',
  284. '13'
  285. ]
  286. ] ) );
  287. } );
  288. it( 'should move to the previous cell containing an image', () => {
  289. setModelData( model, modelTable( [
  290. [ '<paragraph>foo</paragraph><image><caption></caption></image>', 'bar[]' ]
  291. ] ) );
  292. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  293. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  294. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  295. assertEqualMarkup( getModelData( model ), modelTable( [
  296. [ '<paragraph>[foo</paragraph><image><caption></caption></image>]', 'bar' ]
  297. ] ) );
  298. } );
  299. } );
  300. } );
  301. describe( 'Arrow keys handling', () => {
  302. let leftArrowDomEvtDataStub, rightArrowDomEvtDataStub, upArrowDomEvtDataStub, downArrowDomEvtDataStub;
  303. beforeEach( () => {
  304. leftArrowDomEvtDataStub = {
  305. keyCode: getCode( 'ArrowLeft' ),
  306. preventDefault: sinon.spy(),
  307. stopPropagation: sinon.spy(),
  308. domTarget: global.document.body
  309. };
  310. rightArrowDomEvtDataStub = {
  311. keyCode: getCode( 'ArrowRight' ),
  312. preventDefault: sinon.spy(),
  313. stopPropagation: sinon.spy(),
  314. domTarget: global.document.body
  315. };
  316. upArrowDomEvtDataStub = {
  317. keyCode: getCode( 'ArrowUp' ),
  318. preventDefault: sinon.spy(),
  319. stopPropagation: sinon.spy(),
  320. domTarget: global.document.body
  321. };
  322. downArrowDomEvtDataStub = {
  323. keyCode: getCode( 'ArrowDown' ),
  324. preventDefault: sinon.spy(),
  325. stopPropagation: sinon.spy(),
  326. domTarget: global.document.body
  327. };
  328. } );
  329. it( 'should do nothing if pressed some non-arrow key', () => {
  330. setModelData( model, modelTable( [
  331. [ '00', '01[]' ]
  332. ] ) );
  333. leftArrowDomEvtDataStub.keyCode = getCode( 'a' );
  334. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  335. sinon.assert.notCalled( leftArrowDomEvtDataStub.preventDefault );
  336. sinon.assert.notCalled( leftArrowDomEvtDataStub.stopPropagation );
  337. assertEqualMarkup( getModelData( model ), modelTable( [
  338. [ '00', '01[]' ]
  339. ] ) );
  340. } );
  341. it( 'should do nothing if the selection is not in a table', () => {
  342. const modelData = '<paragraph>[]foobar</paragraph>' + modelTable( [ [ '00', '01' ] ] );
  343. setModelData( model, modelData );
  344. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  345. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  346. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  347. assertEqualMarkup( getModelData( model ), modelData );
  348. } );
  349. describe( '#_navigateFromCellInDirection (finding a proper cell to move the selection to)', () => {
  350. describe( 'with no col/row-spanned cells', () => {
  351. beforeEach( () => {
  352. setModelData( model, '<paragraph>foo</paragraph>' + modelTable( [
  353. [ '00', '01', '02' ],
  354. [ '10', '11', '12' ],
  355. [ '20', '21', '22' ]
  356. ] ) + '<paragraph>bar</paragraph>' );
  357. } );
  358. describe( 'from the first table cell', () => {
  359. let tableCell;
  360. beforeEach( () => {
  361. tableCell = modelRoot.getNodeByPath( [ 1, 0, 0 ] );
  362. } );
  363. it( 'should navigate to the start position of the cell on the right when the direction is "right"', () => {
  364. tableKeyboard._navigateFromCellInDirection( tableCell, 'right' );
  365. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  366. [ '00', '[]01', '02' ],
  367. [ '10', '11', '12' ],
  368. [ '20', '21', '22' ]
  369. ] ) + '<paragraph>bar</paragraph>' );
  370. } );
  371. it( 'should navigate to the start position of the cell below when the direction is "down"', () => {
  372. tableKeyboard._navigateFromCellInDirection( tableCell, 'down' );
  373. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  374. [ '00', '01', '02' ],
  375. [ '[]10', '11', '12' ],
  376. [ '20', '21', '22' ]
  377. ] ) + '<paragraph>bar</paragraph>' );
  378. } );
  379. it( 'should select a whole table when the direction is "up"', () => {
  380. tableKeyboard._navigateFromCellInDirection( tableCell, 'up' );
  381. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>[' + modelTable( [
  382. [ '00', '01', '02' ],
  383. [ '10', '11', '12' ],
  384. [ '20', '21', '22' ]
  385. ] ) + ']<paragraph>bar</paragraph>' );
  386. } );
  387. it( 'should select a whole table when the direction is "left"', () => {
  388. tableKeyboard._navigateFromCellInDirection( tableCell, 'left' );
  389. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>[' + modelTable( [
  390. [ '00', '01', '02' ],
  391. [ '10', '11', '12' ],
  392. [ '20', '21', '22' ]
  393. ] ) + ']<paragraph>bar</paragraph>' );
  394. } );
  395. } );
  396. describe( 'from the last table cell', () => {
  397. let tableCell;
  398. beforeEach( () => {
  399. tableCell = modelRoot.getNodeByPath( [ 1, 2, 2 ] );
  400. } );
  401. it( 'should navigate to the end position of the cell on the left when the direction is "left"', () => {
  402. tableKeyboard._navigateFromCellInDirection( tableCell, 'left' );
  403. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  404. [ '00', '01', '02' ],
  405. [ '10', '11', '12' ],
  406. [ '20', '21[]', '22' ]
  407. ] ) + '<paragraph>bar</paragraph>' );
  408. } );
  409. it( 'should navigate to the end position of the cell above when the direction is "up"', () => {
  410. tableKeyboard._navigateFromCellInDirection( tableCell, 'up' );
  411. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  412. [ '00', '01', '02' ],
  413. [ '10', '11', '12[]' ],
  414. [ '20', '21', '22' ]
  415. ] ) + '<paragraph>bar</paragraph>' );
  416. } );
  417. it( 'should select a whole table when the direction is "down"', () => {
  418. tableKeyboard._navigateFromCellInDirection( tableCell, 'down' );
  419. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>[' + modelTable( [
  420. [ '00', '01', '02' ],
  421. [ '10', '11', '12' ],
  422. [ '20', '21', '22' ]
  423. ] ) + ']<paragraph>bar</paragraph>' );
  424. } );
  425. it( 'should select a whole table when the direction is "right"', () => {
  426. tableKeyboard._navigateFromCellInDirection( tableCell, 'right' );
  427. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>[' + modelTable( [
  428. [ '00', '01', '02' ],
  429. [ '10', '11', '12' ],
  430. [ '20', '21', '22' ]
  431. ] ) + ']<paragraph>bar</paragraph>' );
  432. } );
  433. } );
  434. describe( 'from a cell in the first column (but not first row)', () => {
  435. let tableCell;
  436. beforeEach( () => {
  437. tableCell = modelRoot.getNodeByPath( [ 1, 1, 0 ] );
  438. } );
  439. it( 'should navigate to start position of the cell on the right when the direction is "right"', () => {
  440. tableKeyboard._navigateFromCellInDirection( tableCell, 'right' );
  441. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  442. [ '00', '01', '02' ],
  443. [ '10', '[]11', '12' ],
  444. [ '20', '21', '22' ]
  445. ] ) + '<paragraph>bar</paragraph>' );
  446. } );
  447. it( 'should navigate to the end position of the cell above when the direction is "up"', () => {
  448. tableKeyboard._navigateFromCellInDirection( tableCell, 'up' );
  449. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  450. [ '00[]', '01', '02' ],
  451. [ '10', '11', '12' ],
  452. [ '20', '21', '22' ]
  453. ] ) + '<paragraph>bar</paragraph>' );
  454. } );
  455. it( 'should navigate to the start position of the cell below when the direction is "down"', () => {
  456. tableKeyboard._navigateFromCellInDirection( tableCell, 'down' );
  457. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  458. [ '00', '01', '02' ],
  459. [ '10', '11', '12' ],
  460. [ '[]20', '21', '22' ]
  461. ] ) + '<paragraph>bar</paragraph>' );
  462. } );
  463. it( 'should navigate to the end position of the last cell in the previous row when the direction is "left"', () => {
  464. tableKeyboard._navigateFromCellInDirection( tableCell, 'left' );
  465. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  466. [ '00', '01', '02[]' ],
  467. [ '10', '11', '12' ],
  468. [ '20', '21', '22' ]
  469. ] ) + '<paragraph>bar</paragraph>' );
  470. } );
  471. } );
  472. describe( 'from a cell in the last column (but not the last row)', () => {
  473. let tableCell;
  474. beforeEach( () => {
  475. tableCell = modelRoot.getNodeByPath( [ 1, 1, 2 ] );
  476. } );
  477. it( 'should navigate to the end position of the cell on the left when the direction is "left"', () => {
  478. tableKeyboard._navigateFromCellInDirection( tableCell, 'left' );
  479. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  480. [ '00', '01', '02' ],
  481. [ '10', '11[]', '12' ],
  482. [ '20', '21', '22' ]
  483. ] ) + '<paragraph>bar</paragraph>' );
  484. } );
  485. it( 'should navigate to the end position the cell above when the direction is "up"', () => {
  486. tableKeyboard._navigateFromCellInDirection( tableCell, 'up' );
  487. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  488. [ '00', '01', '02[]' ],
  489. [ '10', '11', '12' ],
  490. [ '20', '21', '22' ]
  491. ] ) + '<paragraph>bar</paragraph>' );
  492. } );
  493. it( 'should navigate to the start position of the cell below when the direction is "down"', () => {
  494. tableKeyboard._navigateFromCellInDirection( tableCell, 'down' );
  495. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  496. [ '00', '01', '02' ],
  497. [ '10', '11', '12' ],
  498. [ '20', '21', '[]22' ]
  499. ] ) + '<paragraph>bar</paragraph>' );
  500. } );
  501. it( 'should navigate to the start position of the first cell in the next row when the direction is "right"', () => {
  502. tableKeyboard._navigateFromCellInDirection( tableCell, 'right' );
  503. assertEqualMarkup( getModelData( model ), '<paragraph>foo</paragraph>' + modelTable( [
  504. [ '00', '01', '02' ],
  505. [ '10', '11', '12' ],
  506. [ '[]20', '21', '22' ]
  507. ] ) + '<paragraph>bar</paragraph>' );
  508. } );
  509. } );
  510. } );
  511. describe( 'with col/row-spanned cells', () => {
  512. beforeEach( () => {
  513. // +----+----+----+----+----+
  514. // | 00 | 01 | 02 | 03 | 04 |
  515. // +----+----+----+----+----+
  516. // | 10 | 11 | 13 | 14 |
  517. // +----+ + +----+
  518. // | 20 | | | 24 |
  519. // +----+----+----+----+----+
  520. // | 30 | 31 | 33 | 34 |
  521. // +----+----+----+----+----+
  522. // | 40 | 41 | 42 | 43 | 44 |
  523. // +----+----+----+----+----+
  524. setModelData( model, modelTable( [
  525. [ '00', '01', '02', '03', '04' ],
  526. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  527. [ '20', '24' ],
  528. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  529. [ '40', '41', '42', '43', '44' ]
  530. ] ) );
  531. } );
  532. describe( 'when navigating to the right', () => {
  533. it( 'should navigate to the row-col-spanned cell when approaching from the upper-spanned row', () => {
  534. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 0 ] );
  535. tableKeyboard._navigateFromCellInDirection( tableCell, 'right' );
  536. assertEqualMarkup( getModelData( model ), modelTable( [
  537. [ '00', '01', '02', '03', '04' ],
  538. [ '10', { contents: '[]11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  539. [ '20', '24' ],
  540. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  541. [ '40', '41', '42', '43', '44' ]
  542. ] ) );
  543. } );
  544. it( 'should navigate to the row-col-spanned cell when approaching from the lower-spanned row', () => {
  545. const tableCell = modelRoot.getNodeByPath( [ 0, 2, 0 ] );
  546. tableKeyboard._navigateFromCellInDirection( tableCell, 'right' );
  547. assertEqualMarkup( getModelData( model ), modelTable( [
  548. [ '00', '01', '02', '03', '04' ],
  549. [ '10', { contents: '[]11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  550. [ '20', '24' ],
  551. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  552. [ '40', '41', '42', '43', '44' ]
  553. ] ) );
  554. } );
  555. it( 'should navigate to the row-spanned cell when approaching from the other row-spanned cell', () => {
  556. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  557. tableKeyboard._navigateFromCellInDirection( tableCell, 'right' );
  558. assertEqualMarkup( getModelData( model ), modelTable( [
  559. [ '00', '01', '02', '03', '04' ],
  560. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '[]13', rowspan: 2 }, '14' ],
  561. [ '20', '24' ],
  562. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  563. [ '40', '41', '42', '43', '44' ]
  564. ] ) );
  565. } );
  566. it( 'should navigate to the cell in the upper-spanned row when approaching from the row-spanned cell', () => {
  567. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 2 ] ); // Cell 13.
  568. tableKeyboard._navigateFromCellInDirection( tableCell, 'right' );
  569. assertEqualMarkup( getModelData( model ), modelTable( [
  570. [ '00', '01', '02', '03', '04' ],
  571. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '[]14' ],
  572. [ '20', '24' ],
  573. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  574. [ '40', '41', '42', '43', '44' ]
  575. ] ) );
  576. } );
  577. it( 'should navigate to the col-spanned cell', () => {
  578. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 0 ] );
  579. tableKeyboard._navigateFromCellInDirection( tableCell, 'right' );
  580. assertEqualMarkup( getModelData( model ), modelTable( [
  581. [ '00', '01', '02', '03', '04' ],
  582. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  583. [ '20', '24' ],
  584. [ '30', { contents: '[]31', colspan: 2 }, '33', '34' ],
  585. [ '40', '41', '42', '43', '44' ]
  586. ] ) );
  587. } );
  588. it( 'should navigate from the col-spanned cell', () => {
  589. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 1 ] );
  590. tableKeyboard._navigateFromCellInDirection( tableCell, 'right' );
  591. assertEqualMarkup( getModelData( model ), modelTable( [
  592. [ '00', '01', '02', '03', '04' ],
  593. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  594. [ '20', '24' ],
  595. [ '30', { contents: '31', colspan: 2 }, '[]33', '34' ],
  596. [ '40', '41', '42', '43', '44' ]
  597. ] ) );
  598. } );
  599. } );
  600. describe( 'when navigating to the left', () => {
  601. it( 'should navigate to the row-spanned cell when approaching from the upper-spanned row', () => {
  602. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 3 ] ); // Cell 14.
  603. tableKeyboard._navigateFromCellInDirection( tableCell, 'left' );
  604. assertEqualMarkup( getModelData( model ), modelTable( [
  605. [ '00', '01', '02', '03', '04' ],
  606. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13[]', rowspan: 2 }, '14' ],
  607. [ '20', '24' ],
  608. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  609. [ '40', '41', '42', '43', '44' ]
  610. ] ) );
  611. } );
  612. it( 'should navigate to the row-spanned cell when approaching from the lower-spanned row', () => {
  613. const tableCell = modelRoot.getNodeByPath( [ 0, 2, 1 ] ); // Cell 24.
  614. tableKeyboard._navigateFromCellInDirection( tableCell, 'left' );
  615. assertEqualMarkup( getModelData( model ), modelTable( [
  616. [ '00', '01', '02', '03', '04' ],
  617. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13[]', rowspan: 2 }, '14' ],
  618. [ '20', '24' ],
  619. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  620. [ '40', '41', '42', '43', '44' ]
  621. ] ) );
  622. } );
  623. it( 'should navigate to the row-spanned cell when approaching from the other row-spanned cell', () => {
  624. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 2 ] ); // Cell 13.
  625. tableKeyboard._navigateFromCellInDirection( tableCell, 'left' );
  626. assertEqualMarkup( getModelData( model ), modelTable( [
  627. [ '00', '01', '02', '03', '04' ],
  628. [ '10', { contents: '11[]', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  629. [ '20', '24' ],
  630. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  631. [ '40', '41', '42', '43', '44' ]
  632. ] ) );
  633. } );
  634. it( 'should navigate to the cell in the upper-spanned row when approaching from the row-spanned cell', () => {
  635. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] ); // Cell 11.
  636. tableKeyboard._navigateFromCellInDirection( tableCell, 'left' );
  637. assertEqualMarkup( getModelData( model ), modelTable( [
  638. [ '00', '01', '02', '03', '04' ],
  639. [ '10[]', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  640. [ '20', '24' ],
  641. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  642. [ '40', '41', '42', '43', '44' ]
  643. ] ) );
  644. } );
  645. it( 'should navigate to the col-spanned cell', () => {
  646. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 2 ] ); // Cell 33.
  647. tableKeyboard._navigateFromCellInDirection( tableCell, 'left' );
  648. assertEqualMarkup( getModelData( model ), modelTable( [
  649. [ '00', '01', '02', '03', '04' ],
  650. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  651. [ '20', '24' ],
  652. [ '30', { contents: '31[]', colspan: 2 }, '33', '34' ],
  653. [ '40', '41', '42', '43', '44' ]
  654. ] ) );
  655. } );
  656. it( 'should navigate from the col-spanned cell', () => {
  657. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 1 ] );
  658. tableKeyboard._navigateFromCellInDirection( tableCell, 'left' );
  659. assertEqualMarkup( getModelData( model ), modelTable( [
  660. [ '00', '01', '02', '03', '04' ],
  661. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  662. [ '20', '24' ],
  663. [ '30[]', { contents: '31', colspan: 2 }, '33', '34' ],
  664. [ '40', '41', '42', '43', '44' ]
  665. ] ) );
  666. } );
  667. } );
  668. describe( 'when navigating down', () => {
  669. it( 'should navigate to the row-col-spanned cell when approaching from the first spanned column', () => {
  670. const tableCell = modelRoot.getNodeByPath( [ 0, 0, 1 ] );
  671. tableKeyboard._navigateFromCellInDirection( tableCell, 'down' );
  672. assertEqualMarkup( getModelData( model ), modelTable( [
  673. [ '00', '01', '02', '03', '04' ],
  674. [ '10', { contents: '[]11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  675. [ '20', '24' ],
  676. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  677. [ '40', '41', '42', '43', '44' ]
  678. ] ) );
  679. } );
  680. it( 'should navigate to the row-col-spanned cell when approaching from the last spanned column', () => {
  681. const tableCell = modelRoot.getNodeByPath( [ 0, 0, 2 ] );
  682. tableKeyboard._navigateFromCellInDirection( tableCell, 'down' );
  683. assertEqualMarkup( getModelData( model ), modelTable( [
  684. [ '00', '01', '02', '03', '04' ],
  685. [ '10', { contents: '[]11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  686. [ '20', '24' ],
  687. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  688. [ '40', '41', '42', '43', '44' ]
  689. ] ) );
  690. } );
  691. it( 'should navigate to the row-spanned cell when approaching from the other col-spanned cell', () => {
  692. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  693. tableKeyboard._navigateFromCellInDirection( tableCell, 'down' );
  694. assertEqualMarkup( getModelData( model ), modelTable( [
  695. [ '00', '01', '02', '03', '04' ],
  696. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  697. [ '20', '24' ],
  698. [ '30', { contents: '[]31', colspan: 2 }, '33', '34' ],
  699. [ '40', '41', '42', '43', '44' ]
  700. ] ) );
  701. } );
  702. it( 'should navigate to the cell in the first spanned column when approaching from the col-spanned cell', () => {
  703. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] ); // Cell 11.
  704. tableKeyboard._navigateFromCellInDirection( tableCell, 'down' );
  705. assertEqualMarkup( getModelData( model ), modelTable( [
  706. [ '00', '01', '02', '03', '04' ],
  707. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  708. [ '20', '24' ],
  709. [ '30', { contents: '[]31', colspan: 2 }, '33', '34' ],
  710. [ '40', '41', '42', '43', '44' ]
  711. ] ) );
  712. } );
  713. it( 'should navigate to the row-spanned cell', () => {
  714. const tableCell = modelRoot.getNodeByPath( [ 0, 0, 3 ] );
  715. tableKeyboard._navigateFromCellInDirection( tableCell, 'down' );
  716. assertEqualMarkup( getModelData( model ), modelTable( [
  717. [ '00', '01', '02', '03', '04' ],
  718. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '[]13', rowspan: 2 }, '14' ],
  719. [ '20', '24' ],
  720. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  721. [ '40', '41', '42', '43', '44' ]
  722. ] ) );
  723. } );
  724. it( 'should navigate from the row-spanned cell', () => {
  725. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 2 ] ); // Cell 13.
  726. tableKeyboard._navigateFromCellInDirection( tableCell, 'down' );
  727. assertEqualMarkup( getModelData( model ), modelTable( [
  728. [ '00', '01', '02', '03', '04' ],
  729. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  730. [ '20', '24' ],
  731. [ '30', { contents: '31', colspan: 2 }, '[]33', '34' ],
  732. [ '40', '41', '42', '43', '44' ]
  733. ] ) );
  734. } );
  735. } );
  736. describe( 'when navigating up', () => {
  737. it( 'should navigate to the col-spanned cell when approaching from the first spanned column', () => {
  738. const tableCell = modelRoot.getNodeByPath( [ 0, 4, 1 ] );
  739. tableKeyboard._navigateFromCellInDirection( tableCell, 'up' );
  740. assertEqualMarkup( getModelData( model ), modelTable( [
  741. [ '00', '01', '02', '03', '04' ],
  742. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  743. [ '20', '24' ],
  744. [ '30', { contents: '31[]', colspan: 2 }, '33', '34' ],
  745. [ '40', '41', '42', '43', '44' ]
  746. ] ) );
  747. } );
  748. it( 'should navigate to the col-spanned cell when approaching from the last spanned column', () => {
  749. const tableCell = modelRoot.getNodeByPath( [ 0, 4, 2 ] );
  750. tableKeyboard._navigateFromCellInDirection( tableCell, 'up' );
  751. assertEqualMarkup( getModelData( model ), modelTable( [
  752. [ '00', '01', '02', '03', '04' ],
  753. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  754. [ '20', '24' ],
  755. [ '30', { contents: '31[]', colspan: 2 }, '33', '34' ],
  756. [ '40', '41', '42', '43', '44' ]
  757. ] ) );
  758. } );
  759. it( 'should navigate to the row-col-spanned cell when approaching from the other col-spanned cell', () => {
  760. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 1 ] );
  761. tableKeyboard._navigateFromCellInDirection( tableCell, 'up' );
  762. assertEqualMarkup( getModelData( model ), modelTable( [
  763. [ '00', '01', '02', '03', '04' ],
  764. [ '10', { contents: '11[]', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  765. [ '20', '24' ],
  766. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  767. [ '40', '41', '42', '43', '44' ]
  768. ] ) );
  769. } );
  770. it( 'should navigate to the cell in the first spanned column when approaching from the col-spanned cell', () => {
  771. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  772. tableKeyboard._navigateFromCellInDirection( tableCell, 'up' );
  773. assertEqualMarkup( getModelData( model ), modelTable( [
  774. [ '00', '01[]', '02', '03', '04' ],
  775. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  776. [ '20', '24' ],
  777. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  778. [ '40', '41', '42', '43', '44' ]
  779. ] ) );
  780. } );
  781. it( 'should navigate to the row-spanned cell', () => {
  782. const tableCell = modelRoot.getNodeByPath( [ 0, 3, 2 ] ); // Cell 33.
  783. tableKeyboard._navigateFromCellInDirection( tableCell, 'up' );
  784. assertEqualMarkup( getModelData( model ), modelTable( [
  785. [ '00', '01', '02', '03', '04' ],
  786. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13[]', rowspan: 2 }, '14' ],
  787. [ '20', '24' ],
  788. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  789. [ '40', '41', '42', '43', '44' ]
  790. ] ) );
  791. } );
  792. it( 'should navigate from the row-spanned cell', () => {
  793. const tableCell = modelRoot.getNodeByPath( [ 0, 1, 2 ] ); // Cell 13.
  794. tableKeyboard._navigateFromCellInDirection( tableCell, 'up' );
  795. assertEqualMarkup( getModelData( model ), modelTable( [
  796. [ '00', '01', '02', '03[]', '04' ],
  797. [ '10', { contents: '11', colspan: 2, rowspan: 2 }, { contents: '13', rowspan: 2 }, '14' ],
  798. [ '20', '24' ],
  799. [ '30', { contents: '31', colspan: 2 }, '33', '34' ],
  800. [ '40', '41', '42', '43', '44' ]
  801. ] ) );
  802. } );
  803. } );
  804. } );
  805. describe( 'when expanding selection', () => {
  806. beforeEach( () => {
  807. setModelData( model, modelTable( [
  808. [ '00[]', '01', '02' ],
  809. [ '10', '11', '12' ],
  810. [ '20', '21', '22' ]
  811. ] ) );
  812. } );
  813. describe( 'from the first table cell', () => {
  814. let tableCell;
  815. beforeEach( () => {
  816. tableCell = getTableCellsContainingSelection( selection )[ 0 ];
  817. } );
  818. it( 'should expand the selection to the cell on the right when the direction is "right"', () => {
  819. tableKeyboard._navigateFromCellInDirection( tableCell, 'right', true );
  820. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  821. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) );
  822. expect( selection.rangeCount ).to.equal( 2 );
  823. } );
  824. it( 'should expand the selection to the cell below when the direction is "down"', () => {
  825. tableKeyboard._navigateFromCellInDirection( tableCell, 'down', true );
  826. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  827. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 0 ] ) );
  828. expect( selection.rangeCount ).to.equal( 2 );
  829. } );
  830. it( 'should select a whole table when the direction is "up"', () => {
  831. tableKeyboard._navigateFromCellInDirection( tableCell, 'up', true );
  832. assertEqualMarkup( getModelData( model ), '[' + modelTable( [
  833. [ '00', '01', '02' ],
  834. [ '10', '11', '12' ],
  835. [ '20', '21', '22' ]
  836. ] ) + ']' );
  837. } );
  838. it( 'should select a whole table when the direction is "left"', () => {
  839. tableKeyboard._navigateFromCellInDirection( tableCell, 'left', true );
  840. assertEqualMarkup( getModelData( model ), '[' + modelTable( [
  841. [ '00', '01', '02' ],
  842. [ '10', '11', '12' ],
  843. [ '20', '21', '22' ]
  844. ] ) + ']' );
  845. } );
  846. } );
  847. describe( 'from the last table cell', () => {
  848. let tableCell;
  849. beforeEach( () => {
  850. tableCell = modelRoot.getNodeByPath( [ 0, 2, 2 ] );
  851. tableSelection.setCellSelection( tableCell, tableCell );
  852. } );
  853. it( 'should expand the selection to the cell on the left when the direction is "left"', () => {
  854. tableKeyboard._navigateFromCellInDirection( tableCell, 'left', true );
  855. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  856. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 1 ] ) );
  857. expect( selection.rangeCount ).to.equal( 2 );
  858. } );
  859. it( 'should expand the selection to the cell above when the direction is "up"', () => {
  860. tableKeyboard._navigateFromCellInDirection( tableCell, 'up', true );
  861. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  862. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 2 ] ) );
  863. expect( selection.rangeCount ).to.equal( 2 );
  864. } );
  865. it( 'should select a whole table when the direction is "down"', () => {
  866. tableKeyboard._navigateFromCellInDirection( tableCell, 'down', true );
  867. assertEqualMarkup( getModelData( model ), '[' + modelTable( [
  868. [ '00', '01', '02' ],
  869. [ '10', '11', '12' ],
  870. [ '20', '21', '22' ]
  871. ] ) + ']' );
  872. } );
  873. it( 'should select a whole table when the direction is "right"', () => {
  874. tableKeyboard._navigateFromCellInDirection( tableCell, 'right', true );
  875. assertEqualMarkup( getModelData( model ), '[' + modelTable( [
  876. [ '00', '01', '02' ],
  877. [ '10', '11', '12' ],
  878. [ '20', '21', '22' ]
  879. ] ) + ']' );
  880. } );
  881. } );
  882. describe( 'from a cell in the first column (but not first row)', () => {
  883. let tableCell;
  884. beforeEach( () => {
  885. tableCell = modelRoot.getNodeByPath( [ 0, 1, 0 ] );
  886. tableSelection.setCellSelection( tableCell, tableCell );
  887. } );
  888. it( 'should expand the selection to the cell on the right when the direction is "right"', () => {
  889. tableKeyboard._navigateFromCellInDirection( tableCell, 'right', true );
  890. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  891. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 1 ] ) );
  892. expect( selection.rangeCount ).to.equal( 2 );
  893. } );
  894. it( 'should expand the selection to the cell above when the direction is "up"', () => {
  895. tableKeyboard._navigateFromCellInDirection( tableCell, 'up', true );
  896. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  897. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 0, 0 ] ) );
  898. expect( selection.rangeCount ).to.equal( 2 );
  899. } );
  900. it( 'should expand the selection to the cell below when the direction is "down"', () => {
  901. tableKeyboard._navigateFromCellInDirection( tableCell, 'down', true );
  902. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  903. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 0 ] ) );
  904. expect( selection.rangeCount ).to.equal( 2 );
  905. } );
  906. it( 'should expand the selection to the cell above when the direction is "left"', () => {
  907. tableKeyboard._navigateFromCellInDirection( tableCell, 'left', true );
  908. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  909. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 0, 0 ] ) );
  910. expect( selection.rangeCount ).to.equal( 2 );
  911. } );
  912. } );
  913. describe( 'from a cell in the last column (but not the last row)', () => {
  914. let tableCell;
  915. beforeEach( () => {
  916. tableCell = modelRoot.getNodeByPath( [ 0, 1, 2 ] );
  917. tableSelection.setCellSelection( tableCell, tableCell );
  918. } );
  919. it( 'should expand the selection to the cell on the left when the direction is "left"', () => {
  920. tableKeyboard._navigateFromCellInDirection( tableCell, 'left', true );
  921. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  922. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 1 ] ) );
  923. expect( selection.rangeCount ).to.equal( 2 );
  924. } );
  925. it( 'should expand the selection to the cell above when the direction is "up"', () => {
  926. tableKeyboard._navigateFromCellInDirection( tableCell, 'up', true );
  927. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  928. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 0, 2 ] ) );
  929. expect( selection.rangeCount ).to.equal( 2 );
  930. } );
  931. it( 'should expand the selection to the cell below when the direction is "down"', () => {
  932. tableKeyboard._navigateFromCellInDirection( tableCell, 'down', true );
  933. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  934. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 2 ] ) );
  935. expect( selection.rangeCount ).to.equal( 2 );
  936. } );
  937. it( 'should expand the selection to the cell below when the direction is "right"', () => {
  938. tableKeyboard._navigateFromCellInDirection( tableCell, 'right', true );
  939. expect( tableSelection.getAnchorCell() ).to.equal( tableCell );
  940. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 2 ] ) );
  941. expect( selection.rangeCount ).to.equal( 2 );
  942. } );
  943. } );
  944. } );
  945. } );
  946. describe( 'with the table cells selected from outside', () => {
  947. describe( 'on a single table cell selected', () => {
  948. let anchorCell, focusCell;
  949. beforeEach( () => {
  950. setModelData( model, modelTable( [
  951. [ '00', '01', '02' ],
  952. [ '10', '11', '12' ],
  953. [ '20', '21', '22' ]
  954. ] ) );
  955. anchorCell = focusCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  956. tableSelection.setCellSelection( anchorCell, focusCell );
  957. } );
  958. describe( 'without shift pressed', () => {
  959. it( 'should move to the cell on the left', () => {
  960. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  961. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  962. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  963. assertEqualMarkup( getModelData( model ), modelTable( [
  964. [ '00', '01', '02' ],
  965. [ '10[]', '11', '12' ],
  966. [ '20', '21', '22' ]
  967. ] ) );
  968. } );
  969. it( 'should move to the cell on the right', () => {
  970. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  971. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  972. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  973. assertEqualMarkup( getModelData( model ), modelTable( [
  974. [ '00', '01', '02' ],
  975. [ '10', '11', '[]12' ],
  976. [ '20', '21', '22' ]
  977. ] ) );
  978. } );
  979. it( 'should move to the cell above the selection', () => {
  980. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  981. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  982. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  983. assertEqualMarkup( getModelData( model ), modelTable( [
  984. [ '00', '01[]', '02' ],
  985. [ '10', '11', '12' ],
  986. [ '20', '21', '22' ]
  987. ] ) );
  988. } );
  989. it( 'should move to the cell below the selection', () => {
  990. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  991. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  992. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  993. assertEqualMarkup( getModelData( model ), modelTable( [
  994. [ '00', '01', '02' ],
  995. [ '10', '11', '12' ],
  996. [ '20', '[]21', '22' ]
  997. ] ) );
  998. } );
  999. } );
  1000. describe( 'with shift pressed', () => {
  1001. beforeEach( () => {
  1002. leftArrowDomEvtDataStub.shiftKey = true;
  1003. rightArrowDomEvtDataStub.shiftKey = true;
  1004. upArrowDomEvtDataStub.shiftKey = true;
  1005. downArrowDomEvtDataStub.shiftKey = true;
  1006. } );
  1007. it( 'should expand the selection to the cell on the left', () => {
  1008. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1009. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1010. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1011. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1012. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 0 ] ) );
  1013. expect( selection.rangeCount ).to.equal( 2 );
  1014. } );
  1015. it( 'should expand the selection to the cell on the right', () => {
  1016. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1017. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1018. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1019. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1020. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 2 ] ) );
  1021. expect( selection.rangeCount ).to.equal( 2 );
  1022. } );
  1023. it( 'should expand the selection to the cell above the selection', () => {
  1024. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1025. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1026. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1027. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1028. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) );
  1029. expect( selection.rangeCount ).to.equal( 2 );
  1030. } );
  1031. it( 'should expand the selection to the cell below the selection', () => {
  1032. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1033. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1034. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1035. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1036. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 1 ] ) );
  1037. expect( selection.rangeCount ).to.equal( 2 );
  1038. } );
  1039. } );
  1040. } );
  1041. describe( 'on multiple table cells selected vertically (the anchor cell above the focus cell)', () => {
  1042. let anchorCell, focusCell;
  1043. beforeEach( () => {
  1044. setModelData( model, modelTable( [
  1045. [ '00', '01', '02', '03' ],
  1046. [ '10', '11', '12', '13' ],
  1047. [ '20', '21', '22', '23' ],
  1048. [ '30', '31', '32', '33' ]
  1049. ] ) );
  1050. anchorCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  1051. focusCell = modelRoot.getNodeByPath( [ 0, 2, 1 ] );
  1052. tableSelection.setCellSelection( anchorCell, focusCell );
  1053. } );
  1054. describe( 'without shift pressed', () => {
  1055. it( 'should move to the cell on the top left of the selection', () => {
  1056. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1057. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1058. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1059. assertEqualMarkup( getModelData( model ), modelTable( [
  1060. [ '00', '01', '02', '03' ],
  1061. [ '10[]', '11', '12', '13' ],
  1062. [ '20', '21', '22', '23' ],
  1063. [ '30', '31', '32', '33' ]
  1064. ] ) );
  1065. } );
  1066. it( 'should move to the cell on the bottom right of the selection', () => {
  1067. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1068. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1069. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1070. assertEqualMarkup( getModelData( model ), modelTable( [
  1071. [ '00', '01', '02', '03' ],
  1072. [ '10', '11', '12', '13' ],
  1073. [ '20', '21', '[]22', '23' ],
  1074. [ '30', '31', '32', '33' ]
  1075. ] ) );
  1076. } );
  1077. it( 'should move to the cell above the selection', () => {
  1078. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1079. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1080. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1081. assertEqualMarkup( getModelData( model ), modelTable( [
  1082. [ '00', '01[]', '02', '03' ],
  1083. [ '10', '11', '12', '13' ],
  1084. [ '20', '21', '22', '23' ],
  1085. [ '30', '31', '32', '33' ]
  1086. ] ) );
  1087. } );
  1088. it( 'should move to the cell below the selection', () => {
  1089. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1090. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1091. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1092. assertEqualMarkup( getModelData( model ), modelTable( [
  1093. [ '00', '01', '02', '03' ],
  1094. [ '10', '11', '12', '13' ],
  1095. [ '20', '21', '22', '23' ],
  1096. [ '30', '[]31', '32', '33' ]
  1097. ] ) );
  1098. } );
  1099. } );
  1100. describe( 'with shift pressed', () => {
  1101. beforeEach( () => {
  1102. leftArrowDomEvtDataStub.shiftKey = true;
  1103. rightArrowDomEvtDataStub.shiftKey = true;
  1104. upArrowDomEvtDataStub.shiftKey = true;
  1105. downArrowDomEvtDataStub.shiftKey = true;
  1106. } );
  1107. it( 'should expand the selection to the cell on the left from the focus cell', () => {
  1108. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1109. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1110. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1111. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1112. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 0 ] ) );
  1113. expect( selection.rangeCount ).to.equal( 4 );
  1114. } );
  1115. it( 'should expand the selection to the cell on the right from the focus cell', () => {
  1116. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1117. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1118. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1119. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1120. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 2 ] ) );
  1121. expect( selection.rangeCount ).to.equal( 4 );
  1122. } );
  1123. it( 'should shrink the selection to the anchor cell', () => {
  1124. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1125. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1126. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1127. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1128. expect( tableSelection.getFocusCell() ).to.equal( anchorCell );
  1129. expect( selection.rangeCount ).to.equal( 1 );
  1130. } );
  1131. it( 'should expand the selection to the cell below the focus cell', () => {
  1132. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1133. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1134. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1135. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1136. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 3, 1 ] ) );
  1137. expect( selection.rangeCount ).to.equal( 3 );
  1138. } );
  1139. } );
  1140. } );
  1141. describe( 'on multiple table cells selected vertically (the anchor cell below the focus cell)', () => {
  1142. let anchorCell, focusCell;
  1143. beforeEach( () => {
  1144. setModelData( model, modelTable( [
  1145. [ '00', '01', '02', '03' ],
  1146. [ '10', '11', '12', '13' ],
  1147. [ '20', '21', '22', '23' ],
  1148. [ '30', '31', '32', '33' ]
  1149. ] ) );
  1150. anchorCell = modelRoot.getNodeByPath( [ 0, 2, 1 ] );
  1151. focusCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  1152. tableSelection.setCellSelection( anchorCell, focusCell );
  1153. } );
  1154. describe( 'without shift pressed', () => {
  1155. it( 'should move to the cell on the top left of the selection', () => {
  1156. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1157. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1158. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1159. assertEqualMarkup( getModelData( model ), modelTable( [
  1160. [ '00', '01', '02', '03' ],
  1161. [ '10[]', '11', '12', '13' ],
  1162. [ '20', '21', '22', '23' ],
  1163. [ '30', '31', '32', '33' ]
  1164. ] ) );
  1165. } );
  1166. it( 'should move to the cell on the bottom right of the selection', () => {
  1167. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1168. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1169. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1170. assertEqualMarkup( getModelData( model ), modelTable( [
  1171. [ '00', '01', '02', '03' ],
  1172. [ '10', '11', '12', '13' ],
  1173. [ '20', '21', '[]22', '23' ],
  1174. [ '30', '31', '32', '33' ]
  1175. ] ) );
  1176. } );
  1177. it( 'should move to the cell above the selection', () => {
  1178. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1179. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1180. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1181. assertEqualMarkup( getModelData( model ), modelTable( [
  1182. [ '00', '01[]', '02', '03' ],
  1183. [ '10', '11', '12', '13' ],
  1184. [ '20', '21', '22', '23' ],
  1185. [ '30', '31', '32', '33' ]
  1186. ] ) );
  1187. } );
  1188. it( 'should move to the cell below the selection', () => {
  1189. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1190. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1191. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1192. assertEqualMarkup( getModelData( model ), modelTable( [
  1193. [ '00', '01', '02', '03' ],
  1194. [ '10', '11', '12', '13' ],
  1195. [ '20', '21', '22', '23' ],
  1196. [ '30', '[]31', '32', '33' ]
  1197. ] ) );
  1198. } );
  1199. } );
  1200. describe( 'with shift pressed', () => {
  1201. beforeEach( () => {
  1202. leftArrowDomEvtDataStub.shiftKey = true;
  1203. rightArrowDomEvtDataStub.shiftKey = true;
  1204. upArrowDomEvtDataStub.shiftKey = true;
  1205. downArrowDomEvtDataStub.shiftKey = true;
  1206. } );
  1207. it( 'should expand the selection to the cell on the left from the focus cell', () => {
  1208. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1209. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1210. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1211. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1212. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 0 ] ) );
  1213. expect( selection.rangeCount ).to.equal( 4 );
  1214. } );
  1215. it( 'should expand the selection to the cell on the right from the focus cell', () => {
  1216. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1217. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1218. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1219. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1220. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 2 ] ) );
  1221. expect( selection.rangeCount ).to.equal( 4 );
  1222. } );
  1223. it( 'should shrink the selection to the anchor cell', () => {
  1224. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1225. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1226. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1227. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1228. expect( tableSelection.getFocusCell() ).to.equal( anchorCell );
  1229. expect( selection.rangeCount ).to.equal( 1 );
  1230. } );
  1231. it( 'should expand the selection to the cell below the focus cell', () => {
  1232. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1233. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1234. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1235. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1236. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) );
  1237. expect( selection.rangeCount ).to.equal( 3 );
  1238. } );
  1239. } );
  1240. } );
  1241. describe( 'on multiple table cell selected horizontally (the anchor cell is to the left of the focus cell ', () => {
  1242. let anchorCell, focusCell;
  1243. beforeEach( () => {
  1244. setModelData( model, modelTable( [
  1245. [ '00', '01', '02', '03' ],
  1246. [ '10', '11', '12', '13' ],
  1247. [ '20', '21', '22', '23' ],
  1248. [ '30', '31', '32', '33' ]
  1249. ] ) );
  1250. anchorCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  1251. focusCell = modelRoot.getNodeByPath( [ 0, 1, 2 ] );
  1252. tableSelection.setCellSelection( anchorCell, focusCell );
  1253. } );
  1254. describe( 'without shift pressed', () => {
  1255. it( 'should move to the cell on the top left of the selection', () => {
  1256. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1257. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1258. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1259. assertEqualMarkup( getModelData( model ), modelTable( [
  1260. [ '00', '01', '02', '03' ],
  1261. [ '10[]', '11', '12', '13' ],
  1262. [ '20', '21', '22', '23' ],
  1263. [ '30', '31', '32', '33' ]
  1264. ] ) );
  1265. } );
  1266. it( 'should move to the cell on the bottom right of the selection', () => {
  1267. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1268. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1269. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1270. assertEqualMarkup( getModelData( model ), modelTable( [
  1271. [ '00', '01', '02', '03' ],
  1272. [ '10', '11', '12', '[]13' ],
  1273. [ '20', '21', '22', '23' ],
  1274. [ '30', '31', '32', '33' ]
  1275. ] ) );
  1276. } );
  1277. it( 'should move to the cell above the selection', () => {
  1278. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1279. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1280. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1281. assertEqualMarkup( getModelData( model ), modelTable( [
  1282. [ '00', '01[]', '02', '03' ],
  1283. [ '10', '11', '12', '13' ],
  1284. [ '20', '21', '22', '23' ],
  1285. [ '30', '31', '32', '33' ]
  1286. ] ) );
  1287. } );
  1288. it( 'should move to the cell below the selection', () => {
  1289. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1290. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1291. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1292. assertEqualMarkup( getModelData( model ), modelTable( [
  1293. [ '00', '01', '02', '03' ],
  1294. [ '10', '11', '12', '13' ],
  1295. [ '20', '21', '[]22', '23' ],
  1296. [ '30', '31', '32', '33' ]
  1297. ] ) );
  1298. } );
  1299. } );
  1300. describe( 'with shift pressed', () => {
  1301. beforeEach( () => {
  1302. leftArrowDomEvtDataStub.shiftKey = true;
  1303. rightArrowDomEvtDataStub.shiftKey = true;
  1304. upArrowDomEvtDataStub.shiftKey = true;
  1305. downArrowDomEvtDataStub.shiftKey = true;
  1306. } );
  1307. it( 'should expand the selection to the cell above the focus cell', () => {
  1308. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1309. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1310. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1311. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1312. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 0, 2 ] ) );
  1313. expect( selection.rangeCount ).to.equal( 4 );
  1314. } );
  1315. it( 'should expand the selection to the cell below the focus cell', () => {
  1316. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1317. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1318. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1319. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1320. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 2 ] ) );
  1321. expect( selection.rangeCount ).to.equal( 4 );
  1322. } );
  1323. it( 'should shrink the selection to the anchor cell', () => {
  1324. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1325. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1326. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1327. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1328. expect( tableSelection.getFocusCell() ).to.equal( anchorCell );
  1329. expect( selection.rangeCount ).to.equal( 1 );
  1330. } );
  1331. it( 'should expand the selection to the cell on the right to the focus cell', () => {
  1332. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1333. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1334. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1335. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1336. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 3 ] ) );
  1337. expect( selection.rangeCount ).to.equal( 3 );
  1338. } );
  1339. } );
  1340. } );
  1341. describe( 'on multiple table cell selected diagonally', () => {
  1342. beforeEach( () => {
  1343. setModelData( model, modelTable( [
  1344. [ '00', '01', '02', '03' ],
  1345. [ '10', '11', '12', '13' ],
  1346. [ '20', '21', '22', '23' ],
  1347. [ '30', '31', '32', '33' ]
  1348. ] ) );
  1349. tableSelection.setCellSelection(
  1350. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1351. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  1352. );
  1353. } );
  1354. it( 'should move to the cell on the top left of selection', () => {
  1355. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1356. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1357. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1358. assertEqualMarkup( getModelData( model ), modelTable( [
  1359. [ '00', '01', '02', '03' ],
  1360. [ '10[]', '11', '12', '13' ],
  1361. [ '20', '21', '22', '23' ],
  1362. [ '30', '31', '32', '33' ]
  1363. ] ) );
  1364. } );
  1365. it( 'should move to the cell on the bottom right of selection', () => {
  1366. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1367. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1368. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1369. assertEqualMarkup( getModelData( model ), modelTable( [
  1370. [ '00', '01', '02', '03' ],
  1371. [ '10', '11', '12', '13' ],
  1372. [ '20', '21', '22', '[]23' ],
  1373. [ '30', '31', '32', '33' ]
  1374. ] ) );
  1375. } );
  1376. it( 'should move to the cell above selection', () => {
  1377. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1378. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1379. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1380. assertEqualMarkup( getModelData( model ), modelTable( [
  1381. [ '00', '01[]', '02', '03' ],
  1382. [ '10', '11', '12', '13' ],
  1383. [ '20', '21', '22', '23' ],
  1384. [ '30', '31', '32', '33' ]
  1385. ] ) );
  1386. } );
  1387. it( 'should move to the cell below selection', () => {
  1388. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1389. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1390. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1391. assertEqualMarkup( getModelData( model ), modelTable( [
  1392. [ '00', '01', '02', '03' ],
  1393. [ '10', '11', '12', '13' ],
  1394. [ '20', '21', '22', '23' ],
  1395. [ '30', '31', '[]32', '33' ]
  1396. ] ) );
  1397. } );
  1398. } );
  1399. } );
  1400. describe( 'with the selection inside a table cell', () => {
  1401. describe( 'with the selection at the boundary of a cell', () => {
  1402. describe( 'simple cell text content', () => {
  1403. it( 'should navigate to the cell on the left', () => {
  1404. setModelData( model, modelTable( [
  1405. [ '00', '01', '02' ],
  1406. [ '10', '[]11', '12' ],
  1407. [ '20', '21', '22' ]
  1408. ] ) );
  1409. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1410. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1411. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1412. assertEqualMarkup( getModelData( model ), modelTable( [
  1413. [ '00', '01', '02' ],
  1414. [ '10[]', '11', '12' ],
  1415. [ '20', '21', '22' ]
  1416. ] ) );
  1417. } );
  1418. it( 'should navigate to the cell on the right', () => {
  1419. setModelData( model, modelTable( [
  1420. [ '00', '01', '02' ],
  1421. [ '10', '11[]', '12' ],
  1422. [ '20', '21', '22' ]
  1423. ] ) );
  1424. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1425. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1426. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1427. assertEqualMarkup( getModelData( model ), modelTable( [
  1428. [ '00', '01', '02' ],
  1429. [ '10', '11', '[]12' ],
  1430. [ '20', '21', '22' ]
  1431. ] ) );
  1432. } );
  1433. it( 'should navigate to the cell above', () => {
  1434. setModelData( model, modelTable( [
  1435. [ '00', '01', '02' ],
  1436. [ '10', '[]11', '12' ],
  1437. [ '20', '21', '22' ]
  1438. ] ) );
  1439. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1440. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1441. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1442. assertEqualMarkup( getModelData( model ), modelTable( [
  1443. [ '00', '01[]', '02' ],
  1444. [ '10', '11', '12' ],
  1445. [ '20', '21', '22' ]
  1446. ] ) );
  1447. } );
  1448. it( 'should navigate to the cell below', () => {
  1449. setModelData( model, modelTable( [
  1450. [ '00', '01', '02' ],
  1451. [ '10', '11[]', '12' ],
  1452. [ '20', '21', '22' ]
  1453. ] ) );
  1454. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1455. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1456. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1457. assertEqualMarkup( getModelData( model ), modelTable( [
  1458. [ '00', '01', '02' ],
  1459. [ '10', '11', '12' ],
  1460. [ '20', '[]21', '22' ]
  1461. ] ) );
  1462. } );
  1463. } );
  1464. describe( 'multiple paragraphs in the cell content', () => {
  1465. it( 'should navigate to the cell on the left', () => {
  1466. setModelData( model, modelTable( [
  1467. [ '00', '01', '02' ],
  1468. [ '10', '<paragraph>[]11</paragraph><paragraph>x</paragraph>', '12' ],
  1469. [ '20', '21', '22' ]
  1470. ] ) );
  1471. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1472. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1473. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1474. assertEqualMarkup( getModelData( model ), modelTable( [
  1475. [ '00', '01', '02' ],
  1476. [ '10[]', '<paragraph>11</paragraph><paragraph>x</paragraph>', '12' ],
  1477. [ '20', '21', '22' ]
  1478. ] ) );
  1479. } );
  1480. it( 'should navigate to the cell on the right', () => {
  1481. setModelData( model, modelTable( [
  1482. [ '00', '01', '02' ],
  1483. [ '10', '<paragraph>11</paragraph><paragraph>x[]</paragraph>', '12' ],
  1484. [ '20', '21', '22' ]
  1485. ] ) );
  1486. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1487. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1488. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1489. assertEqualMarkup( getModelData( model ), modelTable( [
  1490. [ '00', '01', '02' ],
  1491. [ '10', '<paragraph>11</paragraph><paragraph>x</paragraph>', '[]12' ],
  1492. [ '20', '21', '22' ]
  1493. ] ) );
  1494. } );
  1495. it( 'should navigate to the cell above', () => {
  1496. setModelData( model, modelTable( [
  1497. [ '00', '01', '02' ],
  1498. [ '10', '<paragraph>[]11</paragraph><paragraph>x</paragraph>', '12' ],
  1499. [ '20', '21', '22' ]
  1500. ] ) );
  1501. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1502. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1503. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1504. assertEqualMarkup( getModelData( model ), modelTable( [
  1505. [ '00', '01[]', '02' ],
  1506. [ '10', '<paragraph>11</paragraph><paragraph>x</paragraph>', '12' ],
  1507. [ '20', '21', '22' ]
  1508. ] ) );
  1509. } );
  1510. it( 'should navigate to the cell below', () => {
  1511. setModelData( model, modelTable( [
  1512. [ '00', '01', '02' ],
  1513. [ '10', '<paragraph>11</paragraph><paragraph>x[]</paragraph>', '12' ],
  1514. [ '20', '21', '22' ]
  1515. ] ) );
  1516. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1517. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1518. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1519. assertEqualMarkup( getModelData( model ), modelTable( [
  1520. [ '00', '01', '02' ],
  1521. [ '10', '<paragraph>11</paragraph><paragraph>x</paragraph>', '12' ],
  1522. [ '20', '[]21', '22' ]
  1523. ] ) );
  1524. } );
  1525. } );
  1526. describe( 'image widget with caption as only cell content', () => {
  1527. it( 'should navigate to the cell on the left', () => {
  1528. setModelData( model, modelTable( [
  1529. [ '00', '01', '02' ],
  1530. [ '10', `<image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  1531. [ '20', '21', '22' ]
  1532. ] ) );
  1533. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1534. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1535. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1536. assertEqualMarkup( getModelData( model ), modelTable( [
  1537. [ '00', '01', '02' ],
  1538. [ '10[]', `<image src="${ imageUrl }"><caption>11</caption></image>`, '12' ],
  1539. [ '20', '21', '22' ]
  1540. ] ) );
  1541. } );
  1542. it( 'should navigate to the cell on the right', () => {
  1543. setModelData( model, modelTable( [
  1544. [ '00', '01', '02' ],
  1545. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image>`, '12' ],
  1546. [ '20', '21', '22' ]
  1547. ] ) );
  1548. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1549. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1550. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1551. assertEqualMarkup( getModelData( model ), modelTable( [
  1552. [ '00', '01', '02' ],
  1553. [ '10', `<image src="${ imageUrl }"><caption>11</caption></image>`, '[]12' ],
  1554. [ '20', '21', '22' ]
  1555. ] ) );
  1556. } );
  1557. it( 'should navigate to the cell above', () => {
  1558. setModelData( model, modelTable( [
  1559. [ '00', '01', '02' ],
  1560. [ '10', `<image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  1561. [ '20', '21', '22' ]
  1562. ] ) );
  1563. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1564. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1565. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1566. assertEqualMarkup( getModelData( model ), modelTable( [
  1567. [ '00', '01[]', '02' ],
  1568. [ '10', `<image src="${ imageUrl }"><caption>11</caption></image>`, '12' ],
  1569. [ '20', '21', '22' ]
  1570. ] ) );
  1571. } );
  1572. it( 'should navigate to the cell below', () => {
  1573. setModelData( model, modelTable( [
  1574. [ '00', '01', '02' ],
  1575. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image>`, '12' ],
  1576. [ '20', '21', '22' ]
  1577. ] ) );
  1578. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1579. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1580. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1581. assertEqualMarkup( getModelData( model ), modelTable( [
  1582. [ '00', '01', '02' ],
  1583. [ '10', `<image src="${ imageUrl }"><caption>11</caption></image>`, '12' ],
  1584. [ '20', '[]21', '22' ]
  1585. ] ) );
  1586. } );
  1587. } );
  1588. describe( 'horizontal line as only cell content (widget without $text positions)', () => {
  1589. beforeEach( () => {
  1590. setModelData( model, modelTable( [
  1591. [ '00', '01', '02' ],
  1592. [ '10', '[<horizontalLine></horizontalLine>]', '12' ],
  1593. [ '20', '21', '22' ]
  1594. ] ) );
  1595. } );
  1596. it( 'should navigate to the cell on the left', () => {
  1597. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1598. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1599. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1600. assertEqualMarkup( getModelData( model ), modelTable( [
  1601. [ '00', '01', '02' ],
  1602. [ '10[]', '<horizontalLine></horizontalLine>', '12' ],
  1603. [ '20', '21', '22' ]
  1604. ] ) );
  1605. } );
  1606. it( 'should navigate to the cell on the right', () => {
  1607. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1608. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1609. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1610. assertEqualMarkup( getModelData( model ), modelTable( [
  1611. [ '00', '01', '02' ],
  1612. [ '10', '<horizontalLine></horizontalLine>', '[]12' ],
  1613. [ '20', '21', '22' ]
  1614. ] ) );
  1615. } );
  1616. it( 'should navigate to the cell above', () => {
  1617. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1618. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1619. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1620. assertEqualMarkup( getModelData( model ), modelTable( [
  1621. [ '00', '01[]', '02' ],
  1622. [ '10', '<horizontalLine></horizontalLine>', '12' ],
  1623. [ '20', '21', '22' ]
  1624. ] ) );
  1625. } );
  1626. it( 'should navigate to the cell below', () => {
  1627. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1628. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1629. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1630. assertEqualMarkup( getModelData( model ), modelTable( [
  1631. [ '00', '01', '02' ],
  1632. [ '10', '<horizontalLine></horizontalLine>', '12' ],
  1633. [ '20', '[]21', '22' ]
  1634. ] ) );
  1635. } );
  1636. } );
  1637. describe( 'two horizontal lines as only cell content (widget without $text positions)', () => {
  1638. it( 'should navigate to the cell on the left', () => {
  1639. setModelData( model, modelTable( [
  1640. [ '00', '01', '02' ],
  1641. [ '10', '[<horizontalLine></horizontalLine>]<horizontalLine></horizontalLine>', '12' ],
  1642. [ '20', '21', '22' ]
  1643. ] ) );
  1644. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1645. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1646. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1647. assertEqualMarkup( getModelData( model ), modelTable( [
  1648. [ '00', '01', '02' ],
  1649. [ '10[]', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '12' ],
  1650. [ '20', '21', '22' ]
  1651. ] ) );
  1652. } );
  1653. it( 'should navigate to the cell on the right', () => {
  1654. setModelData( model, modelTable( [
  1655. [ '00', '01', '02' ],
  1656. [ '10', '<horizontalLine></horizontalLine>[<horizontalLine></horizontalLine>]', '12' ],
  1657. [ '20', '21', '22' ]
  1658. ] ) );
  1659. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1660. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1661. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1662. assertEqualMarkup( getModelData( model ), modelTable( [
  1663. [ '00', '01', '02' ],
  1664. [ '10', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '[]12' ],
  1665. [ '20', '21', '22' ]
  1666. ] ) );
  1667. } );
  1668. it( 'should navigate to the cell above', () => {
  1669. setModelData( model, modelTable( [
  1670. [ '00', '01', '02' ],
  1671. [ '10', '[<horizontalLine></horizontalLine>]<horizontalLine></horizontalLine>', '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', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '12' ],
  1680. [ '20', '21', '22' ]
  1681. ] ) );
  1682. } );
  1683. it( 'should navigate to the cell below', () => {
  1684. setModelData( model, modelTable( [
  1685. [ '00', '01', '02' ],
  1686. [ '10', '<horizontalLine></horizontalLine>[<horizontalLine></horizontalLine>]', '12' ],
  1687. [ '20', '21', '22' ]
  1688. ] ) );
  1689. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1690. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1691. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1692. assertEqualMarkup( getModelData( model ), modelTable( [
  1693. [ '00', '01', '02' ],
  1694. [ '10', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '12' ],
  1695. [ '20', '[]21', '22' ]
  1696. ] ) );
  1697. } );
  1698. } );
  1699. } );
  1700. describe( 'with selection not at the boundary of a cell', () => {
  1701. let editorElement, editor, model, styleElement;
  1702. beforeEach( async () => {
  1703. editorElement = global.document.createElement( 'div' );
  1704. global.document.body.appendChild( editorElement );
  1705. editor = await ClassicTestEditor.create( editorElement, {
  1706. plugins: [ Table, Paragraph, Image, ImageCaption, HorizontalLine ]
  1707. } );
  1708. model = editor.model;
  1709. styleElement = global.document.createElement( 'style' );
  1710. styleElement.type = 'text/css';
  1711. styleElement.appendChild( global.document.createTextNode(
  1712. `
  1713. * {
  1714. font-size: 12px !important;
  1715. font-family: serif !important;
  1716. margin: 0 !important;
  1717. padding: 0 !important;
  1718. border: 0 !important
  1719. }
  1720. td { width: 30px !important; }
  1721. tr:nth-child(2) td:nth-child(2) { width: 300px !important; }
  1722. `
  1723. ) );
  1724. global.document.querySelector( 'head' ).appendChild( styleElement );
  1725. // The editing view must be focused because otherwise in Chrome the DOM selection will not contain
  1726. // any ranges and jumpOverUiElement will crash (for the right arrow when shift is pressed).
  1727. editor.editing.view.focus();
  1728. } );
  1729. afterEach( async () => {
  1730. editorElement.remove();
  1731. styleElement.remove();
  1732. await editor.destroy();
  1733. } );
  1734. describe( 'simple cell text content', () => {
  1735. it( 'should not navigate to the cell on the left', () => {
  1736. setModelData( model, modelTable( [
  1737. [ '00', '01', '02' ],
  1738. [ '10', '1[]1', '12' ],
  1739. [ '20', '21', '22' ]
  1740. ] ) );
  1741. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1742. sinon.assert.notCalled( leftArrowDomEvtDataStub.preventDefault );
  1743. sinon.assert.notCalled( leftArrowDomEvtDataStub.stopPropagation );
  1744. } );
  1745. it( 'should not navigate to the cell on the right', () => {
  1746. setModelData( model, modelTable( [
  1747. [ '00', '01', '02' ],
  1748. [ '10', '1[]1', '12' ],
  1749. [ '20', '21', '22' ]
  1750. ] ) );
  1751. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1752. sinon.assert.notCalled( rightArrowDomEvtDataStub.preventDefault );
  1753. sinon.assert.notCalled( rightArrowDomEvtDataStub.stopPropagation );
  1754. } );
  1755. it( 'should not navigate to the cell above', () => {
  1756. setModelData( model, modelTable( [
  1757. [ '00', '01', '02' ],
  1758. [ '10', '1[]1', '12' ],
  1759. [ '20', '21', '22' ]
  1760. ] ) );
  1761. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1762. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1763. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1764. assertEqualMarkup( getModelData( model ), modelTable( [
  1765. [ '00', '01', '02' ],
  1766. [ '10', '[]11', '12' ],
  1767. [ '20', '21', '22' ]
  1768. ] ) );
  1769. } );
  1770. it( 'should not navigate to the cell below', () => {
  1771. setModelData( model, modelTable( [
  1772. [ '00', '01', '02' ],
  1773. [ '10', '1[]1', '12' ],
  1774. [ '20', '21', '22' ]
  1775. ] ) );
  1776. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1777. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1778. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1779. assertEqualMarkup( getModelData( model ), modelTable( [
  1780. [ '00', '01', '02' ],
  1781. [ '10', '11[]', '12' ],
  1782. [ '20', '21', '22' ]
  1783. ] ) );
  1784. } );
  1785. describe( 'when shift key is pressed', () => {
  1786. beforeEach( () => {
  1787. setModelData( model, modelTable( [
  1788. [ '00', '01', '02' ],
  1789. [ '10', '1[]1', '12' ],
  1790. [ '20', '21', '22' ]
  1791. ] ) );
  1792. leftArrowDomEvtDataStub.shiftKey = true;
  1793. rightArrowDomEvtDataStub.shiftKey = true;
  1794. upArrowDomEvtDataStub.shiftKey = true;
  1795. downArrowDomEvtDataStub.shiftKey = true;
  1796. } );
  1797. it( 'should not prevent default browser behavior for the left arrow pressed with shift', () => {
  1798. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1799. sinon.assert.notCalled( leftArrowDomEvtDataStub.preventDefault );
  1800. sinon.assert.notCalled( leftArrowDomEvtDataStub.stopPropagation );
  1801. } );
  1802. it( 'should not prevent default browser behavior for the right arrow pressed with shift', () => {
  1803. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1804. sinon.assert.notCalled( rightArrowDomEvtDataStub.preventDefault );
  1805. sinon.assert.notCalled( rightArrowDomEvtDataStub.stopPropagation );
  1806. } );
  1807. it( 'should expand selection to the beginning of the cell content', () => {
  1808. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1809. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1810. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1811. assertEqualMarkup( getModelData( model ), modelTable( [
  1812. [ '00', '01', '02' ],
  1813. [ '10', '[1]1', '12' ],
  1814. [ '20', '21', '22' ]
  1815. ] ) );
  1816. } );
  1817. it( 'should expand selection to the end of the cell content', () => {
  1818. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1819. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1820. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1821. assertEqualMarkup( getModelData( model ), modelTable( [
  1822. [ '00', '01', '02' ],
  1823. [ '10', '1[1]', '12' ],
  1824. [ '20', '21', '22' ]
  1825. ] ) );
  1826. } );
  1827. } );
  1828. } );
  1829. describe( 'selection inside paragraph', () => {
  1830. const text = new Array( 20 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  1831. it( 'should not navigate if caret is in the middle line of a text', () => {
  1832. setModelData( model, modelTable( [
  1833. [ '00', '01', '02' ],
  1834. [ '10', text + '[] ' + text, '12' ],
  1835. [ '20', '21', '22' ]
  1836. ] ) );
  1837. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1838. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  1839. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  1840. } );
  1841. it( 'should move caret to beginning of cell content if caret is in the first line of a text', () => {
  1842. setModelData( model, modelTable( [
  1843. [ '00', '01', '02' ],
  1844. [ '10', 'word[] word' + text, '12' ],
  1845. [ '20', '21', '22' ]
  1846. ] ) );
  1847. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1848. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1849. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1850. assertEqualMarkup( getModelData( model ), modelTable( [
  1851. [ '00', '01', '02' ],
  1852. [ '10', '[]word word' + text, '12' ],
  1853. [ '20', '21', '22' ]
  1854. ] ) );
  1855. } );
  1856. it( 'should move caret to end of cell content if caret is in the last line of a text', () => {
  1857. setModelData( model, modelTable( [
  1858. [ '00', '01', '02' ],
  1859. [ '10', text + 'word[] word', '12' ],
  1860. [ '20', '21', '22' ]
  1861. ] ) );
  1862. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1863. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1864. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1865. assertEqualMarkup( getModelData( model ), modelTable( [
  1866. [ '00', '01', '02' ],
  1867. [ '10', text + 'word word[]', '12' ],
  1868. [ '20', '21', '22' ]
  1869. ] ) );
  1870. } );
  1871. describe( 'when shift key is pressed', () => {
  1872. beforeEach( () => {
  1873. upArrowDomEvtDataStub.shiftKey = true;
  1874. downArrowDomEvtDataStub.shiftKey = true;
  1875. } );
  1876. it( 'should not prevent default browser behavior for the up arrow in the middle lines of the cell text', () => {
  1877. setModelData( model, modelTable( [
  1878. [ '00', '01', '02' ],
  1879. [ '10', text + '[] ' + text, '12' ],
  1880. [ '20', '21', '22' ]
  1881. ] ) );
  1882. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1883. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  1884. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  1885. } );
  1886. it( 'should not prevent default browser behavior for the down arrow in the middle lines of cell text', () => {
  1887. setModelData( model, modelTable( [
  1888. [ '00', '01', '02' ],
  1889. [ '10', text + '[] ' + text, '12' ],
  1890. [ '20', '21', '22' ]
  1891. ] ) );
  1892. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1893. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  1894. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  1895. } );
  1896. it( 'should expand collapsed selection to the beginning of the cell content', () => {
  1897. setModelData( model, modelTable( [
  1898. [ '00', '01', '02' ],
  1899. [ '10', 'word[] word' + text, '12' ],
  1900. [ '20', '21', '22' ]
  1901. ] ) );
  1902. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1903. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1904. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1905. assertEqualMarkup( getModelData( model ), modelTable( [
  1906. [ '00', '01', '02' ],
  1907. [ '10', '[word] word' + text, '12' ],
  1908. [ '20', '21', '22' ]
  1909. ] ) );
  1910. } );
  1911. it( 'should expand not collapsed selection to the beginning of the cell content from the selection anchor', () => {
  1912. setModelData( model, modelTable( [
  1913. [ '00', '01', '02' ],
  1914. [ '10', 'word [word]' + text, '12' ],
  1915. [ '20', '21', '22' ]
  1916. ] ) );
  1917. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1918. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1919. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1920. assertEqualMarkup( getModelData( model ), modelTable( [
  1921. [ '00', '01', '02' ],
  1922. [ '10', '[word ]word' + text, '12' ],
  1923. [ '20', '21', '22' ]
  1924. ] ) );
  1925. } );
  1926. it( 'should expand collapsed selection to the end of the cell content', () => {
  1927. setModelData( model, modelTable( [
  1928. [ '00', '01', '02' ],
  1929. [ '10', text + 'word[] word', '12' ],
  1930. [ '20', '21', '22' ]
  1931. ] ) );
  1932. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1933. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1934. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1935. assertEqualMarkup( getModelData( model ), modelTable( [
  1936. [ '00', '01', '02' ],
  1937. [ '10', text + 'word[ word]', '12' ],
  1938. [ '20', '21', '22' ]
  1939. ] ) );
  1940. } );
  1941. it( 'should expand not collapsed selection to the end of the cell content from the selection anchor', () => {
  1942. setModelData( model, modelTable( [
  1943. [ '00', '01', '02' ],
  1944. [ '10', text + '[word] word', '12' ],
  1945. [ '20', '21', '22' ]
  1946. ] ) );
  1947. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1948. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1949. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1950. assertEqualMarkup( getModelData( model ), modelTable( [
  1951. [ '00', '01', '02' ],
  1952. [ '10', text + '[word word]', '12' ],
  1953. [ '20', '21', '22' ]
  1954. ] ) );
  1955. } );
  1956. } );
  1957. } );
  1958. if ( !env.isGecko ) {
  1959. // These tests fails on Travis. They work correctly when started on local machine.
  1960. // Issue is probably related to text rendering and wrapping.
  1961. describe( 'with selection in the wrap area', () => {
  1962. const text = new Array( 10 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  1963. it( 'should move the caret to end if the caret is after the last space in the line next to the last one', () => {
  1964. // This is also first position in the last line.
  1965. setModelData( model, modelTable( [
  1966. [ '00', '01', '02' ],
  1967. [ '10', text + ' []word word word', '12' ],
  1968. [ '20', '21', '22' ]
  1969. ] ) );
  1970. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1971. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1972. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1973. assertEqualMarkup( getModelData( model ), modelTable( [
  1974. [ '00', '01', '02' ],
  1975. [ '10', text + ' word word word[]', '12' ],
  1976. [ '20', '21', '22' ]
  1977. ] ) );
  1978. } );
  1979. it( 'should move the caret to end if ther caret is at the last space in the line next to last one', () => {
  1980. setModelData( model, modelTable( [
  1981. [ '00', '01', '02' ],
  1982. [ '10', text + '[] word word word', '12' ],
  1983. [ '20', '21', '22' ]
  1984. ] ) );
  1985. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1986. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1987. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1988. assertEqualMarkup( getModelData( model ), modelTable( [
  1989. [ '00', '01', '02' ],
  1990. [ '10', text + ' word word word[]', '12' ],
  1991. [ '20', '21', '22' ]
  1992. ] ) );
  1993. } );
  1994. it( 'should not move the caret if it\'s just before the last space in the line next to last one', () => {
  1995. setModelData( model, modelTable( [
  1996. [ '00', '01', '02' ],
  1997. [ '10', text.substring( 0, text.length - 1 ) + '[]d word word word', '12' ],
  1998. [ '20', '21', '22' ]
  1999. ] ) );
  2000. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2001. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  2002. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  2003. } );
  2004. describe( 'when shift key is pressed', () => {
  2005. beforeEach( () => {
  2006. upArrowDomEvtDataStub.shiftKey = true;
  2007. downArrowDomEvtDataStub.shiftKey = true;
  2008. } );
  2009. it( 'should expand collapsed selection to the end of the cell content', () => {
  2010. setModelData( model, modelTable( [
  2011. [ '00', '01', '02' ],
  2012. [ '10', text + '[] word word word', '12' ],
  2013. [ '20', '21', '22' ]
  2014. ] ) );
  2015. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2016. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2017. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2018. assertEqualMarkup( getModelData( model ), modelTable( [
  2019. [ '00', '01', '02' ],
  2020. [ '10', text + '[ word word word]', '12' ],
  2021. [ '20', '21', '22' ]
  2022. ] ) );
  2023. } );
  2024. it( 'should expand not collapsed selection to the end of the cell content from the selection anchor', () => {
  2025. setModelData( model, modelTable( [
  2026. [ '00', '01', '02' ],
  2027. [ '10', text + '[ word] word word', '12' ],
  2028. [ '20', '21', '22' ]
  2029. ] ) );
  2030. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2031. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2032. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2033. assertEqualMarkup( getModelData( model ), modelTable( [
  2034. [ '00', '01', '02' ],
  2035. [ '10', text + '[ word word word]', '12' ],
  2036. [ '20', '21', '22' ]
  2037. ] ) );
  2038. } );
  2039. } );
  2040. } );
  2041. }
  2042. describe( 'with multiple paragraphs of text', () => {
  2043. const text = new Array( 100 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  2044. it( 'should not navigate if caret is in the middle of a line of text', () => {
  2045. setModelData( model, modelTable( [
  2046. [ '00', '01', '02' ],
  2047. [ '10', `<paragraph>${ text }[]${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2048. [ '20', '21', '22' ]
  2049. ] ) );
  2050. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2051. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  2052. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  2053. } );
  2054. it( 'should move the caret to the beginning of a cell content if the caret is in the first line of text', () => {
  2055. setModelData( model, modelTable( [
  2056. [ '00', '01', '02' ],
  2057. [ '10', `<paragraph>word[]${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2058. [ '20', '21', '22' ]
  2059. ] ) );
  2060. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2061. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2062. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2063. assertEqualMarkup( getModelData( model ), modelTable( [
  2064. [ '00', '01', '02' ],
  2065. [ '10', `<paragraph>[]word${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2066. [ '20', '21', '22' ]
  2067. ] ) );
  2068. } );
  2069. it( 'should not move the caret to the end of a cell content if the caret is not in the last line of text', () => {
  2070. setModelData( model, modelTable( [
  2071. [ '00', '01', '02' ],
  2072. [ '10', `<paragraph>${ text }word []word</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2073. [ '20', '21', '22' ]
  2074. ] ) );
  2075. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2076. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  2077. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  2078. } );
  2079. it( 'should move the caret to end of a cell content if the caret is in the last line of text', () => {
  2080. setModelData( model, modelTable( [
  2081. [ '00', '01', '02' ],
  2082. [ '10', `<paragraph>foobar</paragraph><paragraph>${ text }word []word</paragraph>`, '12' ],
  2083. [ '20', '21', '22' ]
  2084. ] ) );
  2085. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2086. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2087. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2088. assertEqualMarkup( getModelData( model ), modelTable( [
  2089. [ '00', '01', '02' ],
  2090. [ '10', `<paragraph>foobar</paragraph><paragraph>${ text }word word[]</paragraph>`, '12' ],
  2091. [ '20', '21', '22' ]
  2092. ] ) );
  2093. } );
  2094. describe( 'when shift key is pressed', () => {
  2095. beforeEach( () => {
  2096. upArrowDomEvtDataStub.shiftKey = true;
  2097. downArrowDomEvtDataStub.shiftKey = true;
  2098. } );
  2099. it( 'should expand selection to the beginning of the cell content', () => {
  2100. setModelData( model, modelTable( [
  2101. [ '00', '01', '02' ],
  2102. [ '10', `<paragraph>word[] ${ text }</paragraph><paragraph>${ text }</paragraph>`, '12' ],
  2103. [ '20', '21', '22' ]
  2104. ] ) );
  2105. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2106. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2107. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2108. assertEqualMarkup( getModelData( model ), modelTable( [
  2109. [ '00', '01', '02' ],
  2110. [ '10', `<paragraph>[word] ${ text }</paragraph><paragraph>${ text }</paragraph>`, '12' ],
  2111. [ '20', '21', '22' ]
  2112. ] ) );
  2113. } );
  2114. it( 'should expand selection to the end of the cell content', () => {
  2115. setModelData( model, modelTable( [
  2116. [ '00', '01', '02' ],
  2117. [ '10', `<paragraph>${ text }</paragraph><paragraph>${ text } []word</paragraph>`, '12' ],
  2118. [ '20', '21', '22' ]
  2119. ] ) );
  2120. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2121. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2122. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2123. assertEqualMarkup( getModelData( model ), modelTable( [
  2124. [ '00', '01', '02' ],
  2125. [ '10', `<paragraph>${ text }</paragraph><paragraph>${ text } [word]</paragraph>`, '12' ],
  2126. [ '20', '21', '22' ]
  2127. ] ) );
  2128. } );
  2129. } );
  2130. } );
  2131. describe( 'with horizontal line widget', () => {
  2132. const text = new Array( 100 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  2133. it( 'should not navigate if the caret is in the middle line of text', () => {
  2134. setModelData( model, modelTable( [
  2135. [ '00', '01', '02' ],
  2136. [ '10', `<horizontalLine></horizontalLine><paragraph>${ text }[]${ text }</paragraph>`, '12' ],
  2137. [ '20', '21', '22' ]
  2138. ] ) );
  2139. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2140. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  2141. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  2142. } );
  2143. it( 'should move the caret to the beginning of cell content if the caret is in the first line of text', () => {
  2144. setModelData( model, modelTable( [
  2145. [ '00', '01', '02' ],
  2146. [ '10', `<horizontalLine></horizontalLine><paragraph>word[] ${ text }</paragraph>`, '12' ],
  2147. [ '20', '21', '22' ]
  2148. ] ) );
  2149. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2150. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2151. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2152. assertEqualMarkup( getModelData( model ), modelTable( [
  2153. [ '00', '01', '02' ],
  2154. [ '10', `[<horizontalLine></horizontalLine>]<paragraph>word ${ text }</paragraph>`, '12' ],
  2155. [ '20', '21', '22' ]
  2156. ] ) );
  2157. } );
  2158. it( 'should move the caret to the end of cell content if the caret is in the last line of text', () => {
  2159. setModelData( model, modelTable( [
  2160. [ '00', '01', '02' ],
  2161. [ '10', `<paragraph>${ text } word []word</paragraph><horizontalLine></horizontalLine>`, '12' ],
  2162. [ '20', '21', '22' ]
  2163. ] ) );
  2164. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2165. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2166. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2167. assertEqualMarkup( getModelData( model ), modelTable( [
  2168. [ '00', '01', '02' ],
  2169. [ '10', `<paragraph>${ text } word word</paragraph>[<horizontalLine></horizontalLine>]`, '12' ],
  2170. [ '20', '21', '22' ]
  2171. ] ) );
  2172. } );
  2173. it( 'should not move the caret to the end of cell content if widget is selected in middle of a cell content', () => {
  2174. const paragraph = `<paragraph>${ text }</paragraph>`;
  2175. const hr = '<horizontalLine></horizontalLine>';
  2176. setModelData( model, modelTable( [
  2177. [ '00', '01', '02' ],
  2178. [ '10', `${ paragraph }[${ hr }]${ paragraph }${ hr }`, '12' ],
  2179. [ '20', '21', '22' ]
  2180. ] ) );
  2181. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2182. assertEqualMarkup( getModelData( model ), modelTable( [
  2183. [ '00', '01', '02' ],
  2184. [ '10', `${ paragraph }${ hr }<paragraph>[]${ text }</paragraph>${ hr }`, '12' ],
  2185. [ '20', '21', '22' ]
  2186. ] ) );
  2187. } );
  2188. it( 'should not move the caret to the end of cell content if widget is next to the selection', () => {
  2189. const paragraph = `<paragraph>${ text }</paragraph>`;
  2190. const hr = '<horizontalLine></horizontalLine>';
  2191. setModelData( model, modelTable( [
  2192. [ '00', '01', '02' ],
  2193. [ '10', `${ paragraph }[]${ hr }`, '12' ],
  2194. [ '20', '21', '22' ]
  2195. ] ) );
  2196. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2197. assertEqualMarkup( getModelData( model ), modelTable( [
  2198. [ '00', '01', '02' ],
  2199. [ '10', `${ paragraph }[${ hr }]`, '12' ],
  2200. [ '20', '21', '22' ]
  2201. ] ) );
  2202. } );
  2203. describe( 'when shift key is pressed', () => {
  2204. beforeEach( () => {
  2205. upArrowDomEvtDataStub.shiftKey = true;
  2206. downArrowDomEvtDataStub.shiftKey = true;
  2207. } );
  2208. it( 'should expand selection to the beginning of the cell content', () => {
  2209. setModelData( model, modelTable( [
  2210. [ '00', '01', '02' ],
  2211. [ '10', '<horizontalLine></horizontalLine><paragraph>foo[]bar</paragraph>', '12' ],
  2212. [ '20', '21', '22' ]
  2213. ] ) );
  2214. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2215. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2216. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2217. assertEqualMarkup( getModelData( model ), modelTable( [
  2218. [ '00', '01', '02' ],
  2219. [ '10', '[<horizontalLine></horizontalLine><paragraph>foo]bar</paragraph>', '12' ],
  2220. [ '20', '21', '22' ]
  2221. ] ) );
  2222. } );
  2223. it( 'should expand selection to the end of the cell content', () => {
  2224. setModelData( model, modelTable( [
  2225. [ '00', '01', '02' ],
  2226. [ '10', '<paragraph>foo[]bar</paragraph><horizontalLine></horizontalLine>', '12' ],
  2227. [ '20', '21', '22' ]
  2228. ] ) );
  2229. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2230. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2231. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2232. assertEqualMarkup( getModelData( model ), modelTable( [
  2233. [ '00', '01', '02' ],
  2234. [ '10', '<paragraph>foo[bar</paragraph><horizontalLine></horizontalLine>]', '12' ],
  2235. [ '20', '21', '22' ]
  2236. ] ) );
  2237. } );
  2238. } );
  2239. } );
  2240. describe( 'contains image widget with caption and selection inside the caption', () => {
  2241. it( 'should not navigate to the cell on the left', () => {
  2242. setModelData( model, modelTable( [
  2243. [ '00', '01', '02' ],
  2244. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  2245. [ '20', '21', '22' ]
  2246. ] ) );
  2247. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  2248. sinon.assert.notCalled( leftArrowDomEvtDataStub.preventDefault );
  2249. sinon.assert.notCalled( leftArrowDomEvtDataStub.stopPropagation );
  2250. } );
  2251. it( 'should not navigate to the cell on the right', () => {
  2252. setModelData( model, modelTable( [
  2253. [ '00', '01', '02' ],
  2254. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image><paragraph>foo</paragraph>`, '12' ],
  2255. [ '20', '21', '22' ]
  2256. ] ) );
  2257. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  2258. sinon.assert.notCalled( rightArrowDomEvtDataStub.preventDefault );
  2259. sinon.assert.notCalled( rightArrowDomEvtDataStub.stopPropagation );
  2260. } );
  2261. it( 'should not navigate to the cell above', () => {
  2262. setModelData( model, modelTable( [
  2263. [ '00', '01', '02' ],
  2264. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>1[]1</caption></image>`, '12' ],
  2265. [ '20', '21', '22' ]
  2266. ] ) );
  2267. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2268. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  2269. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  2270. } );
  2271. it( 'should not navigate to the cell above but should select the image widget', () => {
  2272. setModelData( model, modelTable( [
  2273. [ '00', '01', '02' ],
  2274. [ '10', `<image src="${ imageUrl }"><caption>1[]1</caption></image><paragraph>foo</paragraph>`, '12' ],
  2275. [ '20', '21', '22' ]
  2276. ] ) );
  2277. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2278. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2279. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2280. assertEqualMarkup( getModelData( model ), modelTable( [
  2281. [ '00', '01', '02' ],
  2282. [ '10', `[<image src="${ imageUrl }"><caption>11</caption></image>]<paragraph>foo</paragraph>`, '12' ],
  2283. [ '20', '21', '22' ]
  2284. ] ) );
  2285. } );
  2286. it( 'should not navigate to the cell below when followed by a paragraph', () => {
  2287. setModelData( model, modelTable( [
  2288. [ '00', '01', '02' ],
  2289. [ '10', `<image src="${ imageUrl }"><caption>1[]1</caption></image><paragraph>foo</paragraph>`, '12' ],
  2290. [ '20', '21', '22' ]
  2291. ] ) );
  2292. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2293. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  2294. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  2295. } );
  2296. it( 'should not navigate to the cell below but should select the image widget', () => {
  2297. setModelData( model, modelTable( [
  2298. [ '00', '01', '02' ],
  2299. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>1[]1</caption></image>`, '12' ],
  2300. [ '20', '21', '22' ]
  2301. ] ) );
  2302. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2303. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2304. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2305. assertEqualMarkup( getModelData( model ), modelTable( [
  2306. [ '00', '01', '02' ],
  2307. [ '10', `<paragraph>foo</paragraph>[<image src="${ imageUrl }"><caption>11</caption></image>]`, '12' ],
  2308. [ '20', '21', '22' ]
  2309. ] ) );
  2310. } );
  2311. it( 'should not navigate to the cell above but should select the image widget without caption', () => {
  2312. setModelData( model, modelTable( [
  2313. [ '00', '01', '02' ],
  2314. [ '10', `<image src="${ imageUrl }"><caption></caption></image><paragraph>f[]oo</paragraph>`, '12' ],
  2315. [ '20', '21', '22' ]
  2316. ] ) );
  2317. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2318. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2319. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2320. assertEqualMarkup( getModelData( model ), modelTable( [
  2321. [ '00', '01', '02' ],
  2322. [ '10', `[<image src="${ imageUrl }"><caption></caption></image>]<paragraph>foo</paragraph>`, '12' ],
  2323. [ '20', '21', '22' ]
  2324. ] ) );
  2325. } );
  2326. it( 'should not navigate to the cell below but should select the image widget without caption', () => {
  2327. setModelData( model, modelTable( [
  2328. [ '00', '01', '02' ],
  2329. [ '10', `<paragraph>f[]oo</paragraph><image src="${ imageUrl }"><caption></caption></image>`, '12' ],
  2330. [ '20', '21', '22' ]
  2331. ] ) );
  2332. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2333. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2334. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2335. assertEqualMarkup( getModelData( model ), modelTable( [
  2336. [ '00', '01', '02' ],
  2337. [ '10', `<paragraph>foo</paragraph>[<image src="${ imageUrl }"><caption></caption></image>]`, '12' ],
  2338. [ '20', '21', '22' ]
  2339. ] ) );
  2340. } );
  2341. } );
  2342. } );
  2343. } );
  2344. describe( 'for right-to-left content language', () => {
  2345. beforeEach( () => {
  2346. return VirtualTestEditor
  2347. .create( {
  2348. plugins: [ TableEditing, TableKeyboard, TableSelection, Paragraph, ImageEditing, MediaEmbedEditing ],
  2349. language: 'ar'
  2350. } )
  2351. .then( newEditor => {
  2352. editor = newEditor;
  2353. model = editor.model;
  2354. modelRoot = model.document.getRoot();
  2355. tableSelection = editor.plugins.get( TableSelection );
  2356. } );
  2357. } );
  2358. describe( 'with the table cell selected from outside', () => {
  2359. beforeEach( () => {
  2360. setModelData( model, modelTable( [
  2361. [ '00', '01', '02' ],
  2362. [ '10', '11', '12' ],
  2363. [ '20', '21', '22' ]
  2364. ] ) );
  2365. tableSelection.setCellSelection(
  2366. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  2367. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  2368. );
  2369. } );
  2370. it( 'should move to the cell on the right (visually flipped by the browser)', () => {
  2371. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  2372. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  2373. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  2374. assertEqualMarkup( getModelData( model ), modelTable( [
  2375. [ '00', '01', '02' ],
  2376. [ '10', '11', '[]12' ],
  2377. [ '20', '21', '22' ]
  2378. ] ) );
  2379. } );
  2380. it( 'should move to the cell on the left (visually flipped by the browser)', () => {
  2381. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  2382. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  2383. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  2384. assertEqualMarkup( getModelData( model ), modelTable( [
  2385. [ '00', '01', '02' ],
  2386. [ '10[]', '11', '12' ],
  2387. [ '20', '21', '22' ]
  2388. ] ) );
  2389. } );
  2390. it( 'should move to the cell above the selection', () => {
  2391. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2392. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2393. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2394. assertEqualMarkup( getModelData( model ), modelTable( [
  2395. [ '00', '01[]', '02' ],
  2396. [ '10', '11', '12' ],
  2397. [ '20', '21', '22' ]
  2398. ] ) );
  2399. } );
  2400. it( 'should move to the cell below the selection', () => {
  2401. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2402. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2403. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2404. assertEqualMarkup( getModelData( model ), modelTable( [
  2405. [ '00', '01', '02' ],
  2406. [ '10', '11', '12' ],
  2407. [ '20', '[]21', '22' ]
  2408. ] ) );
  2409. } );
  2410. } );
  2411. } );
  2412. } );
  2413. } );