selection-post-fixer.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  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 Model from '../../../src/model/model';
  6. import { injectSelectionPostFixer } from '../../../src/model/utils/selection-post-fixer';
  7. import { getData as getModelData, setData as setModelData } from '../../../src/dev-utils/model';
  8. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  9. describe( 'Selection post-fixer', () => {
  10. describe( 'injectSelectionPostFixer()', () => {
  11. it( 'is a function', () => {
  12. expect( injectSelectionPostFixer ).to.be.a( 'function' );
  13. } );
  14. } );
  15. describe( 'injected behavior', () => {
  16. let model, modelRoot;
  17. beforeEach( () => {
  18. model = new Model();
  19. modelRoot = model.document.createRoot();
  20. model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  21. model.schema.register( 'table', {
  22. allowWhere: '$block',
  23. allowAttributes: [ 'headingRows', 'headingColumns' ],
  24. isLimit: true,
  25. isObject: true
  26. } );
  27. model.schema.register( 'tableRow', {
  28. allowIn: 'table',
  29. isLimit: true
  30. } );
  31. model.schema.register( 'tableCell', {
  32. allowIn: 'tableRow',
  33. allowAttributes: [ 'colspan', 'rowspan' ],
  34. isObject: true
  35. } );
  36. model.schema.extend( '$block', { allowIn: 'tableCell' } );
  37. model.schema.register( 'image', {
  38. isObject: true,
  39. isBlock: true,
  40. allowWhere: '$block'
  41. } );
  42. model.schema.extend( '$block', { allowIn: 'tableCell' } );
  43. model.schema.register( 'caption', {
  44. allowIn: 'image',
  45. allowContentOf: '$block',
  46. isLimit: true
  47. } );
  48. model.schema.register( 'inlineWidget', {
  49. isObject: true,
  50. allowIn: [ '$block', '$clipboardHolder' ]
  51. } );
  52. model.schema.register( 'figure', {
  53. allowIn: '$root',
  54. allowAttributes: [ 'name', 'title' ]
  55. } );
  56. } );
  57. it( 'should not crash if there is no correct position for model selection', () => {
  58. setModelData( model, '' );
  59. expect( getModelData( model ) ).to.equal( '[]' );
  60. } );
  61. it( 'should react to structure changes', () => {
  62. setModelData( model, '<paragraph>[]foo</paragraph><image></image>' );
  63. model.change( writer => {
  64. writer.remove( modelRoot.getChild( 0 ) );
  65. } );
  66. expect( getModelData( model ) ).to.equal( '[<image></image>]' );
  67. } );
  68. it( 'should react to selection changes', () => {
  69. setModelData( model, '<paragraph>[]foo</paragraph><image></image>' );
  70. // <paragraph>foo</paragraph>[]<image></image>
  71. model.change( writer => {
  72. writer.setSelection(
  73. writer.createRange( writer.createPositionAt( modelRoot, 1 ), writer.createPositionAt( modelRoot, 1 ) )
  74. );
  75. } );
  76. expect( getModelData( model ) ).to.equal( '<paragraph>foo[]</paragraph><image></image>' );
  77. } );
  78. describe( 'selection - table scenarios', () => {
  79. beforeEach( () => {
  80. setModelData( model,
  81. '<paragraph>[]foo</paragraph>' +
  82. '<table>' +
  83. '<tableRow>' +
  84. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  85. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  86. '</tableRow>' +
  87. '</table>' +
  88. '<paragraph>bar</paragraph>'
  89. );
  90. } );
  91. it( 'should fix #1 (range start outside table, end on table cell)', () => {
  92. // <paragraph>f[oo</paragraph><table><tableRow><tableCell></tableCell>]<tableCell>...
  93. model.change( writer => {
  94. writer.setSelection( writer.createRange(
  95. writer.createPositionAt( modelRoot.getChild( 0 ), 1 ),
  96. writer.createPositionAt( modelRoot.getChild( 1 ).getChild( 0 ), 1 )
  97. ) );
  98. } );
  99. expect( getModelData( model ) ).to.equal(
  100. '<paragraph>f[oo</paragraph>' +
  101. '<table>' +
  102. '<tableRow>' +
  103. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  104. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  105. '</tableRow>' +
  106. '</table>]' +
  107. '<paragraph>bar</paragraph>'
  108. );
  109. } );
  110. it( 'should fix #2 (range start on table cell, end outside table)', () => {
  111. // ...<table><tableRow><tableCell></tableCell>[<tableCell></tableCell></tableRow></table><paragraph>b]ar</paragraph>
  112. model.change( writer => {
  113. writer.setSelection( writer.createRange(
  114. writer.createPositionAt( modelRoot.getChild( 1 ).getChild( 0 ), 1 ),
  115. writer.createPositionAt( modelRoot.getChild( 2 ), 1 )
  116. ) );
  117. } );
  118. expect( getModelData( model ) ).to.equal(
  119. '<paragraph>foo</paragraph>' +
  120. '[<table>' +
  121. '<tableRow>' +
  122. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  123. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  124. '</tableRow>' +
  125. '</table>' +
  126. '<paragraph>b]ar</paragraph>'
  127. );
  128. } );
  129. it( 'should fix #3', () => {
  130. // <paragraph>f[oo</paragraph><table>]<tableRow>...
  131. model.change( writer => {
  132. writer.setSelection( writer.createRange(
  133. writer.createPositionAt( modelRoot.getChild( 0 ), 1 ),
  134. writer.createPositionAt( modelRoot.getChild( 1 ), 0 )
  135. ) );
  136. } );
  137. expect( getModelData( model ) ).to.equal(
  138. '<paragraph>f[oo</paragraph>' +
  139. '<table>' +
  140. '<tableRow>' +
  141. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  142. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  143. '</tableRow>' +
  144. '</table>]' +
  145. '<paragraph>bar</paragraph>'
  146. );
  147. } );
  148. it( 'should fix #4', () => {
  149. // <paragraph>foo</paragraph><table><tableRow><tableCell>a[aa</tableCell><tableCell>b]bb</tableCell>
  150. model.change( writer => {
  151. writer.setSelection( writer.createRange(
  152. writer.createPositionAt( modelRoot.getNodeByPath( [ 1, 0, 0, 0 ] ), 1 ),
  153. writer.createPositionAt( modelRoot.getNodeByPath( [ 1, 0, 1, 0 ] ), 2 )
  154. ) );
  155. } );
  156. expect( getModelData( model ) ).to.equal(
  157. '<paragraph>foo</paragraph>' +
  158. '[<table>' +
  159. '<tableRow>' +
  160. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  161. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  162. '</tableRow>' +
  163. '</table>]' +
  164. '<paragraph>bar</paragraph>'
  165. );
  166. } );
  167. it( 'should fix #5 (collapsed selection between tables)', () => {
  168. setModelData( model,
  169. '<paragraph>foo</paragraph>' +
  170. '<table>' +
  171. '<tableRow>' +
  172. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  173. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  174. '</tableRow>' +
  175. '</table>' +
  176. '[]' +
  177. '<table>' +
  178. '<tableRow>' +
  179. '<tableCell><paragraph>xxx</paragraph></tableCell>' +
  180. '<tableCell><paragraph>yyy</paragraph></tableCell>' +
  181. '</tableRow>' +
  182. '</table>' +
  183. '<paragraph>baz</paragraph>'
  184. );
  185. assertEqualMarkup( getModelData( model ),
  186. '<paragraph>foo</paragraph>' +
  187. '[<table>' +
  188. '<tableRow>' +
  189. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  190. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  191. '</tableRow>' +
  192. '</table>]' +
  193. '<table>' +
  194. '<tableRow>' +
  195. '<tableCell><paragraph>xxx</paragraph></tableCell>' +
  196. '<tableCell><paragraph>yyy</paragraph></tableCell>' +
  197. '</tableRow>' +
  198. '</table>' +
  199. '<paragraph>baz</paragraph>'
  200. );
  201. } );
  202. // There's a chance that this and the following test will not be up to date with
  203. // how the table feature is really implemented once we'll introduce row/cells/columns selection
  204. // in which case all these elements will need to be marked as objects.
  205. it( 'should fix #6 (element selection of not an object)', () => {
  206. setModelData( model,
  207. '<paragraph>foo</paragraph>' +
  208. '<table>' +
  209. '[<tableRow>' +
  210. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  211. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  212. '</tableRow>]' +
  213. '</table>' +
  214. '<paragraph>baz</paragraph>'
  215. );
  216. expect( getModelData( model ) ).to.equal(
  217. '<paragraph>foo</paragraph>' +
  218. '[<table>' +
  219. '<tableRow>' +
  220. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  221. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  222. '</tableRow>' +
  223. '</table>]' +
  224. '<paragraph>baz</paragraph>'
  225. );
  226. } );
  227. it( 'should fix #7 (element selection of non-objects)', () => {
  228. setModelData( model,
  229. '<paragraph>foo</paragraph>' +
  230. '<table>' +
  231. '[<tableRow>' +
  232. '<tableCell><paragraph>1</paragraph></tableCell>' +
  233. '<tableCell><paragraph>2</paragraph></tableCell>' +
  234. '</tableRow>' +
  235. '<tableRow>' +
  236. '<tableCell><paragraph>3</paragraph></tableCell>' +
  237. '<tableCell><paragraph>4</paragraph></tableCell>]' +
  238. '</tableRow>' +
  239. '<tableRow>' +
  240. '<tableCell><paragraph>5</paragraph></tableCell>' +
  241. '<tableCell><paragraph>6</paragraph></tableCell>' +
  242. '</tableRow>' +
  243. '</table>' +
  244. '<paragraph>baz</paragraph>'
  245. );
  246. expect( getModelData( model ) ).to.equal(
  247. '<paragraph>foo</paragraph>' +
  248. '[<table>' +
  249. '<tableRow>' +
  250. '<tableCell><paragraph>1</paragraph></tableCell>' +
  251. '<tableCell><paragraph>2</paragraph></tableCell>' +
  252. '</tableRow>' +
  253. '<tableRow>' +
  254. '<tableCell><paragraph>3</paragraph></tableCell>' +
  255. '<tableCell><paragraph>4</paragraph></tableCell>' +
  256. '</tableRow>' +
  257. '<tableRow>' +
  258. '<tableCell><paragraph>5</paragraph></tableCell>' +
  259. '<tableCell><paragraph>6</paragraph></tableCell>' +
  260. '</tableRow>' +
  261. '</table>]' +
  262. '<paragraph>baz</paragraph>'
  263. );
  264. } );
  265. it( 'should fix #8 (cross-limit selection which starts in a non-limit elements)', () => {
  266. model.schema.extend( 'paragraph', { allowIn: 'tableCell' } );
  267. setModelData( model,
  268. '<paragraph>foo</paragraph>' +
  269. '<table>' +
  270. '<tableRow>' +
  271. '<tableCell><paragraph>f[oo</paragraph></tableCell>' +
  272. '<tableCell><paragraph>b]ar</paragraph></tableCell>' +
  273. '</tableRow>' +
  274. '</table>' +
  275. '<paragraph>baz</paragraph>'
  276. );
  277. expect( getModelData( model ) ).to.equal(
  278. '<paragraph>foo</paragraph>' +
  279. '[<table>' +
  280. '<tableRow>' +
  281. '<tableCell><paragraph>foo</paragraph></tableCell>' +
  282. '<tableCell><paragraph>bar</paragraph></tableCell>' +
  283. '</tableRow>' +
  284. '</table>]' +
  285. '<paragraph>baz</paragraph>'
  286. );
  287. } );
  288. it( 'should not fix #1 (selection over paragraphs outside table)', () => {
  289. setModelData( model,
  290. '<paragraph>foo</paragraph>' +
  291. '<table>' +
  292. '<tableRow>' +
  293. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  294. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  295. '</tableRow>' +
  296. '</table>' +
  297. '<paragraph>b[ar</paragraph>' +
  298. '<paragraph>ba]z</paragraph>'
  299. );
  300. expect( getModelData( model ) ).to.equal(
  301. '<paragraph>foo</paragraph>' +
  302. '<table>' +
  303. '<tableRow>' +
  304. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  305. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  306. '</tableRow>' +
  307. '</table>' +
  308. '<paragraph>b[ar</paragraph>' +
  309. '<paragraph>ba]z</paragraph>'
  310. );
  311. } );
  312. it( 'should not fix #2 (selection over image in table)', () => {
  313. setModelData( model,
  314. '<paragraph>foo</paragraph>' +
  315. '<table>' +
  316. '<tableRow>' +
  317. '<tableCell><paragraph>foo</paragraph><image></image></tableCell>' +
  318. '<tableCell><paragraph>[]bbb</paragraph></tableCell>' +
  319. '</tableRow>' +
  320. '</table>'
  321. );
  322. model.change( writer => {
  323. const image = model.document.getRoot().getNodeByPath( [ 1, 0, 0, 1 ] );
  324. writer.setSelection( writer.createRangeOn( image ) );
  325. } );
  326. expect( getModelData( model ) ).to.equal(
  327. '<paragraph>foo</paragraph>' +
  328. '<table>' +
  329. '<tableRow>' +
  330. '<tableCell><paragraph>foo</paragraph>[<image></image>]</tableCell>' +
  331. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  332. '</tableRow>' +
  333. '</table>'
  334. );
  335. } );
  336. it( 'should not fix #3 (selection over paragraph & image in table)', () => {
  337. setModelData( model,
  338. '<paragraph>foo</paragraph>' +
  339. '<table>' +
  340. '<tableRow>' +
  341. '<tableCell><paragraph>foo</paragraph><image></image></tableCell>' +
  342. '<tableCell><paragraph>[]bbb</paragraph></tableCell>' +
  343. '</tableRow>' +
  344. '</table>'
  345. );
  346. model.change( writer => {
  347. const tableCell = model.document.getRoot().getNodeByPath( [ 1, 0, 0 ] );
  348. writer.setSelection( writer.createRangeIn( tableCell ) );
  349. } );
  350. expect( getModelData( model ) ).to.equal(
  351. '<paragraph>foo</paragraph>' +
  352. '<table>' +
  353. '<tableRow>' +
  354. '<tableCell><paragraph>[foo</paragraph><image></image>]</tableCell>' +
  355. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  356. '</tableRow>' +
  357. '</table>'
  358. );
  359. } );
  360. it( 'should not fix #4 (selection over image & paragraph in table)', () => {
  361. setModelData( model,
  362. '<paragraph>foo</paragraph>' +
  363. '<table>' +
  364. '<tableRow>' +
  365. '<tableCell><image></image><paragraph>foo</paragraph></tableCell>' +
  366. '<tableCell><paragraph>[]bbb</paragraph></tableCell>' +
  367. '</tableRow>' +
  368. '</table>'
  369. );
  370. model.change( writer => {
  371. const tableCell = model.document.getRoot().getNodeByPath( [ 1, 0, 0 ] );
  372. writer.setSelection( writer.createRangeIn( tableCell ) );
  373. } );
  374. expect( getModelData( model ) ).to.equal(
  375. '<paragraph>foo</paragraph>' +
  376. '<table>' +
  377. '<tableRow>' +
  378. '<tableCell>[<image></image><paragraph>foo]</paragraph></tableCell>' +
  379. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  380. '</tableRow>' +
  381. '</table>'
  382. );
  383. } );
  384. it( 'should not fix #5 (selection over blockQuote in table)', () => {
  385. model.schema.register( 'blockQuote', {
  386. allowWhere: '$block',
  387. allowContentOf: '$root'
  388. } );
  389. setModelData( model,
  390. '<paragraph>foo</paragraph>' +
  391. '<table>' +
  392. '<tableRow>' +
  393. '<tableCell><blockQuote><paragraph>foo</paragraph></blockQuote></tableCell>' +
  394. '<tableCell><paragraph>[]bbb</paragraph></tableCell>' +
  395. '</tableRow>' +
  396. '</table>'
  397. );
  398. model.change( writer => {
  399. const tableCell = model.document.getRoot().getNodeByPath( [ 1, 0, 0 ] );
  400. writer.setSelection( writer.createRangeIn( tableCell ) );
  401. } );
  402. expect( getModelData( model ) ).to.equal(
  403. '<paragraph>foo</paragraph>' +
  404. '<table>' +
  405. '<tableRow>' +
  406. '<tableCell><blockQuote><paragraph>[foo]</paragraph></blockQuote></tableCell>' +
  407. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  408. '</tableRow>' +
  409. '</table>'
  410. );
  411. } );
  412. it( 'should fix multiple ranges #1', () => {
  413. model.change( writer => {
  414. const ranges = [
  415. writer.createRange(
  416. writer.createPositionFromPath( modelRoot, [ 0, 1 ] ),
  417. writer.createPositionFromPath( modelRoot, [ 1, 0 ] )
  418. ),
  419. writer.createRange(
  420. writer.createPositionFromPath( modelRoot, [ 1, 0, 0, 0 ] ),
  421. writer.createPositionFromPath( modelRoot, [ 1, 1 ] )
  422. )
  423. ];
  424. writer.setSelection( ranges );
  425. } );
  426. expect( getModelData( model ) ).to.equal(
  427. '<paragraph>f[oo</paragraph>' +
  428. '<table>' +
  429. '<tableRow>' +
  430. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  431. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  432. '</tableRow>' +
  433. '</table>]' +
  434. '<paragraph>bar</paragraph>'
  435. );
  436. } );
  437. it( 'should fix multiple ranges #2', () => {
  438. model.change( writer => {
  439. const ranges = [
  440. writer.createRange(
  441. writer.createPositionFromPath( modelRoot, [ 0, 1 ] ),
  442. writer.createPositionFromPath( modelRoot, [ 1, 0 ] )
  443. ),
  444. writer.createRange(
  445. writer.createPositionFromPath( modelRoot, [ 1, 0, 0, 0 ] ),
  446. writer.createPositionFromPath( modelRoot, [ 2, 2 ] )
  447. )
  448. ];
  449. writer.setSelection( ranges );
  450. } );
  451. expect( getModelData( model ) ).to.equal(
  452. '<paragraph>f[oo</paragraph>' +
  453. '<table>' +
  454. '<tableRow>' +
  455. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  456. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  457. '</tableRow>' +
  458. '</table>' +
  459. '<paragraph>ba]r</paragraph>'
  460. );
  461. } );
  462. it( 'should fix multiple ranges #3', () => {
  463. setModelData( model,
  464. '<paragraph>foo</paragraph>' +
  465. '<table>' +
  466. '<tableRow>' +
  467. '<tableCell><paragraph>[aaa</paragraph></tableCell>' +
  468. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  469. '</tableRow>' +
  470. '<tableRow>]' +
  471. '<tableCell><paragraph>[aaa</paragraph></tableCell>' +
  472. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  473. '</tableRow>' +
  474. '<tableRow>]' +
  475. '<tableCell><paragraph>[aaa</paragraph></tableCell>' +
  476. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  477. '</tableRow>' +
  478. '<tableRow>]' +
  479. '<tableCell><paragraph>[aaa</paragraph></tableCell>' +
  480. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  481. '</tableRow>' +
  482. '</table>' +
  483. '<paragraph>b]az</paragraph>'
  484. );
  485. expect( getModelData( model ) ).to.equal(
  486. '<paragraph>foo</paragraph>' +
  487. '[<table>' +
  488. '<tableRow>' +
  489. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  490. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  491. '</tableRow>' +
  492. '<tableRow>' +
  493. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  494. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  495. '</tableRow>' +
  496. '<tableRow>' +
  497. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  498. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  499. '</tableRow>' +
  500. '<tableRow>' +
  501. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  502. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  503. '</tableRow>' +
  504. '</table>' +
  505. '<paragraph>b]az</paragraph>'
  506. );
  507. } );
  508. it( 'should not fix multiple ranges #1 (not overlapping ranges)', () => {
  509. model.change( writer => {
  510. const ranges = [
  511. writer.createRange(
  512. writer.createPositionFromPath( modelRoot, [ 0, 1 ] ),
  513. writer.createPositionFromPath( modelRoot, [ 1, 0 ] )
  514. ),
  515. writer.createRange(
  516. writer.createPositionFromPath( modelRoot, [ 1, 0, 0, 0 ] ),
  517. writer.createPositionFromPath( modelRoot, [ 2, 1 ] )
  518. ),
  519. writer.createRange(
  520. writer.createPositionFromPath( modelRoot, [ 2, 2 ] ),
  521. writer.createPositionFromPath( modelRoot, [ 2, 3 ] )
  522. )
  523. ];
  524. writer.setSelection( ranges );
  525. } );
  526. expect( getModelData( model ) ).to.equal(
  527. '<paragraph>f[oo</paragraph>' +
  528. '<table>' +
  529. '<tableRow>' +
  530. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  531. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  532. '</tableRow>' +
  533. '</table>' +
  534. '<paragraph>b]a[r]</paragraph>'
  535. );
  536. } );
  537. it( 'should not fix multiple ranges on objects (table selection)', () => {
  538. setModelData( model,
  539. '<table>' +
  540. '<tableRow>' +
  541. '[<tableCell><paragraph>a</paragraph></tableCell>]' +
  542. '[<tableCell><paragraph>b</paragraph></tableCell>]' +
  543. '</tableRow>' +
  544. '<tableRow>' +
  545. '[<tableCell><paragraph>c</paragraph></tableCell>]' +
  546. '<tableCell><paragraph>d</paragraph></tableCell>' +
  547. '</tableRow>' +
  548. '</table>'
  549. );
  550. assertEqualMarkup( getModelData( model ),
  551. '<table>' +
  552. '<tableRow>' +
  553. '[<tableCell><paragraph>a</paragraph></tableCell>]' +
  554. '[<tableCell><paragraph>b</paragraph></tableCell>]' +
  555. '</tableRow>' +
  556. '<tableRow>' +
  557. '[<tableCell><paragraph>c</paragraph></tableCell>]' +
  558. '<tableCell><paragraph>d</paragraph></tableCell>' +
  559. '</tableRow>' +
  560. '</table>'
  561. );
  562. } );
  563. it( 'should fix selection on block', () => {
  564. model.schema.extend( '$block', { allowIn: 'tableCell' } );
  565. setModelData( model,
  566. '<table>' +
  567. '<tableRow><tableCell>[<paragraph>aaa</paragraph>]</tableCell></tableRow>' +
  568. '</table>'
  569. );
  570. assertEqualMarkup( getModelData( model ),
  571. '<table>' +
  572. '<tableRow><tableCell><paragraph>[aaa]</paragraph></tableCell></tableRow>' +
  573. '</table>'
  574. );
  575. } );
  576. it( 'should allow multi-range selection on non-continues blocks (column selected)', () => {
  577. setModelData( model,
  578. '<table>' +
  579. '<tableRow>' +
  580. '[<tableCell><paragraph>A1</paragraph></tableCell>]' +
  581. '<tableCell><paragraph>B1</paragraph></tableCell>' +
  582. '</tableRow>' +
  583. '<tableRow>' +
  584. '[<tableCell><paragraph>A2</paragraph></tableCell>]' +
  585. '<tableCell><paragraph>B2</paragraph></tableCell>' +
  586. '</tableRow>' +
  587. '<tableRow>' +
  588. '[<tableCell><paragraph>A3</paragraph></tableCell>]' +
  589. '<tableCell><paragraph>B3</paragraph></tableCell>' +
  590. '</tableRow>' +
  591. '</table>'
  592. );
  593. assertEqualMarkup( getModelData( model ),
  594. '<table>' +
  595. '<tableRow>' +
  596. '[<tableCell><paragraph>A1</paragraph></tableCell>]' +
  597. '<tableCell><paragraph>B1</paragraph></tableCell>' +
  598. '</tableRow>' +
  599. '<tableRow>' +
  600. '[<tableCell><paragraph>A2</paragraph></tableCell>]' +
  601. '<tableCell><paragraph>B2</paragraph></tableCell>' +
  602. '</tableRow>' +
  603. '<tableRow>' +
  604. '[<tableCell><paragraph>A3</paragraph></tableCell>]' +
  605. '<tableCell><paragraph>B3</paragraph></tableCell>' +
  606. '</tableRow>' +
  607. '</table>'
  608. );
  609. } );
  610. it( 'should not fix ranges in multi-range selection (each range set differently - but valid)', () => {
  611. setModelData( model,
  612. '<paragraph>[foo]</paragraph>' +
  613. '<table>' +
  614. '<tableRow>' +
  615. '[<tableCell><paragraph>aaa</paragraph></tableCell>]' +
  616. '<tableCell><paragraph>[bbb]</paragraph></tableCell>' +
  617. '</tableRow>' +
  618. '</table>'
  619. );
  620. assertEqualMarkup( getModelData( model ),
  621. '<paragraph>[foo]</paragraph>' +
  622. '<table>' +
  623. '<tableRow>' +
  624. '[<tableCell><paragraph>aaa</paragraph></tableCell>]' +
  625. '<tableCell><paragraph>[bbb]</paragraph></tableCell>' +
  626. '</tableRow>' +
  627. '</table>'
  628. );
  629. } );
  630. it( 'should fix partially wrong selection (last range is post-fixed on whole table)', () => {
  631. setModelData( model,
  632. '<table>' +
  633. '<tableRow>' +
  634. '[<tableCell><paragraph>aaa</paragraph></tableCell>]' +
  635. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  636. '[<tableCell><paragraph>ccc</paragraph></tableCell>' +
  637. '</tableRow>]' +
  638. '</table>'
  639. );
  640. assertEqualMarkup( getModelData( model ),
  641. '[<table>' +
  642. '<tableRow>' +
  643. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  644. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  645. '<tableCell><paragraph>ccc</paragraph></tableCell>' +
  646. '</tableRow>' +
  647. '</table>]'
  648. );
  649. } );
  650. it( 'should fix partially wrong selection (first range is post-fixed on whole table)', () => {
  651. setModelData( model,
  652. '<table>' +
  653. '[<tableRow>' +
  654. '<tableCell><paragraph>aaa</paragraph></tableCell>]' +
  655. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  656. '[<tableCell><paragraph>ccc</paragraph></tableCell>]' +
  657. '</tableRow>' +
  658. '</table>'
  659. );
  660. assertEqualMarkup( getModelData( model ),
  661. '[<table>' +
  662. '<tableRow>' +
  663. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  664. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  665. '<tableCell><paragraph>ccc</paragraph></tableCell>' +
  666. '</tableRow>' +
  667. '</table>]'
  668. );
  669. } );
  670. } );
  671. describe( 'non-collapsed selection - image scenarios', () => {
  672. beforeEach( () => {
  673. setModelData( model,
  674. '<paragraph>[]foo</paragraph>' +
  675. '<image>' +
  676. '<caption>xxx</caption>' +
  677. '</image>' +
  678. '<paragraph>bar</paragraph>'
  679. );
  680. } );
  681. it( 'should fix #1 (crossing object and limit boundaries)', () => {
  682. model.change( writer => {
  683. // <paragraph>f[oo</paragraph><image><caption>x]xx</caption>...
  684. writer.setSelection( writer.createRange(
  685. writer.createPositionAt( modelRoot.getChild( 0 ), 1 ),
  686. writer.createPositionAt( modelRoot.getChild( 1 ).getChild( 0 ), 1 )
  687. ) );
  688. } );
  689. expect( getModelData( model ) ).to.equal(
  690. '<paragraph>f[oo</paragraph>' +
  691. '<image>' +
  692. '<caption>xxx</caption>' +
  693. '</image>]' +
  694. '<paragraph>bar</paragraph>'
  695. );
  696. } );
  697. it( 'should fix #2 (crossing object boundary)', () => {
  698. model.change( writer => {
  699. // <paragraph>f[oo</paragraph><image>]<caption>xxx</caption>...
  700. writer.setSelection( writer.createRange(
  701. writer.createPositionAt( modelRoot.getChild( 0 ), 1 ),
  702. writer.createPositionAt( modelRoot.getChild( 1 ), 0 )
  703. ) );
  704. } );
  705. expect( getModelData( model ) ).to.equal(
  706. '<paragraph>f[oo</paragraph>' +
  707. '<image>' +
  708. '<caption>xxx</caption>' +
  709. '</image>]' +
  710. '<paragraph>bar</paragraph>'
  711. );
  712. } );
  713. it( 'should fix #3 (crossing object boundary)', () => {
  714. model.change( writer => {
  715. // <paragraph>f[oo</paragraph><image><caption>xxx</caption>]</image>...
  716. writer.setSelection( writer.createRange(
  717. writer.createPositionAt( modelRoot.getChild( 0 ), 1 ),
  718. writer.createPositionAt( modelRoot.getChild( 1 ), 1 )
  719. ) );
  720. } );
  721. expect( getModelData( model ) ).to.equal(
  722. '<paragraph>f[oo</paragraph>' +
  723. '<image>' +
  724. '<caption>xxx</caption>' +
  725. '</image>]' +
  726. '<paragraph>bar</paragraph>'
  727. );
  728. } );
  729. it( 'should fix #4 (element selection of not an object)', () => {
  730. model.change( writer => {
  731. // <paragraph>foo</paragraph><image>[<caption>xxx</caption>]</image>...
  732. writer.setSelection( writer.createRange(
  733. writer.createPositionAt( modelRoot.getChild( 1 ), 0 ),
  734. writer.createPositionAt( modelRoot.getChild( 1 ), 1 )
  735. ) );
  736. } );
  737. expect( getModelData( model ) ).to.equal(
  738. '<paragraph>foo</paragraph>' +
  739. '[<image>' +
  740. '<caption>xxx</caption>' +
  741. '</image>]' +
  742. '<paragraph>bar</paragraph>'
  743. );
  744. } );
  745. it( 'should not fix #1 (element selection of an object)', () => {
  746. model.change( writer => {
  747. // <paragraph>foo</paragraph>[<image><caption>xxx</caption></image>]...
  748. writer.setSelection( writer.createRange(
  749. writer.createPositionAt( modelRoot, 1 ),
  750. writer.createPositionAt( modelRoot, 2 )
  751. ) );
  752. } );
  753. expect( getModelData( model ) ).to.equal(
  754. '<paragraph>foo</paragraph>' +
  755. '[<image>' +
  756. '<caption>xxx</caption>' +
  757. '</image>]' +
  758. '<paragraph>bar</paragraph>'
  759. );
  760. } );
  761. it( 'should not fix #2 (inside a limit)', () => {
  762. model.change( writer => {
  763. const caption = modelRoot.getChild( 1 ).getChild( 0 );
  764. // <paragraph>foo</paragraph><image><caption>[xxx]</caption></image>...
  765. writer.setSelection( writer.createRange(
  766. writer.createPositionAt( caption, 0 ),
  767. writer.createPositionAt( caption, 3 )
  768. ) );
  769. } );
  770. expect( getModelData( model ) ).to.equal(
  771. '<paragraph>foo</paragraph>' +
  772. '<image>' +
  773. '<caption>[xxx]</caption>' +
  774. '</image>' +
  775. '<paragraph>bar</paragraph>'
  776. );
  777. } );
  778. it( 'should not fix #3 (inside a limit - partial text selection)', () => {
  779. model.change( writer => {
  780. const caption = modelRoot.getChild( 1 ).getChild( 0 );
  781. // <paragraph>foo</paragraph><image><caption>[xx]x</caption></image>...
  782. writer.setSelection( writer.createRange(
  783. writer.createPositionAt( caption, 0 ),
  784. writer.createPositionAt( caption, 2 )
  785. ) );
  786. } );
  787. expect( getModelData( model ) ).to.equal(
  788. '<paragraph>foo</paragraph>' +
  789. '<image>' +
  790. '<caption>[xx]x</caption>' +
  791. '</image>' +
  792. '<paragraph>bar</paragraph>'
  793. );
  794. } );
  795. it( 'should not fix #4 (inside a limit - partial text selection)', () => {
  796. model.change( writer => {
  797. const caption = modelRoot.getChild( 1 ).getChild( 0 );
  798. // <paragraph>foo</paragraph><image><caption>x[xx]</caption></image>...
  799. writer.setSelection( writer.createRange(
  800. writer.createPositionAt( caption, 1 ),
  801. writer.createPositionAt( caption, 3 )
  802. ) );
  803. } );
  804. expect( getModelData( model ) ).to.equal(
  805. '<paragraph>foo</paragraph>' +
  806. '<image>' +
  807. '<caption>x[xx]</caption>' +
  808. '</image>' +
  809. '<paragraph>bar</paragraph>'
  810. );
  811. } );
  812. it( 'should not fix #5 (selection in root on non limit element that doesn\'t allow text)', () => {
  813. setModelData( model,
  814. '[<figure></figure>]'
  815. );
  816. expect( getModelData( model ) ).to.equal(
  817. '[<figure></figure>]'
  818. );
  819. } );
  820. } );
  821. describe( 'non-collapsed selection - other scenarios', () => {
  822. it( 'should fix #1 (element selection of not an object)', () => {
  823. setModelData( model,
  824. '<paragraph>aaa</paragraph>' +
  825. '[<paragraph>bbb</paragraph>]' +
  826. '<paragraph>ccc</paragraph>'
  827. );
  828. expect( getModelData( model ) ).to.equal(
  829. '<paragraph>aaa</paragraph>' +
  830. '<paragraph>[bbb]</paragraph>' +
  831. '<paragraph>ccc</paragraph>'
  832. );
  833. } );
  834. it( 'should fix #2 (elements selection of not an object)', () => {
  835. setModelData( model,
  836. '<paragraph>aaa</paragraph>' +
  837. '[<paragraph>bbb</paragraph>' +
  838. '<paragraph>ccc</paragraph>]'
  839. );
  840. expect( getModelData( model ) ).to.equal(
  841. '<paragraph>aaa</paragraph>' +
  842. '<paragraph>[bbb</paragraph>' +
  843. '<paragraph>ccc]</paragraph>'
  844. );
  845. } );
  846. it( 'should fix #3 (partial selection of not an object)', () => {
  847. setModelData( model,
  848. '<paragraph>aaa</paragraph>' +
  849. '[<paragraph>bbb</paragraph>' +
  850. '<paragraph>ccc]</paragraph>'
  851. );
  852. expect( getModelData( model ) ).to.equal(
  853. '<paragraph>aaa</paragraph>' +
  854. '<paragraph>[bbb</paragraph>' +
  855. '<paragraph>ccc]</paragraph>'
  856. );
  857. } );
  858. it( 'should fix #4 (partial selection of not an object)', () => {
  859. setModelData( model,
  860. '<paragraph>aaa</paragraph>' +
  861. '<paragraph>b[bb</paragraph>]' +
  862. '<paragraph>ccc</paragraph>'
  863. );
  864. expect( getModelData( model ) ).to.equal(
  865. '<paragraph>aaa</paragraph>' +
  866. '<paragraph>b[bb]</paragraph>' +
  867. '<paragraph>ccc</paragraph>'
  868. );
  869. } );
  870. it( 'should fix #5 (partial selection of not an object)', () => {
  871. setModelData( model,
  872. '<paragraph>aaa</paragraph>' +
  873. '[<paragraph>bb]b</paragraph>' +
  874. '<paragraph>ccc</paragraph>'
  875. );
  876. expect( getModelData( model ) ).to.equal(
  877. '<paragraph>aaa</paragraph>' +
  878. '<paragraph>[bb]b</paragraph>' +
  879. '<paragraph>ccc</paragraph>'
  880. );
  881. } );
  882. it( 'should fix #6 (selection must not cross a limit element; starts in a root)', () => {
  883. model.schema.register( 'a', { isLimit: true, allowIn: '$root' } );
  884. model.schema.register( 'b', { isLimit: true, allowIn: 'a' } );
  885. model.schema.register( 'c', { allowIn: 'b' } );
  886. model.schema.extend( '$text', { allowIn: 'c' } );
  887. setModelData( model,
  888. '<a><b><c>[</c></b></a>]'
  889. );
  890. expect( getModelData( model ) ).to.equal( '[<a><b><c></c></b></a>]' );
  891. } );
  892. it( 'should fix #7 (selection must not cross a limit element; ends in a root)', () => {
  893. model.schema.register( 'a', { isLimit: true, allowIn: '$root' } );
  894. model.schema.register( 'b', { isLimit: true, allowIn: 'a' } );
  895. model.schema.register( 'c', { allowIn: 'b' } );
  896. model.schema.extend( '$text', { allowIn: 'c' } );
  897. setModelData( model,
  898. '[<a><b><c>]</c></b></a>'
  899. );
  900. expect( getModelData( model ) ).to.equal( '[<a><b><c></c></b></a>]' );
  901. } );
  902. it( 'should fix #8 (selection must not cross a limit element; starts in a non-limit)', () => {
  903. model.schema.register( 'div', { allowIn: '$root' } );
  904. model.schema.register( 'a', { isLimit: true, allowIn: 'div' } );
  905. model.schema.register( 'b', { isLimit: true, allowIn: 'a' } );
  906. model.schema.register( 'c', { allowIn: 'b' } );
  907. model.schema.extend( '$text', { allowIn: 'c' } );
  908. setModelData( model,
  909. '<div>[<a><b><c>]</c></b></a></div>'
  910. );
  911. expect( getModelData( model ) ).to.equal( '<div>[<a><b><c></c></b></a>]</div>' );
  912. } );
  913. it( 'should fix #9 (selection must not cross a limit element; ends in a non-limit)', () => {
  914. model.schema.register( 'div', { allowIn: '$root' } );
  915. model.schema.register( 'a', { isLimit: true, allowIn: 'div' } );
  916. model.schema.register( 'b', { isLimit: true, allowIn: 'a' } );
  917. model.schema.register( 'c', { allowIn: 'b' } );
  918. model.schema.extend( '$text', { allowIn: 'c' } );
  919. setModelData( model,
  920. '<div><a><b><c>[</c></b></a>]</div>'
  921. );
  922. expect( getModelData( model ) ).to.equal( '<div>[<a><b><c></c></b></a>]</div>' );
  923. } );
  924. it( 'should not fix #1 (selection on text node)', () => {
  925. setModelData( model, '<paragraph>foob[a]r</paragraph>', { lastRangeBackward: true } );
  926. expect( getModelData( model ) ).to.equal( '<paragraph>foob[a]r</paragraph>' );
  927. } );
  928. it( 'should not fix #2 (inline widget selected)', () => {
  929. setModelData( model,
  930. '<paragraph>[<inlineWidget></inlineWidget>]</paragraph>'
  931. );
  932. expect( getModelData( model ) ).to.equal(
  933. '<paragraph>[<inlineWidget></inlineWidget>]</paragraph>'
  934. );
  935. } );
  936. it( 'should not fix #3 (text around inline widget)', () => {
  937. setModelData( model,
  938. '<paragraph>fo[o<inlineWidget></inlineWidget>b]ar</paragraph>'
  939. );
  940. expect( getModelData( model ) ).to.equal(
  941. '<paragraph>fo[o<inlineWidget></inlineWidget>b]ar</paragraph>'
  942. );
  943. } );
  944. it( 'should not fix #4 (object in object)', () => {
  945. model.schema.register( 'div', {
  946. allowIn: [ '$root', 'div' ],
  947. isObject: true
  948. } );
  949. setModelData( model, '<div>[<div></div>]</div>' );
  950. model.change( writer => {
  951. const innerDiv = model.document.getRoot().getNodeByPath( [ 0, 0 ] );
  952. writer.setSelection( writer.createRangeOn( innerDiv ) );
  953. } );
  954. expect( getModelData( model ) ).to.equal( '<div>[<div></div>]</div>' );
  955. } );
  956. } );
  957. describe( 'non-collapsed selection - inline widget scenarios', () => {
  958. beforeEach( () => {
  959. model.schema.register( 'placeholder', {
  960. allowWhere: '$text',
  961. isInline: true
  962. } );
  963. } );
  964. it( 'should fix selection that ends in inline element', () => {
  965. setModelData( model, '<paragraph>aaa[<placeholder>]</placeholder>bbb</paragraph>' );
  966. expect( getModelData( model ) ).to.equal( '<paragraph>aaa[]<placeholder></placeholder>bbb</paragraph>' );
  967. } );
  968. it( 'should fix selection that starts in inline element', () => {
  969. setModelData( model, '<paragraph>aaa<placeholder>[</placeholder>]bbb</paragraph>' );
  970. expect( getModelData( model ) ).to.equal( '<paragraph>aaa<placeholder></placeholder>[]bbb</paragraph>' );
  971. } );
  972. it( 'should fix selection that ends in inline element that is also an object', () => {
  973. model.schema.extend( 'placeholder', {
  974. isObject: true
  975. } );
  976. setModelData( model, '<paragraph>aaa[<placeholder>]</placeholder>bbb</paragraph>' );
  977. expect( getModelData( model ) ).to.equal( '<paragraph>aaa[<placeholder></placeholder>]bbb</paragraph>' );
  978. } );
  979. it( 'should fix selection that starts in inline element that is also an object', () => {
  980. model.schema.extend( 'placeholder', {
  981. isObject: true
  982. } );
  983. setModelData( model, '<paragraph>aaa<placeholder>[</placeholder>]bbb</paragraph>' );
  984. expect( getModelData( model ) ).to.equal( '<paragraph>aaa[<placeholder></placeholder>]bbb</paragraph>' );
  985. } );
  986. } );
  987. describe( 'collapsed selection', () => {
  988. beforeEach( () => {
  989. setModelData( model,
  990. '<paragraph>foo</paragraph>' +
  991. '<table>' +
  992. '<tableRow>' +
  993. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  994. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  995. '</tableRow>' +
  996. '</table>' +
  997. '<paragraph>bar</paragraph>'
  998. );
  999. } );
  1000. it( 'should fix #1 (selection in limit element & before limit element)', () => {
  1001. // <table>[]<tableRow>...
  1002. model.change( writer => {
  1003. writer.setSelection(
  1004. writer.createRange( writer.createPositionAt( modelRoot.getChild( 1 ), 0 ) )
  1005. );
  1006. } );
  1007. expect( getModelData( model ) ).to.equal(
  1008. '<paragraph>foo[]</paragraph>' +
  1009. '<table>' +
  1010. '<tableRow>' +
  1011. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  1012. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  1013. '</tableRow>' +
  1014. '</table>' +
  1015. '<paragraph>bar</paragraph>'
  1016. );
  1017. } );
  1018. it( 'should fix #2 (selection in limit element & before limit+object element)', () => {
  1019. // <table><tableRow>[]<tableCell>...
  1020. model.change( writer => {
  1021. const row = modelRoot.getChild( 1 ).getChild( 0 );
  1022. writer.setSelection(
  1023. writer.createRange( writer.createPositionAt( row, 0 ) )
  1024. );
  1025. } );
  1026. expect( getModelData( model ) ).to.equal(
  1027. '<paragraph>foo</paragraph>' +
  1028. '<table>' +
  1029. '<tableRow>' +
  1030. '[<tableCell><paragraph>aaa</paragraph></tableCell>]' +
  1031. '<tableCell><paragraph>bbb</paragraph></tableCell>' +
  1032. '</tableRow>' +
  1033. '</table>' +
  1034. '<paragraph>bar</paragraph>'
  1035. );
  1036. } );
  1037. it( 'should fix #3 (selection inside object element and before block element)', () => {
  1038. setModelData( model,
  1039. '<paragraph>foo</paragraph>' +
  1040. '<table>' +
  1041. '<tableRow>' +
  1042. '<tableCell>[]<paragraph>aaa</paragraph></tableCell>' +
  1043. '</tableRow>' +
  1044. '</table>' +
  1045. '<paragraph>bar</paragraph>'
  1046. );
  1047. assertEqualMarkup( getModelData( model ),
  1048. '<paragraph>foo</paragraph>' +
  1049. '<table>' +
  1050. '<tableRow>' +
  1051. '<tableCell><paragraph>[]aaa</paragraph></tableCell>' +
  1052. '</tableRow>' +
  1053. '</table>' +
  1054. '<paragraph>bar</paragraph>'
  1055. );
  1056. } );
  1057. it( 'should fix multiple ranges outside block element (but not merge them)', () => {
  1058. setModelData( model,
  1059. '[]<paragraph>foo</paragraph>[]' +
  1060. '<table>' +
  1061. '<tableRow>' +
  1062. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  1063. '</tableRow>' +
  1064. '</table>' +
  1065. '<paragraph>bar</paragraph>'
  1066. );
  1067. assertEqualMarkup( getModelData( model ),
  1068. '<paragraph>[]foo[]</paragraph>' +
  1069. '<table>' +
  1070. '<tableRow>' +
  1071. '<tableCell><paragraph>aaa</paragraph></tableCell>' +
  1072. '</tableRow>' +
  1073. '</table>' +
  1074. '<paragraph>bar</paragraph>'
  1075. );
  1076. } );
  1077. } );
  1078. } );
  1079. } );