tablekeyboard.js 116 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151
  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 not prevent default browser behavior for shrinking selection (up arrow)', () => {
  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.notCalled( upArrowDomEvtDataStub.preventDefault );
  1937. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  1938. } );
  1939. it( 'should expand not collapsed selection to the beginning of the cell content from the selection anchor', () => {
  1940. setModelData( model, modelTable( [
  1941. [ '00', '01', '02' ],
  1942. [ '10', 'word [word]' + text, '12' ],
  1943. [ '20', '21', '22' ]
  1944. ] ), { lastRangeBackward: true } );
  1945. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  1946. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  1947. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  1948. assertEqualMarkup( getModelData( model ), modelTable( [
  1949. [ '00', '01', '02' ],
  1950. [ '10', '[word word]' + text, '12' ],
  1951. [ '20', '21', '22' ]
  1952. ] ) );
  1953. } );
  1954. it( 'should expand collapsed selection to the end of the cell content', () => {
  1955. setModelData( model, modelTable( [
  1956. [ '00', '01', '02' ],
  1957. [ '10', text + 'word[] word', '12' ],
  1958. [ '20', '21', '22' ]
  1959. ] ) );
  1960. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1961. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1962. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1963. assertEqualMarkup( getModelData( model ), modelTable( [
  1964. [ '00', '01', '02' ],
  1965. [ '10', text + 'word[ word]', '12' ],
  1966. [ '20', '21', '22' ]
  1967. ] ) );
  1968. } );
  1969. it( 'should not prevent default browser behavior for shrinking selection (down arrow)', () => {
  1970. setModelData( model, modelTable( [
  1971. [ '00', '01', '02' ],
  1972. [ '10', text + '[word] word', '12' ],
  1973. [ '20', '21', '22' ]
  1974. ] ), { lastRangeBackward: true } );
  1975. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1976. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  1977. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  1978. } );
  1979. it( 'should expand not collapsed selection to the end of the cell content from the selection anchor', () => {
  1980. setModelData( model, modelTable( [
  1981. [ '00', '01', '02' ],
  1982. [ '10', text + '[word] word', '12' ],
  1983. [ '20', '21', '22' ]
  1984. ] ) );
  1985. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  1986. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  1987. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  1988. assertEqualMarkup( getModelData( model ), modelTable( [
  1989. [ '00', '01', '02' ],
  1990. [ '10', text + '[word word]', '12' ],
  1991. [ '20', '21', '22' ]
  1992. ] ) );
  1993. } );
  1994. } );
  1995. } );
  1996. if ( !env.isGecko ) {
  1997. // These tests fails on Travis. They work correctly when started on local machine.
  1998. // Issue is probably related to text rendering and wrapping.
  1999. describe( 'with selection in the wrap area', () => {
  2000. const text = new Array( 10 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  2001. it( 'should move the caret to end if the caret is after the last space in the line next to the last one', () => {
  2002. // This is also first position in the last line.
  2003. setModelData( model, modelTable( [
  2004. [ '00', '01', '02' ],
  2005. [ '10', text + ' []word word word', '12' ],
  2006. [ '20', '21', '22' ]
  2007. ] ) );
  2008. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2009. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2010. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2011. assertEqualMarkup( getModelData( model ), modelTable( [
  2012. [ '00', '01', '02' ],
  2013. [ '10', text + ' word word word[]', '12' ],
  2014. [ '20', '21', '22' ]
  2015. ] ) );
  2016. } );
  2017. it( 'should move the caret to end if ther caret is at the last space in the line next to last one', () => {
  2018. setModelData( model, modelTable( [
  2019. [ '00', '01', '02' ],
  2020. [ '10', text + '[] word word word', '12' ],
  2021. [ '20', '21', '22' ]
  2022. ] ) );
  2023. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2024. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2025. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2026. assertEqualMarkup( getModelData( model ), modelTable( [
  2027. [ '00', '01', '02' ],
  2028. [ '10', text + ' word word word[]', '12' ],
  2029. [ '20', '21', '22' ]
  2030. ] ) );
  2031. } );
  2032. it( 'should not move the caret if it\'s just before the last space in the line next to last one', () => {
  2033. setModelData( model, modelTable( [
  2034. [ '00', '01', '02' ],
  2035. [ '10', text.substring( 0, text.length - 1 ) + '[]d word word word', '12' ],
  2036. [ '20', '21', '22' ]
  2037. ] ) );
  2038. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2039. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  2040. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  2041. } );
  2042. describe( 'when shift key is pressed', () => {
  2043. beforeEach( () => {
  2044. upArrowDomEvtDataStub.shiftKey = true;
  2045. downArrowDomEvtDataStub.shiftKey = true;
  2046. } );
  2047. it( 'should expand collapsed selection to the end of the cell content', () => {
  2048. setModelData( model, modelTable( [
  2049. [ '00', '01', '02' ],
  2050. [ '10', text + '[] word word word', '12' ],
  2051. [ '20', '21', '22' ]
  2052. ] ) );
  2053. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2054. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2055. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2056. assertEqualMarkup( getModelData( model ), modelTable( [
  2057. [ '00', '01', '02' ],
  2058. [ '10', text + '[ word word word]', '12' ],
  2059. [ '20', '21', '22' ]
  2060. ] ) );
  2061. } );
  2062. it( 'should expand not collapsed selection to the end of the cell content from the selection anchor', () => {
  2063. setModelData( model, modelTable( [
  2064. [ '00', '01', '02' ],
  2065. [ '10', text + '[ word] word word', '12' ],
  2066. [ '20', '21', '22' ]
  2067. ] ) );
  2068. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2069. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2070. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2071. assertEqualMarkup( getModelData( model ), modelTable( [
  2072. [ '00', '01', '02' ],
  2073. [ '10', text + '[ word word word]', '12' ],
  2074. [ '20', '21', '22' ]
  2075. ] ) );
  2076. } );
  2077. } );
  2078. } );
  2079. }
  2080. describe( 'with multiple paragraphs of text', () => {
  2081. const text = new Array( 100 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  2082. it( 'should not navigate if caret is in the middle of a line of text', () => {
  2083. setModelData( model, modelTable( [
  2084. [ '00', '01', '02' ],
  2085. [ '10', `<paragraph>${ text }[]${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2086. [ '20', '21', '22' ]
  2087. ] ) );
  2088. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2089. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  2090. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  2091. } );
  2092. it( 'should move the caret to the beginning of a cell content if the caret is in the first line of text', () => {
  2093. setModelData( model, modelTable( [
  2094. [ '00', '01', '02' ],
  2095. [ '10', `<paragraph>word[]${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2096. [ '20', '21', '22' ]
  2097. ] ) );
  2098. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2099. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2100. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2101. assertEqualMarkup( getModelData( model ), modelTable( [
  2102. [ '00', '01', '02' ],
  2103. [ '10', `<paragraph>[]word${ text }</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2104. [ '20', '21', '22' ]
  2105. ] ) );
  2106. } );
  2107. it( 'should not move the caret to the end of a cell content if the caret is not in the last line of text', () => {
  2108. setModelData( model, modelTable( [
  2109. [ '00', '01', '02' ],
  2110. [ '10', `<paragraph>${ text }word []word</paragraph><paragraph>foobar</paragraph>`, '12' ],
  2111. [ '20', '21', '22' ]
  2112. ] ) );
  2113. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2114. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  2115. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  2116. } );
  2117. it( 'should move the caret to end of a cell content if the caret is in the last line of text', () => {
  2118. setModelData( model, modelTable( [
  2119. [ '00', '01', '02' ],
  2120. [ '10', `<paragraph>foobar</paragraph><paragraph>${ text }word []word</paragraph>`, '12' ],
  2121. [ '20', '21', '22' ]
  2122. ] ) );
  2123. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2124. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2125. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2126. assertEqualMarkup( getModelData( model ), modelTable( [
  2127. [ '00', '01', '02' ],
  2128. [ '10', `<paragraph>foobar</paragraph><paragraph>${ text }word word[]</paragraph>`, '12' ],
  2129. [ '20', '21', '22' ]
  2130. ] ) );
  2131. } );
  2132. describe( 'when shift key is pressed', () => {
  2133. beforeEach( () => {
  2134. upArrowDomEvtDataStub.shiftKey = true;
  2135. downArrowDomEvtDataStub.shiftKey = true;
  2136. } );
  2137. it( 'should expand selection to the beginning of the cell content', () => {
  2138. setModelData( model, modelTable( [
  2139. [ '00', '01', '02' ],
  2140. [ '10', `<paragraph>word[] ${ text }</paragraph><paragraph>${ text }</paragraph>`, '12' ],
  2141. [ '20', '21', '22' ]
  2142. ] ) );
  2143. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2144. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2145. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2146. assertEqualMarkup( getModelData( model ), modelTable( [
  2147. [ '00', '01', '02' ],
  2148. [ '10', `<paragraph>[word] ${ text }</paragraph><paragraph>${ text }</paragraph>`, '12' ],
  2149. [ '20', '21', '22' ]
  2150. ] ) );
  2151. } );
  2152. it( 'should expand selection to the end of the cell content', () => {
  2153. setModelData( model, modelTable( [
  2154. [ '00', '01', '02' ],
  2155. [ '10', `<paragraph>${ text }</paragraph><paragraph>${ text } []word</paragraph>`, '12' ],
  2156. [ '20', '21', '22' ]
  2157. ] ) );
  2158. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2159. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2160. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2161. assertEqualMarkup( getModelData( model ), modelTable( [
  2162. [ '00', '01', '02' ],
  2163. [ '10', `<paragraph>${ text }</paragraph><paragraph>${ text } [word]</paragraph>`, '12' ],
  2164. [ '20', '21', '22' ]
  2165. ] ) );
  2166. } );
  2167. } );
  2168. } );
  2169. describe( 'with horizontal line widget', () => {
  2170. const text = new Array( 100 ).fill( 0 ).map( () => 'word' ).join( ' ' );
  2171. it( 'should not navigate if the caret is in the middle line of text', () => {
  2172. setModelData( model, modelTable( [
  2173. [ '00', '01', '02' ],
  2174. [ '10', `<horizontalLine></horizontalLine><paragraph>${ text }[]${ text }</paragraph>`, '12' ],
  2175. [ '20', '21', '22' ]
  2176. ] ) );
  2177. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2178. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  2179. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  2180. } );
  2181. it( 'should move the caret to the beginning of cell content if the caret is in the first line of text', () => {
  2182. setModelData( model, modelTable( [
  2183. [ '00', '01', '02' ],
  2184. [ '10', `<horizontalLine></horizontalLine><paragraph>word[] ${ text }</paragraph>`, '12' ],
  2185. [ '20', '21', '22' ]
  2186. ] ) );
  2187. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2188. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2189. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2190. assertEqualMarkup( getModelData( model ), modelTable( [
  2191. [ '00', '01', '02' ],
  2192. [ '10', `<horizontalLine></horizontalLine><paragraph>[]word ${ text }</paragraph>`, '12' ],
  2193. [ '20', '21', '22' ]
  2194. ] ) );
  2195. } );
  2196. it( 'should move the caret to the end of cell content if the caret is in the last line of text', () => {
  2197. setModelData( model, modelTable( [
  2198. [ '00', '01', '02' ],
  2199. [ '10', `<paragraph>${ text } word []word</paragraph><horizontalLine></horizontalLine>`, '12' ],
  2200. [ '20', '21', '22' ]
  2201. ] ) );
  2202. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2203. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2204. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2205. assertEqualMarkup( getModelData( model ), modelTable( [
  2206. [ '00', '01', '02' ],
  2207. [ '10', `<paragraph>${ text } word word[]</paragraph><horizontalLine></horizontalLine>`, '12' ],
  2208. [ '20', '21', '22' ]
  2209. ] ) );
  2210. } );
  2211. it( 'should not move the caret to the end of cell content if widget is selected in middle of a cell content', () => {
  2212. const paragraph = `<paragraph>${ text }</paragraph>`;
  2213. const hr = '<horizontalLine></horizontalLine>';
  2214. setModelData( model, modelTable( [
  2215. [ '00', '01', '02' ],
  2216. [ '10', `${ paragraph }[${ hr }]${ paragraph }${ hr }`, '12' ],
  2217. [ '20', '21', '22' ]
  2218. ] ) );
  2219. // Note: Two keydowns are necessary because the first one is handled by the WidgetTypeAround plugin
  2220. // to activate the "fake caret".
  2221. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2222. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2223. assertEqualMarkup( getModelData( model ), modelTable( [
  2224. [ '00', '01', '02' ],
  2225. [ '10', `${ paragraph }${ hr }<paragraph>[]${ text }</paragraph>${ hr }`, '12' ],
  2226. [ '20', '21', '22' ]
  2227. ] ) );
  2228. } );
  2229. it( 'should not move the caret to the end of cell content if widget is next to the selection', () => {
  2230. const paragraph = `<paragraph>${ text }</paragraph>`;
  2231. const hr = '<horizontalLine></horizontalLine>';
  2232. setModelData( model, modelTable( [
  2233. [ '00', '01', '02' ],
  2234. [ '10', `${ paragraph }[]${ hr }`, '12' ],
  2235. [ '20', '21', '22' ]
  2236. ] ) );
  2237. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2238. assertEqualMarkup( getModelData( model ), modelTable( [
  2239. [ '00', '01', '02' ],
  2240. [ '10', `${ paragraph }[${ hr }]`, '12' ],
  2241. [ '20', '21', '22' ]
  2242. ] ) );
  2243. } );
  2244. describe( 'when shift key is pressed', () => {
  2245. beforeEach( () => {
  2246. upArrowDomEvtDataStub.shiftKey = true;
  2247. downArrowDomEvtDataStub.shiftKey = true;
  2248. } );
  2249. it( 'should expand selection to the beginning of the cell content', () => {
  2250. setModelData( model, modelTable( [
  2251. [ '00', '01', '02' ],
  2252. [ '10', '<horizontalLine></horizontalLine><paragraph>foo[]bar</paragraph>', '12' ],
  2253. [ '20', '21', '22' ]
  2254. ] ) );
  2255. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2256. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2257. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2258. assertEqualMarkup( getModelData( model ), modelTable( [
  2259. [ '00', '01', '02' ],
  2260. [ '10', '<horizontalLine></horizontalLine><paragraph>[foo]bar</paragraph>', '12' ],
  2261. [ '20', '21', '22' ]
  2262. ] ) );
  2263. } );
  2264. it( 'should expand selection to the end of the cell content', () => {
  2265. setModelData( model, modelTable( [
  2266. [ '00', '01', '02' ],
  2267. [ '10', '<paragraph>foo[]bar</paragraph><horizontalLine></horizontalLine>', '12' ],
  2268. [ '20', '21', '22' ]
  2269. ] ) );
  2270. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2271. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2272. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2273. assertEqualMarkup( getModelData( model ), modelTable( [
  2274. [ '00', '01', '02' ],
  2275. [ '10', '<paragraph>foo[bar]</paragraph><horizontalLine></horizontalLine>', '12' ],
  2276. [ '20', '21', '22' ]
  2277. ] ) );
  2278. } );
  2279. } );
  2280. } );
  2281. describe( 'contains image widget with caption and selection inside the caption', () => {
  2282. it( 'should not navigate to the cell on the left', () => {
  2283. setModelData( model, modelTable( [
  2284. [ '00', '01', '02' ],
  2285. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  2286. [ '20', '21', '22' ]
  2287. ] ) );
  2288. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  2289. sinon.assert.notCalled( leftArrowDomEvtDataStub.preventDefault );
  2290. sinon.assert.notCalled( leftArrowDomEvtDataStub.stopPropagation );
  2291. } );
  2292. it( 'should not navigate to the cell on the right', () => {
  2293. setModelData( model, modelTable( [
  2294. [ '00', '01', '02' ],
  2295. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image><paragraph>foo</paragraph>`, '12' ],
  2296. [ '20', '21', '22' ]
  2297. ] ) );
  2298. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  2299. sinon.assert.notCalled( rightArrowDomEvtDataStub.preventDefault );
  2300. sinon.assert.notCalled( rightArrowDomEvtDataStub.stopPropagation );
  2301. } );
  2302. it( 'should not navigate to the cell above (only to closest limit boundary)', () => {
  2303. setModelData( model, modelTable( [
  2304. [ '00', '01', '02' ],
  2305. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>1[]1</caption></image>`, '12' ],
  2306. [ '20', '21', '22' ]
  2307. ] ) );
  2308. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2309. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2310. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2311. assertEqualMarkup( getModelData( model ), modelTable( [
  2312. [ '00', '01', '02' ],
  2313. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  2314. [ '20', '21', '22' ]
  2315. ] ) );
  2316. } );
  2317. it( 'should not navigate to the cell above (only to paragraph above)', () => {
  2318. setModelData( model, modelTable( [
  2319. [ '00', '01', '02' ],
  2320. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>[]11</caption></image>`, '12' ],
  2321. [ '20', '21', '22' ]
  2322. ] ) );
  2323. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2324. sinon.assert.notCalled( upArrowDomEvtDataStub.preventDefault );
  2325. sinon.assert.notCalled( upArrowDomEvtDataStub.stopPropagation );
  2326. } );
  2327. it( 'should not navigate to the cell above but should put caret at first position of the image caption', () => {
  2328. setModelData( model, modelTable( [
  2329. [ '00', '01', '02' ],
  2330. [ '10', `<image src="${ imageUrl }"><caption>1[]1</caption></image><paragraph>foo</paragraph>`, '12' ],
  2331. [ '20', '21', '22' ]
  2332. ] ) );
  2333. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2334. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2335. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2336. assertEqualMarkup( getModelData( model ), modelTable( [
  2337. [ '00', '01', '02' ],
  2338. [ '10', `<image src="${ imageUrl }"><caption>[]11</caption></image><paragraph>foo</paragraph>`, '12' ],
  2339. [ '20', '21', '22' ]
  2340. ] ) );
  2341. } );
  2342. it( 'should not navigate to the cell below when inside the image caption', () => {
  2343. setModelData( model, modelTable( [
  2344. [ '00', '01', '02' ],
  2345. [ '10', `<image src="${ imageUrl }"><caption>1[]1</caption></image><paragraph>foo</paragraph>`, '12' ],
  2346. [ '20', '21', '22' ]
  2347. ] ) );
  2348. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2349. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2350. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2351. assertEqualMarkup( getModelData( model ), modelTable( [
  2352. [ '00', '01', '02' ],
  2353. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image><paragraph>foo</paragraph>`, '12' ],
  2354. [ '20', '21', '22' ]
  2355. ] ) );
  2356. } );
  2357. it( 'should not navigate to the cell below when followed by a paragraph', () => {
  2358. setModelData( model, modelTable( [
  2359. [ '00', '01', '02' ],
  2360. [ '10', `<image src="${ imageUrl }"><caption>11[]</caption></image><paragraph>foo</paragraph>`, '12' ],
  2361. [ '20', '21', '22' ]
  2362. ] ) );
  2363. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2364. sinon.assert.notCalled( downArrowDomEvtDataStub.preventDefault );
  2365. sinon.assert.notCalled( downArrowDomEvtDataStub.stopPropagation );
  2366. } );
  2367. it( 'should navigate to the cell below if the caret on last position in the image caption', () => {
  2368. setModelData( model, modelTable( [
  2369. [ '00', '01', '02' ],
  2370. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>11[]</caption></image>`, '12' ],
  2371. [ '20', '21', '22' ]
  2372. ] ) );
  2373. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2374. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2375. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2376. assertEqualMarkup( getModelData( model ), modelTable( [
  2377. [ '00', '01', '02' ],
  2378. [ '10', `<paragraph>foo</paragraph><image src="${ imageUrl }"><caption>11</caption></image>`, '12' ],
  2379. [ '20', '[]21', '22' ]
  2380. ] ) );
  2381. } );
  2382. it( 'should not navigate to the cell above but should select the image widget without caption', () => {
  2383. setModelData( model, modelTable( [
  2384. [ '00', '01', '02' ],
  2385. [ '10', `<image src="${ imageUrl }"><caption></caption></image><paragraph>[]foo</paragraph>`, '12' ],
  2386. [ '20', '21', '22' ]
  2387. ] ) );
  2388. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2389. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2390. assertEqualMarkup( getModelData( model ), modelTable( [
  2391. [ '00', '01', '02' ],
  2392. [ '10', `[<image src="${ imageUrl }"><caption></caption></image>]<paragraph>foo</paragraph>`, '12' ],
  2393. [ '20', '21', '22' ]
  2394. ] ) );
  2395. } );
  2396. it( 'should not navigate to the cell below but should select the image widget without caption', () => {
  2397. setModelData( model, modelTable( [
  2398. [ '00', '01', '02' ],
  2399. [ '10', `<paragraph>foo[]</paragraph><image src="${ imageUrl }"><caption></caption></image>`, '12' ],
  2400. [ '20', '21', '22' ]
  2401. ] ) );
  2402. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2403. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2404. assertEqualMarkup( getModelData( model ), modelTable( [
  2405. [ '00', '01', '02' ],
  2406. [ '10', `<paragraph>foo</paragraph>[<image src="${ imageUrl }"><caption></caption></image>]`, '12' ],
  2407. [ '20', '21', '22' ]
  2408. ] ) );
  2409. } );
  2410. } );
  2411. } );
  2412. } );
  2413. describe( 'for right-to-left content language', () => {
  2414. beforeEach( () => {
  2415. return VirtualTestEditor
  2416. .create( {
  2417. plugins: [ TableEditing, TableKeyboard, TableSelection, Paragraph, ImageEditing, MediaEmbedEditing ],
  2418. language: 'ar'
  2419. } )
  2420. .then( newEditor => {
  2421. editor = newEditor;
  2422. model = editor.model;
  2423. modelRoot = model.document.getRoot();
  2424. tableSelection = editor.plugins.get( TableSelection );
  2425. } );
  2426. } );
  2427. describe( 'with the table cell selected from outside', () => {
  2428. beforeEach( () => {
  2429. setModelData( model, modelTable( [
  2430. [ '00', '01', '02' ],
  2431. [ '10', '11', '12' ],
  2432. [ '20', '21', '22' ]
  2433. ] ) );
  2434. tableSelection.setCellSelection(
  2435. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  2436. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  2437. );
  2438. } );
  2439. it( 'should move to the cell on the right (visually flipped by the browser)', () => {
  2440. editor.editing.view.document.fire( 'keydown', leftArrowDomEvtDataStub );
  2441. sinon.assert.calledOnce( leftArrowDomEvtDataStub.preventDefault );
  2442. sinon.assert.calledOnce( leftArrowDomEvtDataStub.stopPropagation );
  2443. assertEqualMarkup( getModelData( model ), modelTable( [
  2444. [ '00', '01', '02' ],
  2445. [ '10', '11', '[]12' ],
  2446. [ '20', '21', '22' ]
  2447. ] ) );
  2448. } );
  2449. it( 'should move to the cell on the left (visually flipped by the browser)', () => {
  2450. editor.editing.view.document.fire( 'keydown', rightArrowDomEvtDataStub );
  2451. sinon.assert.calledOnce( rightArrowDomEvtDataStub.preventDefault );
  2452. sinon.assert.calledOnce( rightArrowDomEvtDataStub.stopPropagation );
  2453. assertEqualMarkup( getModelData( model ), modelTable( [
  2454. [ '00', '01', '02' ],
  2455. [ '10[]', '11', '12' ],
  2456. [ '20', '21', '22' ]
  2457. ] ) );
  2458. } );
  2459. it( 'should move to the cell above the selection', () => {
  2460. editor.editing.view.document.fire( 'keydown', upArrowDomEvtDataStub );
  2461. sinon.assert.calledOnce( upArrowDomEvtDataStub.preventDefault );
  2462. sinon.assert.calledOnce( upArrowDomEvtDataStub.stopPropagation );
  2463. assertEqualMarkup( getModelData( model ), modelTable( [
  2464. [ '00', '01[]', '02' ],
  2465. [ '10', '11', '12' ],
  2466. [ '20', '21', '22' ]
  2467. ] ) );
  2468. } );
  2469. it( 'should move to the cell below the selection', () => {
  2470. editor.editing.view.document.fire( 'keydown', downArrowDomEvtDataStub );
  2471. sinon.assert.calledOnce( downArrowDomEvtDataStub.preventDefault );
  2472. sinon.assert.calledOnce( downArrowDomEvtDataStub.stopPropagation );
  2473. assertEqualMarkup( getModelData( model ), modelTable( [
  2474. [ '00', '01', '02' ],
  2475. [ '10', '11', '12' ],
  2476. [ '20', '[]21', '22' ]
  2477. ] ) );
  2478. } );
  2479. } );
  2480. } );
  2481. } );
  2482. } );