restrictededitingmodenavigationcommand.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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 ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
  6. import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  7. import RestrictedEditingModeNavigationCommand from '../src/restrictededitingmodenavigationcommand';
  8. describe( 'RestrictedEditingModeNavigationCommand', () => {
  9. let editor, forwardCommand, backwardCommand, model;
  10. beforeEach( () => {
  11. return ModelTestEditor
  12. .create()
  13. .then( newEditor => {
  14. editor = newEditor;
  15. model = editor.model;
  16. forwardCommand = new RestrictedEditingModeNavigationCommand( editor, 'forward' );
  17. backwardCommand = new RestrictedEditingModeNavigationCommand( editor, 'backward' );
  18. model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  19. editor.model.schema.extend( '$text', { allowAttributes: [ 'restrictedEditingException' ] } );
  20. } );
  21. } );
  22. afterEach( () => {
  23. forwardCommand.destroy();
  24. backwardCommand.destroy();
  25. return editor.destroy();
  26. } );
  27. describe( 'forward command', () => {
  28. describe( 'isEnabled', () => {
  29. describe( 'collapsed selection', () => {
  30. it( 'should be true when there is a marker after the selection position', () => {
  31. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  32. const paragraph = model.document.getRoot().getChild( 0 );
  33. // <paragraph>[]foo <marker>bar</marker> baz</paragraph>
  34. model.change( writer => {
  35. writer.addMarker( 'restrictedEditingException:1', {
  36. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  37. usingOperation: true,
  38. affectsData: true
  39. } );
  40. } );
  41. expect( forwardCommand.isEnabled ).to.be.true;
  42. } );
  43. it( 'should be false when there is no marker after the selection position', () => {
  44. setModelData( model, '<paragraph>foo bar baz[]</paragraph>' );
  45. const paragraph = model.document.getRoot().getChild( 0 );
  46. // <paragraph>foo <marker>bar</marker> baz[]</paragraph>
  47. model.change( writer => {
  48. writer.addMarker( 'restrictedEditingException:1', {
  49. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  50. usingOperation: true,
  51. affectsData: true
  52. } );
  53. } );
  54. expect( forwardCommand.isEnabled ).to.be.false;
  55. } );
  56. it( 'should be false when the selection position is at a marker start and there are no more markers', () => {
  57. setModelData( model, '<paragraph>foo []bar baz</paragraph>' );
  58. const paragraph = model.document.getRoot().getChild( 0 );
  59. // <paragraph>foo []<marker>bar</marker> baz</paragraph>
  60. model.change( writer => {
  61. writer.addMarker( 'restrictedEditingException:1', {
  62. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  63. usingOperation: true,
  64. affectsData: true
  65. } );
  66. } );
  67. expect( forwardCommand.isEnabled ).to.be.false;
  68. } );
  69. it( 'should be false when the selection position is in a marker and there are no more markers', () => {
  70. setModelData( model, '<paragraph>foo b[]ar baz</paragraph>' );
  71. const paragraph = model.document.getRoot().getChild( 0 );
  72. // <paragraph>foo <marker>b[]ar</marker> baz</paragraph>
  73. model.change( writer => {
  74. writer.addMarker( 'restrictedEditingException:1', {
  75. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  76. usingOperation: true,
  77. affectsData: true
  78. } );
  79. } );
  80. expect( forwardCommand.isEnabled ).to.be.false;
  81. } );
  82. it( 'should be false when the selection position is at a marker end and there are no more markers', () => {
  83. setModelData( model, '<paragraph>foo bar[] baz</paragraph>' );
  84. const paragraph = model.document.getRoot().getChild( 0 );
  85. // <paragraph>foo <marker>bar</marker>[] baz</paragraph>
  86. model.change( writer => {
  87. writer.addMarker( 'restrictedEditingException:1', {
  88. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  89. usingOperation: true,
  90. affectsData: true
  91. } );
  92. } );
  93. expect( forwardCommand.isEnabled ).to.be.false;
  94. } );
  95. } );
  96. describe( 'expanded selection', () => {
  97. it( 'should be true when there is a marker after the first selection position', () => {
  98. setModelData( model, '<paragraph>[fo]o bar baz</paragraph>' );
  99. const paragraph = model.document.getRoot().getChild( 0 );
  100. // <paragraph>[fo]o <marker>bar</marker> baz</paragraph>
  101. model.change( writer => {
  102. writer.addMarker( 'restrictedEditingException:1', {
  103. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  104. usingOperation: true,
  105. affectsData: true
  106. } );
  107. } );
  108. expect( forwardCommand.isEnabled ).to.be.true;
  109. } );
  110. it( 'should be true when the selection overlaps the marker but the start position is before it', () => {
  111. setModelData( model, '<paragraph>[foo ba]r baz</paragraph>' );
  112. const paragraph = model.document.getRoot().getChild( 0 );
  113. // <paragraph>[foo <marker>ba]r</marker> baz</paragraph>
  114. model.change( writer => {
  115. writer.addMarker( 'restrictedEditingException:1', {
  116. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  117. usingOperation: true,
  118. affectsData: true
  119. } );
  120. } );
  121. expect( forwardCommand.isEnabled ).to.be.true;
  122. } );
  123. it( 'should be false when the selection overlaps the marker but the start position is after it', () => {
  124. setModelData( model, '<paragraph>foo ba[r baz]</paragraph>' );
  125. const paragraph = model.document.getRoot().getChild( 0 );
  126. // <paragraph>foo <marker>ba[r</marker> baz]</paragraph>
  127. model.change( writer => {
  128. writer.addMarker( 'restrictedEditingException:1', {
  129. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  130. usingOperation: true,
  131. affectsData: true
  132. } );
  133. } );
  134. expect( forwardCommand.isEnabled ).to.be.false;
  135. } );
  136. } );
  137. } );
  138. describe( 'execute()', () => {
  139. describe( 'collapsed selection', () => {
  140. it( 'should move to the next marker', () => {
  141. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  142. const paragraph = model.document.getRoot().getChild( 0 );
  143. // <paragraph>[]foo <marker>bar</marker> baz</paragraph>
  144. model.change( writer => {
  145. writer.addMarker( 'restrictedEditingException:1', {
  146. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  147. usingOperation: true,
  148. affectsData: true
  149. } );
  150. } );
  151. // <paragraph>[]foo <marker>bar</marker> <marker>baz</marker></paragraph>
  152. model.change( writer => {
  153. writer.addMarker( 'restrictedEditingException:2', {
  154. range: writer.createRange( writer.createPositionAt( paragraph, 8 ), writer.createPositionAt( paragraph, 11 ) ),
  155. usingOperation: true,
  156. affectsData: true
  157. } );
  158. } );
  159. forwardCommand.execute();
  160. expect( getModelData( model ) ).to.equal( '<paragraph>foo [bar] baz</paragraph>' );
  161. forwardCommand.execute();
  162. expect( getModelData( model ) ).to.equal( '<paragraph>foo bar [baz]</paragraph>' );
  163. } );
  164. it( 'should move to the next marker when at the end of adjacent one', () => {
  165. setModelData( model, '<paragraph>foo[]</paragraph><paragraph>bar</paragraph>' );
  166. const fiirstParagraph = model.document.getRoot().getChild( 0 );
  167. const secondParagraph = model.document.getRoot().getChild( 1 );
  168. // <paragraph><marker>foo</marker>[]</paragraph><paragraph>bar</paragraph>
  169. model.change( writer => {
  170. writer.addMarker( 'restrictedEditingException:1', {
  171. range: writer.createRangeIn( fiirstParagraph ),
  172. usingOperation: true,
  173. affectsData: true
  174. } );
  175. } );
  176. // <paragraph><marker>foo</marker>[]</paragraph><paragraph><marker>bar</marker></paragraph>
  177. model.change( writer => {
  178. writer.addMarker( 'restrictedEditingException:2', {
  179. range: writer.createRangeIn( secondParagraph ),
  180. usingOperation: true,
  181. affectsData: true
  182. } );
  183. } );
  184. forwardCommand.execute();
  185. expect( getModelData( model ) ).to.equal( '<paragraph>foo</paragraph><paragraph>[bar]</paragraph>' );
  186. } );
  187. it( 'should move to the closest marker when created in a reverse order', () => {
  188. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  189. const paragraph = model.document.getRoot().getChild( 0 );
  190. // <paragraph>[]foo bar <marker>baz</marker></paragraph>
  191. model.change( writer => {
  192. writer.addMarker( 'restrictedEditingException:2', {
  193. range: writer.createRange( writer.createPositionAt( paragraph, 8 ), writer.createPositionAt( paragraph, 11 ) ),
  194. usingOperation: true,
  195. affectsData: true
  196. } );
  197. } );
  198. // <paragraph>[]foo <marker>bar</marker> <marker>baz</marker></paragraph>
  199. model.change( writer => {
  200. writer.addMarker( 'restrictedEditingException:1', {
  201. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  202. usingOperation: true,
  203. affectsData: true
  204. } );
  205. } );
  206. forwardCommand.execute();
  207. expect( getModelData( model ) ).to.equal( '<paragraph>foo [bar] baz</paragraph>' );
  208. forwardCommand.execute();
  209. expect( getModelData( model ) ).to.equal( '<paragraph>foo bar [baz]</paragraph>' );
  210. } );
  211. } );
  212. describe( 'expanded selection', () => {
  213. it( 'should move to the next marker when the selection end overlaps the marker', () => {
  214. setModelData( model, '<paragraph>[foo b]ar baz</paragraph>' );
  215. const paragraph = model.document.getRoot().getChild( 0 );
  216. // <paragraph>[foo <marker>b]ar</marker> baz</paragraph>
  217. model.change( writer => {
  218. writer.addMarker( 'restrictedEditingException:1', {
  219. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  220. usingOperation: true,
  221. affectsData: true
  222. } );
  223. } );
  224. // <paragraph>[foo <marker>b]ar</marker> <marker>baz</marker></paragraph>
  225. model.change( writer => {
  226. writer.addMarker( 'restrictedEditingException:2', {
  227. range: writer.createRange( writer.createPositionAt( paragraph, 8 ), writer.createPositionAt( paragraph, 11 ) ),
  228. usingOperation: true,
  229. affectsData: true
  230. } );
  231. } );
  232. forwardCommand.execute();
  233. expect( getModelData( model ) ).to.equal( '<paragraph>foo [bar] baz</paragraph>' );
  234. forwardCommand.execute();
  235. expect( getModelData( model ) ).to.equal( '<paragraph>foo bar [baz]</paragraph>' );
  236. } );
  237. it( 'should move to the next marker when the selection start overlaps the marker', () => {
  238. setModelData( model, '<paragraph>foo b[ar b]az</paragraph>' );
  239. const paragraph = model.document.getRoot().getChild( 0 );
  240. // <paragraph>foo <marker>b[ar</marker> b]az</paragraph>
  241. model.change( writer => {
  242. writer.addMarker( 'restrictedEditingException:1', {
  243. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  244. usingOperation: true,
  245. affectsData: true
  246. } );
  247. } );
  248. // <paragraph>foo <marker>b[ar</marker> <marker>b]az</marker></paragraph>
  249. model.change( writer => {
  250. writer.addMarker( 'restrictedEditingException:2', {
  251. range: writer.createRange( writer.createPositionAt( paragraph, 8 ), writer.createPositionAt( paragraph, 11 ) ),
  252. usingOperation: true,
  253. affectsData: true
  254. } );
  255. } );
  256. forwardCommand.execute();
  257. expect( getModelData( model ) ).to.equal( '<paragraph>foo bar [baz]</paragraph>' );
  258. } );
  259. } );
  260. } );
  261. } );
  262. describe( 'backward command', () => {
  263. describe( 'isEnabled', () => {
  264. describe( 'collapsed selection', () => {
  265. it( 'should be true when there is a marker before the selection position', () => {
  266. setModelData( model, '<paragraph>foo bar baz[]</paragraph>' );
  267. const paragraph = model.document.getRoot().getChild( 0 );
  268. // <paragraph>foo <marker>bar</marker> baz</paragraph>
  269. model.change( writer => {
  270. writer.addMarker( 'restrictedEditingException:1', {
  271. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  272. usingOperation: true,
  273. affectsData: true
  274. } );
  275. } );
  276. expect( backwardCommand.isEnabled ).to.be.true;
  277. } );
  278. it( 'should be false when there is no marker before the selection position', () => {
  279. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  280. const paragraph = model.document.getRoot().getChild( 0 );
  281. // <paragraph>[]foo <marker>bar</marker> baz</paragraph>
  282. model.change( writer => {
  283. writer.addMarker( 'restrictedEditingException:1', {
  284. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  285. usingOperation: true,
  286. affectsData: true
  287. } );
  288. } );
  289. expect( backwardCommand.isEnabled ).to.be.false;
  290. } );
  291. it( 'should be false when the selection position is at a marker end and there are no more markers', () => {
  292. setModelData( model, '<paragraph>foo bar[] baz</paragraph>' );
  293. const paragraph = model.document.getRoot().getChild( 0 );
  294. // <paragraph>foo <marker>bar</marker>[] baz</paragraph>
  295. model.change( writer => {
  296. writer.addMarker( 'restrictedEditingException:1', {
  297. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  298. usingOperation: true,
  299. affectsData: true
  300. } );
  301. } );
  302. expect( backwardCommand.isEnabled ).to.be.false;
  303. } );
  304. it( 'should be false when the selection position is in a marker and there are no more markers', () => {
  305. setModelData( model, '<paragraph>foo b[]ar baz</paragraph>' );
  306. const paragraph = model.document.getRoot().getChild( 0 );
  307. // <paragraph>foo <marker>b[]ar</marker> baz</paragraph>
  308. model.change( writer => {
  309. writer.addMarker( 'restrictedEditingException:1', {
  310. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  311. usingOperation: true,
  312. affectsData: true
  313. } );
  314. } );
  315. expect( backwardCommand.isEnabled ).to.be.false;
  316. } );
  317. it( 'should be false when the selection position is at a marker start and there are no more markers', () => {
  318. setModelData( model, '<paragraph>foo []bar baz</paragraph>' );
  319. const paragraph = model.document.getRoot().getChild( 0 );
  320. // <paragraph>foo []<marker>bar</marker> baz</paragraph>
  321. model.change( writer => {
  322. writer.addMarker( 'restrictedEditingException:1', {
  323. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  324. usingOperation: true,
  325. affectsData: true
  326. } );
  327. } );
  328. expect( backwardCommand.isEnabled ).to.be.false;
  329. } );
  330. } );
  331. describe( 'expanded selection', () => {
  332. it( 'should be true when there is a marker before the first selection position', () => {
  333. setModelData( model, '<paragraph>foo bar b[az]</paragraph>' );
  334. const paragraph = model.document.getRoot().getChild( 0 );
  335. // <paragraph>[fo]o <marker>bar</marker> b[az]</paragraph>
  336. model.change( writer => {
  337. writer.addMarker( 'restrictedEditingException:1', {
  338. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  339. usingOperation: true,
  340. affectsData: true
  341. } );
  342. } );
  343. expect( backwardCommand.isEnabled ).to.be.true;
  344. } );
  345. it( 'should be false when the selection overlaps the marker but the start position is after it', () => {
  346. setModelData( model, '<paragraph>foo b[ar baz]</paragraph>' );
  347. const paragraph = model.document.getRoot().getChild( 0 );
  348. // <paragraph>foo <marker>b[ar</marker> baz]</paragraph>
  349. model.change( writer => {
  350. writer.addMarker( 'restrictedEditingException:1', {
  351. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  352. usingOperation: true,
  353. affectsData: true
  354. } );
  355. } );
  356. expect( backwardCommand.isEnabled ).to.be.false;
  357. } );
  358. it( 'should be false when the selection overlaps the marker but the after position is after it', () => {
  359. setModelData( model, '<paragraph>[foo b]ar baz</paragraph>' );
  360. const paragraph = model.document.getRoot().getChild( 0 );
  361. // <paragraph>[foo <marker>b]ar</marker> baz</paragraph>
  362. model.change( writer => {
  363. writer.addMarker( 'restrictedEditingException:1', {
  364. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  365. usingOperation: true,
  366. affectsData: true
  367. } );
  368. } );
  369. expect( backwardCommand.isEnabled ).to.be.false;
  370. } );
  371. } );
  372. } );
  373. describe( 'execute()', () => {
  374. describe( 'collapsed selection', () => {
  375. it( 'should move to the previous marker', () => {
  376. setModelData( model, '<paragraph>foo bar baz[]</paragraph>' );
  377. const paragraph = model.document.getRoot().getChild( 0 );
  378. // <paragraph>foo <marker>bar</marker> baz[]</paragraph>
  379. model.change( writer => {
  380. writer.addMarker( 'restrictedEditingException:1', {
  381. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  382. usingOperation: true,
  383. affectsData: true
  384. } );
  385. } );
  386. // <paragraph>foo <marker>bar</marker> <marker>baz</marker>[]</paragraph>
  387. model.change( writer => {
  388. writer.addMarker( 'restrictedEditingException:2', {
  389. range: writer.createRange( writer.createPositionAt( paragraph, 8 ), writer.createPositionAt( paragraph, 11 ) ),
  390. usingOperation: true,
  391. affectsData: true
  392. } );
  393. } );
  394. backwardCommand.execute();
  395. expect( getModelData( model ) ).to.equal( '<paragraph>foo [bar] baz</paragraph>' );
  396. } );
  397. it( 'should move to the previous marker when at the beginning of adjacent one', () => {
  398. setModelData( model, '<paragraph>foo</paragraph><paragraph>[]bar</paragraph>' );
  399. const fiirstParagraph = model.document.getRoot().getChild( 0 );
  400. const secondParagraph = model.document.getRoot().getChild( 1 );
  401. // <paragraph><marker>foo</marker></paragraph><paragraph>[]bar</paragraph>
  402. model.change( writer => {
  403. writer.addMarker( 'restrictedEditingException:1', {
  404. range: writer.createRangeIn( fiirstParagraph ),
  405. usingOperation: true,
  406. affectsData: true
  407. } );
  408. } );
  409. // <paragraph><marker>foo</marker></paragraph><paragraph><marker>[]bar</marker></paragraph>
  410. model.change( writer => {
  411. writer.addMarker( 'restrictedEditingException:2', {
  412. range: writer.createRangeIn( secondParagraph ),
  413. usingOperation: true,
  414. affectsData: true
  415. } );
  416. } );
  417. backwardCommand.execute();
  418. expect( getModelData( model ) ).to.equal( '<paragraph>[foo]</paragraph><paragraph>bar</paragraph>' );
  419. } );
  420. it( 'should move to the closest previous marker', () => {
  421. setModelData( model, '<paragraph>foo bar baz qux[]</paragraph>' );
  422. const paragraph = model.document.getRoot().getChild( 0 );
  423. // <paragraph>foo <marker>bar</marker> baz qux[]</paragraph>
  424. model.change( writer => {
  425. writer.addMarker( 'restrictedEditingException:1', {
  426. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  427. usingOperation: true,
  428. affectsData: true
  429. } );
  430. } );
  431. // <paragraph>foo <marker>bar</marker> <marker>baz</marker> qux[]</paragraph>
  432. model.change( writer => {
  433. writer.addMarker( 'restrictedEditingException:2', {
  434. range: writer.createRange( writer.createPositionAt( paragraph, 8 ), writer.createPositionAt( paragraph, 11 ) ),
  435. usingOperation: true,
  436. affectsData: true
  437. } );
  438. } );
  439. backwardCommand.execute();
  440. expect( getModelData( model ) ).to.equal( '<paragraph>foo bar [baz] qux</paragraph>' );
  441. backwardCommand.execute();
  442. expect( getModelData( model ) ).to.equal( '<paragraph>foo [bar] baz qux</paragraph>' );
  443. } );
  444. it( 'should move to the closest previous marker when created in a reverse order', () => {
  445. setModelData( model, '<paragraph>foo bar baz qux[]</paragraph>' );
  446. const paragraph = model.document.getRoot().getChild( 0 );
  447. // <paragraph>foo bar <marker>baz</marker> qux[]</paragraph>
  448. model.change( writer => {
  449. writer.addMarker( 'restrictedEditingException:2', {
  450. range: writer.createRange( writer.createPositionAt( paragraph, 8 ), writer.createPositionAt( paragraph, 11 ) ),
  451. usingOperation: true,
  452. affectsData: true
  453. } );
  454. } );
  455. // <paragraph>foo <marker>bar</marker> <marker>baz</marker> qux[]</paragraph>
  456. model.change( writer => {
  457. writer.addMarker( 'restrictedEditingException:1', {
  458. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  459. usingOperation: true,
  460. affectsData: true
  461. } );
  462. } );
  463. backwardCommand.execute();
  464. expect( getModelData( model ) ).to.equal( '<paragraph>foo bar [baz] qux</paragraph>' );
  465. backwardCommand.execute();
  466. expect( getModelData( model ) ).to.equal( '<paragraph>foo [bar] baz qux</paragraph>' );
  467. } );
  468. } );
  469. describe( 'expanded selection', () => {
  470. it( 'should move to the previous marker when the selection end overlaps the marker', () => {
  471. setModelData( model, '<paragraph>foo bar b[az]</paragraph>' );
  472. const paragraph = model.document.getRoot().getChild( 0 );
  473. // <paragraph>foo <marker>bar</marker> b[az]</paragraph>
  474. model.change( writer => {
  475. writer.addMarker( 'restrictedEditingException:1', {
  476. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  477. usingOperation: true,
  478. affectsData: true
  479. } );
  480. } );
  481. // <paragraph>foo <marker>bar</marker> <marker>b[az</marker>]</paragraph>
  482. model.change( writer => {
  483. writer.addMarker( 'restrictedEditingException:2', {
  484. range: writer.createRange( writer.createPositionAt( paragraph, 8 ), writer.createPositionAt( paragraph, 11 ) ),
  485. usingOperation: true,
  486. affectsData: true
  487. } );
  488. } );
  489. backwardCommand.execute();
  490. expect( getModelData( model ) ).to.equal( '<paragraph>foo [bar] baz</paragraph>' );
  491. } );
  492. } );
  493. } );
  494. } );
  495. } );