tablekeyboard.js 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089
  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 select the whole table 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 ),
  123. '[' + modelTable( [ [ '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 select the whole table 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 move to the cell below if TableSelection plugin is disabled', () => {
  1008. editor.plugins.get( 'TableSelection' ).forceDisabled();
  1009. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1010. assertEqualMarkup( getModelData( model ), modelTable( [
  1011. [ '00', '01', '02' ],
  1012. [ '10[]', '11', '12' ],
  1013. [ '20', '21', '22' ]
  1014. ] ) );
  1015. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1016. assertEqualMarkup( getModelData( model ), modelTable( [
  1017. [ '00', '01', '02' ],
  1018. [ '10', '11', '12' ],
  1019. [ '[]20', '21', '22' ]
  1020. ] ) );
  1021. expect( tableSelection.getAnchorCell() ).to.be.null;
  1022. expect( tableSelection.getFocusCell() ).to.be.null;
  1023. expect( selection.rangeCount ).to.equal( 1 );
  1024. } );
  1025. it( 'should expand the selection to the cell on the left', () => {
  1026. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1027. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1028. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1029. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1030. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 0 ] ) );
  1031. expect( selection.rangeCount ).to.equal( 2 );
  1032. } );
  1033. it( 'should expand the selection to the cell on the right', () => {
  1034. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1035. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1036. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1037. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1038. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 2 ] ) );
  1039. expect( selection.rangeCount ).to.equal( 2 );
  1040. } );
  1041. it( 'should expand the selection to the cell above the selection', () => {
  1042. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1043. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1044. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1045. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1046. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) );
  1047. expect( selection.rangeCount ).to.equal( 2 );
  1048. } );
  1049. it( 'should expand the selection to the cell below the selection', () => {
  1050. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1051. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1052. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1053. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1054. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 1 ] ) );
  1055. expect( selection.rangeCount ).to.equal( 2 );
  1056. } );
  1057. } );
  1058. } );
  1059. describe( 'on multiple table cells selected vertically (the anchor cell above the focus cell)', () => {
  1060. let anchorCell, focusCell;
  1061. beforeEach( () => {
  1062. setModelData( model, modelTable( [
  1063. [ '00', '01', '02', '03' ],
  1064. [ '10', '11', '12', '13' ],
  1065. [ '20', '21', '22', '23' ],
  1066. [ '30', '31', '32', '33' ]
  1067. ] ) );
  1068. anchorCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  1069. focusCell = modelRoot.getNodeByPath( [ 0, 2, 1 ] );
  1070. tableSelection.setCellSelection( anchorCell, focusCell );
  1071. } );
  1072. describe( 'without shift pressed', () => {
  1073. it( 'should move to the cell on the top left of the selection', () => {
  1074. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1075. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1076. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1077. assertEqualMarkup( getModelData( model ), modelTable( [
  1078. [ '00', '01', '02', '03' ],
  1079. [ '10[]', '11', '12', '13' ],
  1080. [ '20', '21', '22', '23' ],
  1081. [ '30', '31', '32', '33' ]
  1082. ] ) );
  1083. } );
  1084. it( 'should move to the cell on the bottom right of the selection', () => {
  1085. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1086. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1087. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1088. assertEqualMarkup( getModelData( model ), modelTable( [
  1089. [ '00', '01', '02', '03' ],
  1090. [ '10', '11', '12', '13' ],
  1091. [ '20', '21', '[]22', '23' ],
  1092. [ '30', '31', '32', '33' ]
  1093. ] ) );
  1094. } );
  1095. it( 'should move to the cell above the selection', () => {
  1096. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1097. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1098. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1099. assertEqualMarkup( getModelData( model ), modelTable( [
  1100. [ '00', '01[]', '02', '03' ],
  1101. [ '10', '11', '12', '13' ],
  1102. [ '20', '21', '22', '23' ],
  1103. [ '30', '31', '32', '33' ]
  1104. ] ) );
  1105. } );
  1106. it( 'should move to the cell below the selection', () => {
  1107. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1108. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1109. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1110. assertEqualMarkup( getModelData( model ), modelTable( [
  1111. [ '00', '01', '02', '03' ],
  1112. [ '10', '11', '12', '13' ],
  1113. [ '20', '21', '22', '23' ],
  1114. [ '30', '[]31', '32', '33' ]
  1115. ] ) );
  1116. } );
  1117. } );
  1118. describe( 'with shift pressed', () => {
  1119. beforeEach( () => {
  1120. leftArrowDomEvtDataStub.shiftKey = true;
  1121. rightArrowDomEvtDataStub.shiftKey = true;
  1122. upArrowDomEvtDataStub.shiftKey = true;
  1123. downArrowDomEvtDataStub.shiftKey = true;
  1124. } );
  1125. it( 'should expand the selection to the cell on the left from the focus cell', () => {
  1126. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1127. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1128. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1129. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1130. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 0 ] ) );
  1131. expect( selection.rangeCount ).to.equal( 4 );
  1132. } );
  1133. it( 'should expand the selection to the cell on the right from the focus cell', () => {
  1134. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1135. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1136. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1137. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1138. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 2 ] ) );
  1139. expect( selection.rangeCount ).to.equal( 4 );
  1140. } );
  1141. it( 'should shrink the selection to the anchor cell', () => {
  1142. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1143. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1144. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1145. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1146. expect( tableSelection.getFocusCell() ).to.equal( anchorCell );
  1147. expect( selection.rangeCount ).to.equal( 1 );
  1148. } );
  1149. it( 'should expand the selection to the cell below the focus cell', () => {
  1150. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1151. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1152. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1153. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1154. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 3, 1 ] ) );
  1155. expect( selection.rangeCount ).to.equal( 3 );
  1156. } );
  1157. } );
  1158. } );
  1159. describe( 'on multiple table cells selected vertically (the anchor cell below the focus cell)', () => {
  1160. let anchorCell, focusCell;
  1161. beforeEach( () => {
  1162. setModelData( model, modelTable( [
  1163. [ '00', '01', '02', '03' ],
  1164. [ '10', '11', '12', '13' ],
  1165. [ '20', '21', '22', '23' ],
  1166. [ '30', '31', '32', '33' ]
  1167. ] ) );
  1168. anchorCell = modelRoot.getNodeByPath( [ 0, 2, 1 ] );
  1169. focusCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  1170. tableSelection.setCellSelection( anchorCell, focusCell );
  1171. } );
  1172. describe( 'without shift pressed', () => {
  1173. it( 'should move to the cell on the top left of the selection', () => {
  1174. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1175. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1176. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1177. assertEqualMarkup( getModelData( model ), modelTable( [
  1178. [ '00', '01', '02', '03' ],
  1179. [ '10[]', '11', '12', '13' ],
  1180. [ '20', '21', '22', '23' ],
  1181. [ '30', '31', '32', '33' ]
  1182. ] ) );
  1183. } );
  1184. it( 'should move to the cell on the bottom right of the selection', () => {
  1185. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1186. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1187. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1188. assertEqualMarkup( getModelData( model ), modelTable( [
  1189. [ '00', '01', '02', '03' ],
  1190. [ '10', '11', '12', '13' ],
  1191. [ '20', '21', '[]22', '23' ],
  1192. [ '30', '31', '32', '33' ]
  1193. ] ) );
  1194. } );
  1195. it( 'should move to the cell above the selection', () => {
  1196. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1197. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1198. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1199. assertEqualMarkup( getModelData( model ), modelTable( [
  1200. [ '00', '01[]', '02', '03' ],
  1201. [ '10', '11', '12', '13' ],
  1202. [ '20', '21', '22', '23' ],
  1203. [ '30', '31', '32', '33' ]
  1204. ] ) );
  1205. } );
  1206. it( 'should move to the cell below the selection', () => {
  1207. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1208. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1209. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1210. assertEqualMarkup( getModelData( model ), modelTable( [
  1211. [ '00', '01', '02', '03' ],
  1212. [ '10', '11', '12', '13' ],
  1213. [ '20', '21', '22', '23' ],
  1214. [ '30', '[]31', '32', '33' ]
  1215. ] ) );
  1216. } );
  1217. } );
  1218. describe( 'with shift pressed', () => {
  1219. beforeEach( () => {
  1220. leftArrowDomEvtDataStub.shiftKey = true;
  1221. rightArrowDomEvtDataStub.shiftKey = true;
  1222. upArrowDomEvtDataStub.shiftKey = true;
  1223. downArrowDomEvtDataStub.shiftKey = true;
  1224. } );
  1225. it( 'should expand the selection to the cell on the left from the focus cell', () => {
  1226. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1227. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1228. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1229. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1230. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 0 ] ) );
  1231. expect( selection.rangeCount ).to.equal( 4 );
  1232. } );
  1233. it( 'should expand the selection to the cell on the right from the focus cell', () => {
  1234. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1235. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1236. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1237. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1238. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 2 ] ) );
  1239. expect( selection.rangeCount ).to.equal( 4 );
  1240. } );
  1241. it( 'should shrink the selection to the anchor cell', () => {
  1242. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1243. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1244. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1245. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1246. expect( tableSelection.getFocusCell() ).to.equal( anchorCell );
  1247. expect( selection.rangeCount ).to.equal( 1 );
  1248. } );
  1249. it( 'should expand the selection to the cell below the focus cell', () => {
  1250. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1251. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1252. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1253. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1254. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) );
  1255. expect( selection.rangeCount ).to.equal( 3 );
  1256. } );
  1257. } );
  1258. } );
  1259. describe( 'on multiple table cell selected horizontally (the anchor cell is to the left of the focus cell ', () => {
  1260. let anchorCell, focusCell;
  1261. beforeEach( () => {
  1262. setModelData( model, modelTable( [
  1263. [ '00', '01', '02', '03' ],
  1264. [ '10', '11', '12', '13' ],
  1265. [ '20', '21', '22', '23' ],
  1266. [ '30', '31', '32', '33' ]
  1267. ] ) );
  1268. anchorCell = modelRoot.getNodeByPath( [ 0, 1, 1 ] );
  1269. focusCell = modelRoot.getNodeByPath( [ 0, 1, 2 ] );
  1270. tableSelection.setCellSelection( anchorCell, focusCell );
  1271. } );
  1272. describe( 'without shift pressed', () => {
  1273. it( 'should move to the cell on the top left of the selection', () => {
  1274. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1275. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1276. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1277. assertEqualMarkup( getModelData( model ), modelTable( [
  1278. [ '00', '01', '02', '03' ],
  1279. [ '10[]', '11', '12', '13' ],
  1280. [ '20', '21', '22', '23' ],
  1281. [ '30', '31', '32', '33' ]
  1282. ] ) );
  1283. } );
  1284. it( 'should move to the cell on the bottom right of the selection', () => {
  1285. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1286. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1287. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1288. assertEqualMarkup( getModelData( model ), modelTable( [
  1289. [ '00', '01', '02', '03' ],
  1290. [ '10', '11', '12', '[]13' ],
  1291. [ '20', '21', '22', '23' ],
  1292. [ '30', '31', '32', '33' ]
  1293. ] ) );
  1294. } );
  1295. it( 'should move to the cell above the selection', () => {
  1296. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1297. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1298. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1299. assertEqualMarkup( getModelData( model ), modelTable( [
  1300. [ '00', '01[]', '02', '03' ],
  1301. [ '10', '11', '12', '13' ],
  1302. [ '20', '21', '22', '23' ],
  1303. [ '30', '31', '32', '33' ]
  1304. ] ) );
  1305. } );
  1306. it( 'should move to the cell below the selection', () => {
  1307. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1308. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1309. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1310. assertEqualMarkup( getModelData( model ), modelTable( [
  1311. [ '00', '01', '02', '03' ],
  1312. [ '10', '11', '12', '13' ],
  1313. [ '20', '21', '[]22', '23' ],
  1314. [ '30', '31', '32', '33' ]
  1315. ] ) );
  1316. } );
  1317. } );
  1318. describe( 'with shift pressed', () => {
  1319. beforeEach( () => {
  1320. leftArrowDomEvtDataStub.shiftKey = true;
  1321. rightArrowDomEvtDataStub.shiftKey = true;
  1322. upArrowDomEvtDataStub.shiftKey = true;
  1323. downArrowDomEvtDataStub.shiftKey = true;
  1324. } );
  1325. it( 'should expand the selection to the cell above the focus cell', () => {
  1326. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1327. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1328. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1329. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1330. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 0, 2 ] ) );
  1331. expect( selection.rangeCount ).to.equal( 4 );
  1332. } );
  1333. it( 'should expand the selection to the cell below the focus cell', () => {
  1334. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1335. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1336. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1337. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1338. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 2, 2 ] ) );
  1339. expect( selection.rangeCount ).to.equal( 4 );
  1340. } );
  1341. it( 'should shrink the selection to the anchor cell', () => {
  1342. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1343. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1344. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1345. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1346. expect( tableSelection.getFocusCell() ).to.equal( anchorCell );
  1347. expect( selection.rangeCount ).to.equal( 1 );
  1348. } );
  1349. it( 'should expand the selection to the cell on the right to the focus cell', () => {
  1350. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1351. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1352. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1353. expect( tableSelection.getAnchorCell() ).to.equal( anchorCell );
  1354. expect( tableSelection.getFocusCell() ).to.equal( modelRoot.getNodeByPath( [ 0, 1, 3 ] ) );
  1355. expect( selection.rangeCount ).to.equal( 3 );
  1356. } );
  1357. } );
  1358. } );
  1359. describe( 'on multiple table cell selected diagonally', () => {
  1360. beforeEach( () => {
  1361. setModelData( model, modelTable( [
  1362. [ '00', '01', '02', '03' ],
  1363. [ '10', '11', '12', '13' ],
  1364. [ '20', '21', '22', '23' ],
  1365. [ '30', '31', '32', '33' ]
  1366. ] ) );
  1367. tableSelection.setCellSelection(
  1368. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  1369. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  1370. );
  1371. } );
  1372. it( 'should move to the cell on the top left of selection', () => {
  1373. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1374. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1375. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1376. assertEqualMarkup( getModelData( model ), modelTable( [
  1377. [ '00', '01', '02', '03' ],
  1378. [ '10[]', '11', '12', '13' ],
  1379. [ '20', '21', '22', '23' ],
  1380. [ '30', '31', '32', '33' ]
  1381. ] ) );
  1382. } );
  1383. it( 'should move to the cell on the bottom right of selection', () => {
  1384. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1385. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1386. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1387. assertEqualMarkup( getModelData( model ), modelTable( [
  1388. [ '00', '01', '02', '03' ],
  1389. [ '10', '11', '12', '13' ],
  1390. [ '20', '21', '22', '[]23' ],
  1391. [ '30', '31', '32', '33' ]
  1392. ] ) );
  1393. } );
  1394. it( 'should move to the cell above selection', () => {
  1395. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1396. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1397. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1398. assertEqualMarkup( getModelData( model ), modelTable( [
  1399. [ '00', '01[]', '02', '03' ],
  1400. [ '10', '11', '12', '13' ],
  1401. [ '20', '21', '22', '23' ],
  1402. [ '30', '31', '32', '33' ]
  1403. ] ) );
  1404. } );
  1405. it( 'should move to the cell below selection', () => {
  1406. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1407. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1408. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1409. assertEqualMarkup( getModelData( model ), modelTable( [
  1410. [ '00', '01', '02', '03' ],
  1411. [ '10', '11', '12', '13' ],
  1412. [ '20', '21', '22', '23' ],
  1413. [ '30', '31', '[]32', '33' ]
  1414. ] ) );
  1415. } );
  1416. } );
  1417. } );
  1418. describe( 'with the selection inside a table cell', () => {
  1419. describe( 'with the selection at the boundary of a cell', () => {
  1420. describe( 'simple cell text content', () => {
  1421. it( 'should navigate to the cell on the left', () => {
  1422. setModelData( model, modelTable( [
  1423. [ '00', '01', '02' ],
  1424. [ '10', '[]11', '12' ],
  1425. [ '20', '21', '22' ]
  1426. ] ) );
  1427. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1428. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1429. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1430. assertEqualMarkup( getModelData( model ), modelTable( [
  1431. [ '00', '01', '02' ],
  1432. [ '10[]', '11', '12' ],
  1433. [ '20', '21', '22' ]
  1434. ] ) );
  1435. } );
  1436. it( 'should navigate to the cell on the right', () => {
  1437. setModelData( model, modelTable( [
  1438. [ '00', '01', '02' ],
  1439. [ '10', '11[]', '12' ],
  1440. [ '20', '21', '22' ]
  1441. ] ) );
  1442. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1443. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1444. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1445. assertEqualMarkup( getModelData( model ), modelTable( [
  1446. [ '00', '01', '02' ],
  1447. [ '10', '11', '[]12' ],
  1448. [ '20', '21', '22' ]
  1449. ] ) );
  1450. } );
  1451. it( 'should navigate to the cell above', () => {
  1452. setModelData( model, modelTable( [
  1453. [ '00', '01', '02' ],
  1454. [ '10', '[]11', '12' ],
  1455. [ '20', '21', '22' ]
  1456. ] ) );
  1457. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1458. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1459. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1460. assertEqualMarkup( getModelData( model ), modelTable( [
  1461. [ '00', '01[]', '02' ],
  1462. [ '10', '11', '12' ],
  1463. [ '20', '21', '22' ]
  1464. ] ) );
  1465. } );
  1466. it( 'should navigate to the cell below', () => {
  1467. setModelData( model, modelTable( [
  1468. [ '00', '01', '02' ],
  1469. [ '10', '11[]', '12' ],
  1470. [ '20', '21', '22' ]
  1471. ] ) );
  1472. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1473. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1474. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1475. assertEqualMarkup( getModelData( model ), modelTable( [
  1476. [ '00', '01', '02' ],
  1477. [ '10', '11', '12' ],
  1478. [ '20', '[]21', '22' ]
  1479. ] ) );
  1480. } );
  1481. } );
  1482. describe( 'multiple paragraphs in the cell content', () => {
  1483. it( 'should navigate to the cell on the left', () => {
  1484. setModelData( model, modelTable( [
  1485. [ '00', '01', '02' ],
  1486. [ '10', '<paragraph>[]11</paragraph><paragraph>x</paragraph>', '12' ],
  1487. [ '20', '21', '22' ]
  1488. ] ) );
  1489. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1490. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1491. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1492. assertEqualMarkup( getModelData( model ), modelTable( [
  1493. [ '00', '01', '02' ],
  1494. [ '10[]', '<paragraph>11</paragraph><paragraph>x</paragraph>', '12' ],
  1495. [ '20', '21', '22' ]
  1496. ] ) );
  1497. } );
  1498. it( 'should navigate to the cell on the right', () => {
  1499. setModelData( model, modelTable( [
  1500. [ '00', '01', '02' ],
  1501. [ '10', '<paragraph>11</paragraph><paragraph>x[]</paragraph>', '12' ],
  1502. [ '20', '21', '22' ]
  1503. ] ) );
  1504. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1505. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1506. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1507. assertEqualMarkup( getModelData( model ), modelTable( [
  1508. [ '00', '01', '02' ],
  1509. [ '10', '<paragraph>11</paragraph><paragraph>x</paragraph>', '[]12' ],
  1510. [ '20', '21', '22' ]
  1511. ] ) );
  1512. } );
  1513. it( 'should navigate to the cell above', () => {
  1514. setModelData( model, modelTable( [
  1515. [ '00', '01', '02' ],
  1516. [ '10', '<paragraph>[]11</paragraph><paragraph>x</paragraph>', '12' ],
  1517. [ '20', '21', '22' ]
  1518. ] ) );
  1519. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1520. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1521. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1522. assertEqualMarkup( getModelData( model ), modelTable( [
  1523. [ '00', '01[]', '02' ],
  1524. [ '10', '<paragraph>11</paragraph><paragraph>x</paragraph>', '12' ],
  1525. [ '20', '21', '22' ]
  1526. ] ) );
  1527. } );
  1528. it( 'should navigate to the cell below', () => {
  1529. setModelData( model, modelTable( [
  1530. [ '00', '01', '02' ],
  1531. [ '10', '<paragraph>11</paragraph><paragraph>x[]</paragraph>', '12' ],
  1532. [ '20', '21', '22' ]
  1533. ] ) );
  1534. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1535. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1536. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1537. assertEqualMarkup( getModelData( model ), modelTable( [
  1538. [ '00', '01', '02' ],
  1539. [ '10', '<paragraph>11</paragraph><paragraph>x</paragraph>', '12' ],
  1540. [ '20', '[]21', '22' ]
  1541. ] ) );
  1542. } );
  1543. } );
  1544. describe( 'image widget with caption as only cell content', () => {
  1545. it( 'should navigate to the cell on the left', () => {
  1546. setModelData( model, modelTable( [
  1547. [ '00', '01', '02' ],
  1548. [ '10', `<image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  1549. [ '20', '21', '22' ]
  1550. ] ) );
  1551. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1552. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1553. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1554. assertEqualMarkup( getModelData( model ), modelTable( [
  1555. [ '00', '01', '02' ],
  1556. [ '10[]', `<image src="${ imageUrl }"><caption>11</caption></image>`, '12' ],
  1557. [ '20', '21', '22' ]
  1558. ] ) );
  1559. } );
  1560. it( 'should navigate to the cell on the right', () => {
  1561. setModelData( model, modelTable( [
  1562. [ '00', '01', '02' ],
  1563. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image>`, '12' ],
  1564. [ '20', '21', '22' ]
  1565. ] ) );
  1566. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1567. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1568. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1569. assertEqualMarkup( getModelData( model ), modelTable( [
  1570. [ '00', '01', '02' ],
  1571. [ '10', `<image src="${ imageUrl }"><caption>11</caption></image>`, '[]12' ],
  1572. [ '20', '21', '22' ]
  1573. ] ) );
  1574. } );
  1575. it( 'should navigate to the cell above', () => {
  1576. setModelData( model, modelTable( [
  1577. [ '00', '01', '02' ],
  1578. [ '10', `<image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  1579. [ '20', '21', '22' ]
  1580. ] ) );
  1581. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1582. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1583. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1584. assertEqualMarkup( getModelData( model ), modelTable( [
  1585. [ '00', '01[]', '02' ],
  1586. [ '10', `<image src="${ imageUrl }"><caption>11</caption></image>`, '12' ],
  1587. [ '20', '21', '22' ]
  1588. ] ) );
  1589. } );
  1590. it( 'should navigate to the cell below', () => {
  1591. setModelData( model, modelTable( [
  1592. [ '00', '01', '02' ],
  1593. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image>`, '12' ],
  1594. [ '20', '21', '22' ]
  1595. ] ) );
  1596. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1597. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1598. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1599. assertEqualMarkup( getModelData( model ), modelTable( [
  1600. [ '00', '01', '02' ],
  1601. [ '10', `<image src="${ imageUrl }"><caption>11</caption></image>`, '12' ],
  1602. [ '20', '[]21', '22' ]
  1603. ] ) );
  1604. } );
  1605. } );
  1606. describe( 'horizontal line as only cell content (widget without $text positions)', () => {
  1607. beforeEach( () => {
  1608. setModelData( model, modelTable( [
  1609. [ '00', '01', '02' ],
  1610. [ '10', '[<horizontalLine></horizontalLine>]', '12' ],
  1611. [ '20', '21', '22' ]
  1612. ] ) );
  1613. } );
  1614. it( 'should navigate to the cell on the left', () => {
  1615. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1616. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1617. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1618. assertEqualMarkup( getModelData( model ), modelTable( [
  1619. [ '00', '01', '02' ],
  1620. [ '10[]', '<horizontalLine></horizontalLine>', '12' ],
  1621. [ '20', '21', '22' ]
  1622. ] ) );
  1623. } );
  1624. it( 'should navigate to the cell on the right', () => {
  1625. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1626. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1627. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1628. assertEqualMarkup( getModelData( model ), modelTable( [
  1629. [ '00', '01', '02' ],
  1630. [ '10', '<horizontalLine></horizontalLine>', '[]12' ],
  1631. [ '20', '21', '22' ]
  1632. ] ) );
  1633. } );
  1634. it( 'should navigate to the cell above', () => {
  1635. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1636. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1637. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1638. assertEqualMarkup( getModelData( model ), modelTable( [
  1639. [ '00', '01[]', '02' ],
  1640. [ '10', '<horizontalLine></horizontalLine>', '12' ],
  1641. [ '20', '21', '22' ]
  1642. ] ) );
  1643. } );
  1644. it( 'should navigate to the cell below', () => {
  1645. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1646. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1647. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1648. assertEqualMarkup( getModelData( model ), modelTable( [
  1649. [ '00', '01', '02' ],
  1650. [ '10', '<horizontalLine></horizontalLine>', '12' ],
  1651. [ '20', '[]21', '22' ]
  1652. ] ) );
  1653. } );
  1654. } );
  1655. describe( 'two horizontal lines as only cell content (widget without $text positions)', () => {
  1656. it( 'should navigate to the cell on the left', () => {
  1657. setModelData( model, modelTable( [
  1658. [ '00', '01', '02' ],
  1659. [ '10', '[<horizontalLine></horizontalLine>]<horizontalLine></horizontalLine>', '12' ],
  1660. [ '20', '21', '22' ]
  1661. ] ) );
  1662. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1663. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  1664. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  1665. assertEqualMarkup( getModelData( model ), modelTable( [
  1666. [ '00', '01', '02' ],
  1667. [ '10[]', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '12' ],
  1668. [ '20', '21', '22' ]
  1669. ] ) );
  1670. } );
  1671. it( 'should navigate to the cell on the right', () => {
  1672. setModelData( model, modelTable( [
  1673. [ '00', '01', '02' ],
  1674. [ '10', '<horizontalLine></horizontalLine>[<horizontalLine></horizontalLine>]', '12' ],
  1675. [ '20', '21', '22' ]
  1676. ] ) );
  1677. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1678. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  1679. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  1680. assertEqualMarkup( getModelData( model ), modelTable( [
  1681. [ '00', '01', '02' ],
  1682. [ '10', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '[]12' ],
  1683. [ '20', '21', '22' ]
  1684. ] ) );
  1685. } );
  1686. it( 'should navigate to the cell above', () => {
  1687. setModelData( model, modelTable( [
  1688. [ '00', '01', '02' ],
  1689. [ '10', '[<horizontalLine></horizontalLine>]<horizontalLine></horizontalLine>', '12' ],
  1690. [ '20', '21', '22' ]
  1691. ] ) );
  1692. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1693. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1694. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1695. assertEqualMarkup( getModelData( model ), modelTable( [
  1696. [ '00', '01[]', '02' ],
  1697. [ '10', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '12' ],
  1698. [ '20', '21', '22' ]
  1699. ] ) );
  1700. } );
  1701. it( 'should navigate to the cell below', () => {
  1702. setModelData( model, modelTable( [
  1703. [ '00', '01', '02' ],
  1704. [ '10', '<horizontalLine></horizontalLine>[<horizontalLine></horizontalLine>]', '12' ],
  1705. [ '20', '21', '22' ]
  1706. ] ) );
  1707. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1708. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1709. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1710. assertEqualMarkup( getModelData( model ), modelTable( [
  1711. [ '00', '01', '02' ],
  1712. [ '10', '<horizontalLine></horizontalLine><horizontalLine></horizontalLine>', '12' ],
  1713. [ '20', '[]21', '22' ]
  1714. ] ) );
  1715. } );
  1716. } );
  1717. } );
  1718. describe( 'with selection not at the boundary of a cell', () => {
  1719. let editorElement, editor, model, styleElement;
  1720. beforeEach( async () => {
  1721. editorElement = global.document.createElement( 'div' );
  1722. global.document.body.appendChild( editorElement );
  1723. editor = await ClassicTestEditor.create( editorElement, {
  1724. plugins: [ Table, Paragraph, Image, ImageCaption, HorizontalLine ]
  1725. } );
  1726. model = editor.model;
  1727. styleElement = global.document.createElement( 'style' );
  1728. styleElement.type = 'text/css';
  1729. styleElement.appendChild( global.document.createTextNode(
  1730. `
  1731. * {
  1732. font-size: 12px !important;
  1733. font-family: serif !important;
  1734. margin: 0 !important;
  1735. padding: 0 !important;
  1736. border: 0 !important
  1737. }
  1738. td { width: 30px !important; }
  1739. tr:nth-child(2) td:nth-child(2) { width: 300px !important; }
  1740. `
  1741. ) );
  1742. global.document.querySelector( 'head' ).appendChild( styleElement );
  1743. // The editing view must be focused because otherwise in Chrome the DOM selection will not contain
  1744. // any ranges and jumpOverUiElement will crash (for the right arrow when shift is pressed).
  1745. editor.editing.view.focus();
  1746. } );
  1747. afterEach( async () => {
  1748. editorElement.remove();
  1749. styleElement.remove();
  1750. await editor.destroy();
  1751. } );
  1752. describe( 'simple cell text content', () => {
  1753. it( 'should not navigate to the cell on the left', () => {
  1754. setModelData( model, modelTable( [
  1755. [ '00', '01', '02' ],
  1756. [ '10', '1[]1', '12' ],
  1757. [ '20', '21', '22' ]
  1758. ] ) );
  1759. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1760. sinon.assert.notCalled( leftArrowDomEvtDataStub.preventDefault );
  1761. sinon.assert.notCalled( leftArrowDomEvtDataStub.stopPropagation );
  1762. } );
  1763. it( 'should not navigate to the cell on the right', () => {
  1764. setModelData( model, modelTable( [
  1765. [ '00', '01', '02' ],
  1766. [ '10', '1[]1', '12' ],
  1767. [ '20', '21', '22' ]
  1768. ] ) );
  1769. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1770. sinon.assert.notCalled( rightArrowDomEvtDataStub.preventDefault );
  1771. sinon.assert.notCalled( rightArrowDomEvtDataStub.stopPropagation );
  1772. } );
  1773. it( 'should not navigate to the cell above', () => {
  1774. setModelData( model, modelTable( [
  1775. [ '00', '01', '02' ],
  1776. [ '10', '1[]1', '12' ],
  1777. [ '20', '21', '22' ]
  1778. ] ) );
  1779. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1780. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1781. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1782. assertEqualMarkup( getModelData( model ), modelTable( [
  1783. [ '00', '01', '02' ],
  1784. [ '10', '[]11', '12' ],
  1785. [ '20', '21', '22' ]
  1786. ] ) );
  1787. } );
  1788. it( 'should not navigate to the cell below', () => {
  1789. setModelData( model, modelTable( [
  1790. [ '00', '01', '02' ],
  1791. [ '10', '1[]1', '12' ],
  1792. [ '20', '21', '22' ]
  1793. ] ) );
  1794. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1795. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1796. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1797. assertEqualMarkup( getModelData( model ), modelTable( [
  1798. [ '00', '01', '02' ],
  1799. [ '10', '11[]', '12' ],
  1800. [ '20', '21', '22' ]
  1801. ] ) );
  1802. } );
  1803. describe( 'when shift key is pressed', () => {
  1804. beforeEach( () => {
  1805. setModelData( model, modelTable( [
  1806. [ '00', '01', '02' ],
  1807. [ '10', '1[]1', '12' ],
  1808. [ '20', '21', '22' ]
  1809. ] ) );
  1810. leftArrowDomEvtDataStub.shiftKey = true;
  1811. rightArrowDomEvtDataStub.shiftKey = true;
  1812. upArrowDomEvtDataStub.shiftKey = true;
  1813. downArrowDomEvtDataStub.shiftKey = true;
  1814. } );
  1815. it( 'should not prevent default browser behavior for the left arrow pressed with shift', () => {
  1816. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  1817. sinon.assert.notCalled( leftArrowDomEvtDataStub.preventDefault );
  1818. sinon.assert.notCalled( leftArrowDomEvtDataStub.stopPropagation );
  1819. } );
  1820. it( 'should not prevent default browser behavior for the right arrow pressed with shift', () => {
  1821. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  1822. sinon.assert.notCalled( rightArrowDomEvtDataStub.preventDefault );
  1823. sinon.assert.notCalled( rightArrowDomEvtDataStub.stopPropagation );
  1824. } );
  1825. it( 'should expand selection to the beginning of the cell content', () => {
  1826. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1827. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1828. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1829. assertEqualMarkup( getModelData( model ), modelTable( [
  1830. [ '00', '01', '02' ],
  1831. [ '10', '[1]1', '12' ],
  1832. [ '20', '21', '22' ]
  1833. ] ) );
  1834. } );
  1835. it( 'should expand selection to the end of the cell content', () => {
  1836. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1837. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1838. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1839. assertEqualMarkup( getModelData( model ), modelTable( [
  1840. [ '00', '01', '02' ],
  1841. [ '10', '1[1]', '12' ],
  1842. [ '20', '21', '22' ]
  1843. ] ) );
  1844. } );
  1845. } );
  1846. } );
  1847. describe( 'selection inside paragraph', () => {
  1848. const text = new Array( 20 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  1849. it( 'should not navigate if caret is in the middle line of a text', () => {
  1850. setModelData( model, modelTable( [
  1851. [ '00', '01', '02' ],
  1852. [ '10', text + '[] ' + text, '12' ],
  1853. [ '20', '21', '22' ]
  1854. ] ) );
  1855. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1856. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  1857. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  1858. } );
  1859. it( 'should move caret to beginning of cell content if caret is in the first line of a text', () => {
  1860. setModelData( model, modelTable( [
  1861. [ '00', '01', '02' ],
  1862. [ '10', 'word[] word' + text, '12' ],
  1863. [ '20', '21', '22' ]
  1864. ] ) );
  1865. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1866. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1867. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1868. assertEqualMarkup( getModelData( model ), modelTable( [
  1869. [ '00', '01', '02' ],
  1870. [ '10', '[]word word' + text, '12' ],
  1871. [ '20', '21', '22' ]
  1872. ] ) );
  1873. } );
  1874. it( 'should move caret to end of cell content if caret is in the last line of a text', () => {
  1875. setModelData( model, modelTable( [
  1876. [ '00', '01', '02' ],
  1877. [ '10', text + 'word[] word', '12' ],
  1878. [ '20', '21', '22' ]
  1879. ] ) );
  1880. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1881. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1882. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1883. assertEqualMarkup( getModelData( model ), modelTable( [
  1884. [ '00', '01', '02' ],
  1885. [ '10', text + 'word word[]', '12' ],
  1886. [ '20', '21', '22' ]
  1887. ] ) );
  1888. } );
  1889. describe( 'when shift key is pressed', () => {
  1890. beforeEach( () => {
  1891. upArrowDomEvtDataStub.shiftKey = true;
  1892. downArrowDomEvtDataStub.shiftKey = true;
  1893. } );
  1894. it( 'should not prevent default browser behavior for the up arrow in the middle lines of the cell text', () => {
  1895. setModelData( model, modelTable( [
  1896. [ '00', '01', '02' ],
  1897. [ '10', text + '[] ' + text, '12' ],
  1898. [ '20', '21', '22' ]
  1899. ] ) );
  1900. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1901. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  1902. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  1903. } );
  1904. it( 'should not prevent default browser behavior for the down arrow in the middle lines of cell text', () => {
  1905. setModelData( model, modelTable( [
  1906. [ '00', '01', '02' ],
  1907. [ '10', text + '[] ' + text, '12' ],
  1908. [ '20', '21', '22' ]
  1909. ] ) );
  1910. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1911. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  1912. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  1913. } );
  1914. it( 'should expand collapsed selection to the beginning of the cell content', () => {
  1915. setModelData( model, modelTable( [
  1916. [ '00', '01', '02' ],
  1917. [ '10', 'word[] word' + text, '12' ],
  1918. [ '20', '21', '22' ]
  1919. ] ) );
  1920. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1921. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1922. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1923. assertEqualMarkup( getModelData( model ), modelTable( [
  1924. [ '00', '01', '02' ],
  1925. [ '10', '[word] word' + text, '12' ],
  1926. [ '20', '21', '22' ]
  1927. ] ) );
  1928. } );
  1929. it( 'should expand not collapsed selection to the beginning of the cell content from the selection anchor', () => {
  1930. setModelData( model, modelTable( [
  1931. [ '00', '01', '02' ],
  1932. [ '10', 'word [word]' + text, '12' ],
  1933. [ '20', '21', '22' ]
  1934. ] ) );
  1935. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1936. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1937. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1938. assertEqualMarkup( getModelData( model ), modelTable( [
  1939. [ '00', '01', '02' ],
  1940. [ '10', '[word ]word' + text, '12' ],
  1941. [ '20', '21', '22' ]
  1942. ] ) );
  1943. } );
  1944. it( 'should expand collapsed selection to the end of the cell content', () => {
  1945. setModelData( model, modelTable( [
  1946. [ '00', '01', '02' ],
  1947. [ '10', text + 'word[] word', '12' ],
  1948. [ '20', '21', '22' ]
  1949. ] ) );
  1950. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1951. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1952. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1953. assertEqualMarkup( getModelData( model ), modelTable( [
  1954. [ '00', '01', '02' ],
  1955. [ '10', text + 'word[ word]', '12' ],
  1956. [ '20', '21', '22' ]
  1957. ] ) );
  1958. } );
  1959. it( 'should expand not collapsed selection to the end of the cell content from the selection anchor', () => {
  1960. setModelData( model, modelTable( [
  1961. [ '00', '01', '02' ],
  1962. [ '10', text + '[word] word', '12' ],
  1963. [ '20', '21', '22' ]
  1964. ] ) );
  1965. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1966. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1967. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1968. assertEqualMarkup( getModelData( model ), modelTable( [
  1969. [ '00', '01', '02' ],
  1970. [ '10', text + '[word word]', '12' ],
  1971. [ '20', '21', '22' ]
  1972. ] ) );
  1973. } );
  1974. } );
  1975. } );
  1976. if ( !env.isGecko ) {
  1977. // These tests fails on Travis. They work correctly when started on local machine.
  1978. // Issue is probably related to text rendering and wrapping.
  1979. describe( 'with selection in the wrap area', () => {
  1980. const text = new Array( 10 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  1981. it( 'should move the caret to end if the caret is after the last space in the line next to the last one', () => {
  1982. // This is also first position in the last line.
  1983. setModelData( model, modelTable( [
  1984. [ '00', '01', '02' ],
  1985. [ '10', text + ' []word word word', '12' ],
  1986. [ '20', '21', '22' ]
  1987. ] ) );
  1988. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1989. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1990. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1991. assertEqualMarkup( getModelData( model ), modelTable( [
  1992. [ '00', '01', '02' ],
  1993. [ '10', text + ' word word word[]', '12' ],
  1994. [ '20', '21', '22' ]
  1995. ] ) );
  1996. } );
  1997. it( 'should move the caret to end if ther caret is at the last space in the line next to last one', () => {
  1998. setModelData( model, modelTable( [
  1999. [ '00', '01', '02' ],
  2000. [ '10', text + '[] word word word', '12' ],
  2001. [ '20', '21', '22' ]
  2002. ] ) );
  2003. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2004. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2005. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2006. assertEqualMarkup( getModelData( model ), modelTable( [
  2007. [ '00', '01', '02' ],
  2008. [ '10', text + ' word word word[]', '12' ],
  2009. [ '20', '21', '22' ]
  2010. ] ) );
  2011. } );
  2012. it( 'should not move the caret if it\'s just before the last space in the line next to last one', () => {
  2013. setModelData( model, modelTable( [
  2014. [ '00', '01', '02' ],
  2015. [ '10', text.substring( 0, text.length - 1 ) + '[]d word word word', '12' ],
  2016. [ '20', '21', '22' ]
  2017. ] ) );
  2018. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2019. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  2020. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  2021. } );
  2022. describe( 'when shift key is pressed', () => {
  2023. beforeEach( () => {
  2024. upArrowDomEvtDataStub.shiftKey = true;
  2025. downArrowDomEvtDataStub.shiftKey = true;
  2026. } );
  2027. it( 'should expand collapsed selection to the end of the cell content', () => {
  2028. setModelData( model, modelTable( [
  2029. [ '00', '01', '02' ],
  2030. [ '10', text + '[] word word word', '12' ],
  2031. [ '20', '21', '22' ]
  2032. ] ) );
  2033. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2034. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2035. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2036. assertEqualMarkup( getModelData( model ), modelTable( [
  2037. [ '00', '01', '02' ],
  2038. [ '10', text + '[ word word word]', '12' ],
  2039. [ '20', '21', '22' ]
  2040. ] ) );
  2041. } );
  2042. it( 'should expand not collapsed selection to the end of the cell content from the selection anchor', () => {
  2043. setModelData( model, modelTable( [
  2044. [ '00', '01', '02' ],
  2045. [ '10', text + '[ word] word word', '12' ],
  2046. [ '20', '21', '22' ]
  2047. ] ) );
  2048. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2049. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2050. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2051. assertEqualMarkup( getModelData( model ), modelTable( [
  2052. [ '00', '01', '02' ],
  2053. [ '10', text + '[ word word word]', '12' ],
  2054. [ '20', '21', '22' ]
  2055. ] ) );
  2056. } );
  2057. } );
  2058. } );
  2059. }
  2060. describe( 'with multiple paragraphs of text', () => {
  2061. const text = new Array( 100 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  2062. it( 'should not navigate if caret is in the middle of a line of text', () => {
  2063. setModelData( model, modelTable( [
  2064. [ '00', '01', '02' ],
  2065. [ '10', `<paragraph>${ text }[]${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2066. [ '20', '21', '22' ]
  2067. ] ) );
  2068. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2069. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  2070. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  2071. } );
  2072. it( 'should move the caret to the beginning of a cell content if the caret is in the first line of text', () => {
  2073. setModelData( model, modelTable( [
  2074. [ '00', '01', '02' ],
  2075. [ '10', `<paragraph>word[]${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2076. [ '20', '21', '22' ]
  2077. ] ) );
  2078. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2079. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2080. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2081. assertEqualMarkup( getModelData( model ), modelTable( [
  2082. [ '00', '01', '02' ],
  2083. [ '10', `<paragraph>[]word${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2084. [ '20', '21', '22' ]
  2085. ] ) );
  2086. } );
  2087. it( 'should not move the caret to the end of a cell content if the caret is not in the last line of text', () => {
  2088. setModelData( model, modelTable( [
  2089. [ '00', '01', '02' ],
  2090. [ '10', `<paragraph>${ text }word []word</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2091. [ '20', '21', '22' ]
  2092. ] ) );
  2093. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2094. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  2095. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  2096. } );
  2097. it( 'should move the caret to end of a cell content if the caret is in the last line of text', () => {
  2098. setModelData( model, modelTable( [
  2099. [ '00', '01', '02' ],
  2100. [ '10', `<paragraph>foobar</paragraph><paragraph>${ text }word []word</paragraph>`, '12' ],
  2101. [ '20', '21', '22' ]
  2102. ] ) );
  2103. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2104. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2105. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2106. assertEqualMarkup( getModelData( model ), modelTable( [
  2107. [ '00', '01', '02' ],
  2108. [ '10', `<paragraph>foobar</paragraph><paragraph>${ text }word word[]</paragraph>`, '12' ],
  2109. [ '20', '21', '22' ]
  2110. ] ) );
  2111. } );
  2112. describe( 'when shift key is pressed', () => {
  2113. beforeEach( () => {
  2114. upArrowDomEvtDataStub.shiftKey = true;
  2115. downArrowDomEvtDataStub.shiftKey = true;
  2116. } );
  2117. it( 'should expand selection to the beginning of the cell content', () => {
  2118. setModelData( model, modelTable( [
  2119. [ '00', '01', '02' ],
  2120. [ '10', `<paragraph>word[] ${ text }</paragraph><paragraph>${ text }</paragraph>`, '12' ],
  2121. [ '20', '21', '22' ]
  2122. ] ) );
  2123. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2124. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2125. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2126. assertEqualMarkup( getModelData( model ), modelTable( [
  2127. [ '00', '01', '02' ],
  2128. [ '10', `<paragraph>[word] ${ text }</paragraph><paragraph>${ text }</paragraph>`, '12' ],
  2129. [ '20', '21', '22' ]
  2130. ] ) );
  2131. } );
  2132. it( 'should expand selection to the end of the cell content', () => {
  2133. setModelData( model, modelTable( [
  2134. [ '00', '01', '02' ],
  2135. [ '10', `<paragraph>${ text }</paragraph><paragraph>${ text } []word</paragraph>`, '12' ],
  2136. [ '20', '21', '22' ]
  2137. ] ) );
  2138. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2139. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2140. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2141. assertEqualMarkup( getModelData( model ), modelTable( [
  2142. [ '00', '01', '02' ],
  2143. [ '10', `<paragraph>${ text }</paragraph><paragraph>${ text } [word]</paragraph>`, '12' ],
  2144. [ '20', '21', '22' ]
  2145. ] ) );
  2146. } );
  2147. } );
  2148. } );
  2149. describe( 'with horizontal line widget', () => {
  2150. const text = new Array( 100 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  2151. it( 'should not navigate if the caret is in the middle line of text', () => {
  2152. setModelData( model, modelTable( [
  2153. [ '00', '01', '02' ],
  2154. [ '10', `<horizontalLine></horizontalLine><paragraph>${ text }[]${ text }</paragraph>`, '12' ],
  2155. [ '20', '21', '22' ]
  2156. ] ) );
  2157. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2158. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  2159. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  2160. } );
  2161. it( 'should move the caret to the beginning of cell content if the caret is in the first line of text', () => {
  2162. setModelData( model, modelTable( [
  2163. [ '00', '01', '02' ],
  2164. [ '10', `<horizontalLine></horizontalLine><paragraph>word[] ${ text }</paragraph>`, '12' ],
  2165. [ '20', '21', '22' ]
  2166. ] ) );
  2167. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2168. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2169. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2170. assertEqualMarkup( getModelData( model ), modelTable( [
  2171. [ '00', '01', '02' ],
  2172. [ '10', `[<horizontalLine></horizontalLine>]<paragraph>word ${ text }</paragraph>`, '12' ],
  2173. [ '20', '21', '22' ]
  2174. ] ) );
  2175. } );
  2176. it( 'should move the caret to the end of cell content if the caret is in the last line of text', () => {
  2177. setModelData( model, modelTable( [
  2178. [ '00', '01', '02' ],
  2179. [ '10', `<paragraph>${ text } word []word</paragraph><horizontalLine></horizontalLine>`, '12' ],
  2180. [ '20', '21', '22' ]
  2181. ] ) );
  2182. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2183. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2184. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2185. assertEqualMarkup( getModelData( model ), modelTable( [
  2186. [ '00', '01', '02' ],
  2187. [ '10', `<paragraph>${ text } word word</paragraph>[<horizontalLine></horizontalLine>]`, '12' ],
  2188. [ '20', '21', '22' ]
  2189. ] ) );
  2190. } );
  2191. it( 'should not move the caret to the end of cell content if widget is selected in middle of a cell content', () => {
  2192. const paragraph = `<paragraph>${ text }</paragraph>`;
  2193. const hr = '<horizontalLine></horizontalLine>';
  2194. setModelData( model, modelTable( [
  2195. [ '00', '01', '02' ],
  2196. [ '10', `${ paragraph }[${ hr }]${ paragraph }${ hr }`, '12' ],
  2197. [ '20', '21', '22' ]
  2198. ] ) );
  2199. // Note: Two keydowns are necessary because the first one is handled by the WidgetTypeAround plugin
  2200. // to activate the "fake caret".
  2201. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2202. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2203. assertEqualMarkup( getModelData( model ), modelTable( [
  2204. [ '00', '01', '02' ],
  2205. [ '10', `${ paragraph }${ hr }<paragraph>[]${ text }</paragraph>${ hr }`, '12' ],
  2206. [ '20', '21', '22' ]
  2207. ] ) );
  2208. } );
  2209. it( 'should not move the caret to the end of cell content if widget is next to the selection', () => {
  2210. const paragraph = `<paragraph>${ text }</paragraph>`;
  2211. const hr = '<horizontalLine></horizontalLine>';
  2212. setModelData( model, modelTable( [
  2213. [ '00', '01', '02' ],
  2214. [ '10', `${ paragraph }[]${ hr }`, '12' ],
  2215. [ '20', '21', '22' ]
  2216. ] ) );
  2217. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2218. assertEqualMarkup( getModelData( model ), modelTable( [
  2219. [ '00', '01', '02' ],
  2220. [ '10', `${ paragraph }[${ hr }]`, '12' ],
  2221. [ '20', '21', '22' ]
  2222. ] ) );
  2223. } );
  2224. describe( 'when shift key is pressed', () => {
  2225. beforeEach( () => {
  2226. upArrowDomEvtDataStub.shiftKey = true;
  2227. downArrowDomEvtDataStub.shiftKey = true;
  2228. } );
  2229. it( 'should expand selection to the beginning of the cell content', () => {
  2230. setModelData( model, modelTable( [
  2231. [ '00', '01', '02' ],
  2232. [ '10', '<horizontalLine></horizontalLine><paragraph>foo[]bar</paragraph>', '12' ],
  2233. [ '20', '21', '22' ]
  2234. ] ) );
  2235. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2236. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2237. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2238. assertEqualMarkup( getModelData( model ), modelTable( [
  2239. [ '00', '01', '02' ],
  2240. [ '10', '[<horizontalLine></horizontalLine><paragraph>foo]bar</paragraph>', '12' ],
  2241. [ '20', '21', '22' ]
  2242. ] ) );
  2243. } );
  2244. it( 'should expand selection to the end of the cell content', () => {
  2245. setModelData( model, modelTable( [
  2246. [ '00', '01', '02' ],
  2247. [ '10', '<paragraph>foo[]bar</paragraph><horizontalLine></horizontalLine>', '12' ],
  2248. [ '20', '21', '22' ]
  2249. ] ) );
  2250. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2251. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2252. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2253. assertEqualMarkup( getModelData( model ), modelTable( [
  2254. [ '00', '01', '02' ],
  2255. [ '10', '<paragraph>foo[bar</paragraph><horizontalLine></horizontalLine>]', '12' ],
  2256. [ '20', '21', '22' ]
  2257. ] ) );
  2258. } );
  2259. } );
  2260. } );
  2261. describe( 'contains image widget with caption and selection inside the caption', () => {
  2262. it( 'should not navigate to the cell on the left', () => {
  2263. setModelData( model, modelTable( [
  2264. [ '00', '01', '02' ],
  2265. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  2266. [ '20', '21', '22' ]
  2267. ] ) );
  2268. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  2269. sinon.assert.notCalled( leftArrowDomEvtDataStub.preventDefault );
  2270. sinon.assert.notCalled( leftArrowDomEvtDataStub.stopPropagation );
  2271. } );
  2272. it( 'should not navigate to the cell on the right', () => {
  2273. setModelData( model, modelTable( [
  2274. [ '00', '01', '02' ],
  2275. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image><paragraph>foo</paragraph>`, '12' ],
  2276. [ '20', '21', '22' ]
  2277. ] ) );
  2278. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  2279. sinon.assert.notCalled( rightArrowDomEvtDataStub.preventDefault );
  2280. sinon.assert.notCalled( rightArrowDomEvtDataStub.stopPropagation );
  2281. } );
  2282. it( 'should not navigate to the cell above', () => {
  2283. setModelData( model, modelTable( [
  2284. [ '00', '01', '02' ],
  2285. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>1[]1</caption></image>`, '12' ],
  2286. [ '20', '21', '22' ]
  2287. ] ) );
  2288. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2289. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  2290. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  2291. } );
  2292. it( 'should not navigate to the cell above but should select the image widget', () => {
  2293. setModelData( model, modelTable( [
  2294. [ '00', '01', '02' ],
  2295. [ '10', `<image src="${ imageUrl }"><caption>1[]1</caption></image><paragraph>foo</paragraph>`, '12' ],
  2296. [ '20', '21', '22' ]
  2297. ] ) );
  2298. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2299. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2300. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2301. assertEqualMarkup( getModelData( model ), modelTable( [
  2302. [ '00', '01', '02' ],
  2303. [ '10', `[<image src="${ imageUrl }"><caption>11</caption></image>]<paragraph>foo</paragraph>`, '12' ],
  2304. [ '20', '21', '22' ]
  2305. ] ) );
  2306. } );
  2307. it( 'should not navigate to the cell below when followed by a paragraph', () => {
  2308. setModelData( model, modelTable( [
  2309. [ '00', '01', '02' ],
  2310. [ '10', `<image src="${ imageUrl }"><caption>1[]1</caption></image><paragraph>foo</paragraph>`, '12' ],
  2311. [ '20', '21', '22' ]
  2312. ] ) );
  2313. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2314. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  2315. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  2316. } );
  2317. it( 'should not navigate to the cell below but should select the image widget', () => {
  2318. setModelData( model, modelTable( [
  2319. [ '00', '01', '02' ],
  2320. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>1[]1</caption></image>`, '12' ],
  2321. [ '20', '21', '22' ]
  2322. ] ) );
  2323. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2324. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2325. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2326. assertEqualMarkup( getModelData( model ), modelTable( [
  2327. [ '00', '01', '02' ],
  2328. [ '10', `<paragraph>foo</paragraph>[<image src="${ imageUrl }"><caption>11</caption></image>]`, '12' ],
  2329. [ '20', '21', '22' ]
  2330. ] ) );
  2331. } );
  2332. it( 'should not navigate to the cell above but should select the image widget without caption', () => {
  2333. setModelData( model, modelTable( [
  2334. [ '00', '01', '02' ],
  2335. [ '10', `<image src="${ imageUrl }"><caption></caption></image><paragraph>f[]oo</paragraph>`, '12' ],
  2336. [ '20', '21', '22' ]
  2337. ] ) );
  2338. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2339. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2340. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2341. assertEqualMarkup( getModelData( model ), modelTable( [
  2342. [ '00', '01', '02' ],
  2343. [ '10', `[<image src="${ imageUrl }"><caption></caption></image>]<paragraph>foo</paragraph>`, '12' ],
  2344. [ '20', '21', '22' ]
  2345. ] ) );
  2346. } );
  2347. it( 'should not navigate to the cell below but should select the image widget without caption', () => {
  2348. setModelData( model, modelTable( [
  2349. [ '00', '01', '02' ],
  2350. [ '10', `<paragraph>f[]oo</paragraph><image src="${ imageUrl }"><caption></caption></image>`, '12' ],
  2351. [ '20', '21', '22' ]
  2352. ] ) );
  2353. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2354. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2355. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2356. assertEqualMarkup( getModelData( model ), modelTable( [
  2357. [ '00', '01', '02' ],
  2358. [ '10', `<paragraph>foo</paragraph>[<image src="${ imageUrl }"><caption></caption></image>]`, '12' ],
  2359. [ '20', '21', '22' ]
  2360. ] ) );
  2361. } );
  2362. } );
  2363. } );
  2364. } );
  2365. describe( 'for right-to-left content language', () => {
  2366. beforeEach( () => {
  2367. return VirtualTestEditor
  2368. .create( {
  2369. plugins: [ TableEditing, TableKeyboard, TableSelection, Paragraph, ImageEditing, MediaEmbedEditing ],
  2370. language: 'ar'
  2371. } )
  2372. .then( newEditor => {
  2373. editor = newEditor;
  2374. model = editor.model;
  2375. modelRoot = model.document.getRoot();
  2376. tableSelection = editor.plugins.get( TableSelection );
  2377. } );
  2378. } );
  2379. describe( 'with the table cell selected from outside', () => {
  2380. beforeEach( () => {
  2381. setModelData( model, modelTable( [
  2382. [ '00', '01', '02' ],
  2383. [ '10', '11', '12' ],
  2384. [ '20', '21', '22' ]
  2385. ] ) );
  2386. tableSelection.setCellSelection(
  2387. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  2388. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  2389. );
  2390. } );
  2391. it( 'should move to the cell on the right (visually flipped by the browser)', () => {
  2392. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  2393. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  2394. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  2395. assertEqualMarkup( getModelData( model ), modelTable( [
  2396. [ '00', '01', '02' ],
  2397. [ '10', '11', '[]12' ],
  2398. [ '20', '21', '22' ]
  2399. ] ) );
  2400. } );
  2401. it( 'should move to the cell on the left (visually flipped by the browser)', () => {
  2402. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  2403. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  2404. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  2405. assertEqualMarkup( getModelData( model ), modelTable( [
  2406. [ '00', '01', '02' ],
  2407. [ '10[]', '11', '12' ],
  2408. [ '20', '21', '22' ]
  2409. ] ) );
  2410. } );
  2411. it( 'should move to the cell above the selection', () => {
  2412. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2413. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2414. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2415. assertEqualMarkup( getModelData( model ), modelTable( [
  2416. [ '00', '01[]', '02' ],
  2417. [ '10', '11', '12' ],
  2418. [ '20', '21', '22' ]
  2419. ] ) );
  2420. } );
  2421. it( 'should move to the cell below the selection', () => {
  2422. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2423. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2424. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2425. assertEqualMarkup( getModelData( model ), modelTable( [
  2426. [ '00', '01', '02' ],
  2427. [ '10', '11', '12' ],
  2428. [ '20', '[]21', '22' ]
  2429. ] ) );
  2430. } );
  2431. } );
  2432. } );
  2433. } );
  2434. } );