8
0

restrictededitingmodeediting.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  6. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  7. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  8. import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
  9. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  10. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  11. import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting';
  12. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  13. import Typing from '@ckeditor/ckeditor5-typing/src/typing';
  14. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  15. import RestrictedEditingModeEditing from './../src/restrictededitingmodeediting';
  16. import RestrictedEditingModeNavigationCommand from '../src/restrictededitingmodenavigationcommand';
  17. import TableEditing from '@ckeditor/ckeditor5-table/src/tableediting';
  18. describe( 'RestrictedEditingModeEditing', () => {
  19. let editor, model;
  20. testUtils.createSinonSandbox();
  21. describe( 'plugin', () => {
  22. beforeEach( async () => {
  23. editor = await VirtualTestEditor.create( { plugins: [ RestrictedEditingModeEditing ] } );
  24. } );
  25. afterEach( async () => {
  26. await editor.destroy();
  27. } );
  28. it( 'should be named', () => {
  29. expect( RestrictedEditingModeEditing.pluginName ).to.equal( 'RestrictedEditingModeEditing' );
  30. } );
  31. it( 'should be loaded', () => {
  32. expect( editor.plugins.get( RestrictedEditingModeEditing ) ).to.be.instanceOf( RestrictedEditingModeEditing );
  33. } );
  34. it( 'adds a "goToPreviousRestrictedEditingException" command', () => {
  35. expect( editor.commands.get( 'goToPreviousRestrictedEditingException' ) )
  36. .to.be.instanceOf( RestrictedEditingModeNavigationCommand );
  37. } );
  38. it( 'adds a "goToNextRestrictedEditingException" command', () => {
  39. expect(
  40. editor.commands.get( 'goToNextRestrictedEditingException' )
  41. ).to.be.instanceOf( RestrictedEditingModeNavigationCommand );
  42. } );
  43. } );
  44. describe( 'conversion', () => {
  45. beforeEach( async () => {
  46. editor = await VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing, RestrictedEditingModeEditing ] } );
  47. model = editor.model;
  48. } );
  49. afterEach( () => {
  50. return editor.destroy();
  51. } );
  52. describe( 'upcast', () => {
  53. it( 'should convert <span class="restricted-editing-exception"> to marker', () => {
  54. editor.setData( '<p>foo <span class="restricted-editing-exception">bar</span> baz</p>' );
  55. expect( model.markers.has( 'restrictedEditingException:1' ) ).to.be.true;
  56. const marker = model.markers.get( 'restrictedEditingException:1' );
  57. expect( marker.getStart().path ).to.deep.equal( [ 0, 4 ] );
  58. expect( marker.getEnd().path ).to.deep.equal( [ 0, 7 ] );
  59. } );
  60. it( 'should convert multiple <span class="restricted-editing-exception">', () => {
  61. editor.setData(
  62. '<p>foo <span class="restricted-editing-exception">bar</span> baz</p>' +
  63. '<p>ABCDEF<span class="restricted-editing-exception">GHIJK</span>LMNOPQRST</p>'
  64. );
  65. expect( model.markers.has( 'restrictedEditingException:1' ) ).to.be.true;
  66. expect( model.markers.has( 'restrictedEditingException:2' ) ).to.be.true;
  67. // Data for the first marker is the same as in previous tests so no need to test it again.
  68. const secondMarker = model.markers.get( 'restrictedEditingException:2' );
  69. expect( secondMarker.getStart().path ).to.deep.equal( [ 1, 6 ] );
  70. expect( secondMarker.getEnd().path ).to.deep.equal( [ 1, 11 ] );
  71. } );
  72. it( 'should convert <span class="restricted-editing-exception"> inside table to marker', () => {
  73. editor.setData(
  74. '<figure class="table">' +
  75. '<table><tbody><tr><td><span class="restricted-editing-exception">bar</span></td></tr></tbody></table>' +
  76. '</figure>'
  77. );
  78. expect( model.markers.has( 'restrictedEditingException:1' ) ).to.be.true;
  79. const marker = model.markers.get( 'restrictedEditingException:1' );
  80. expect( marker.getStart().path ).to.deep.equal( [ 0, 0, 0, 0, 0 ] );
  81. expect( marker.getEnd().path ).to.deep.equal( [ 0, 0, 0, 0, 3 ] );
  82. } );
  83. it( 'should not convert other <span> elements', () => {
  84. editor.setData( '<p>foo <span class="foo bar">bar</span> baz</p>' );
  85. expect( model.markers.has( 'restrictedEditingException:1' ) ).to.be.false;
  86. } );
  87. } );
  88. describe( 'downcast', () => {
  89. it( 'should convert model marker to <span>', () => {
  90. setModelData( model, '<paragraph>foo bar baz</paragraph>' );
  91. const paragraph = model.document.getRoot().getChild( 0 );
  92. model.change( writer => {
  93. writer.addMarker( 'restrictedEditingException:1', {
  94. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  95. usingOperation: true,
  96. affectsData: true
  97. } );
  98. } );
  99. const expectedView = '<p>foo <span class="restricted-editing-exception">bar</span> baz</p>';
  100. expect( editor.getData() ).to.equal( expectedView );
  101. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
  102. } );
  103. it( 'should convert collapsed model marker to <span>', () => {
  104. setModelData( model, '<paragraph>foo bar baz</paragraph>' );
  105. const paragraph = model.document.getRoot().getChild( 0 );
  106. model.change( writer => {
  107. writer.addMarker( 'restrictedEditingException:1', {
  108. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 4 ) ),
  109. usingOperation: true,
  110. affectsData: true
  111. } );
  112. } );
  113. expect( editor.getData() ).to.equal( '<p>foo <span class="restricted-editing-exception"></span>bar baz</p>' );
  114. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal(
  115. '<p>foo <span class="restricted-editing-exception restricted-editing-exception_collapsed"></span>bar baz</p>'
  116. );
  117. } );
  118. it( 'converted <span> should be the outermost attribute element', () => {
  119. editor.conversion.for( 'downcast' ).attributeToElement( { model: 'bold', view: 'b' } );
  120. setModelData( model, '<paragraph><$text bold="true">foo bar baz</$text></paragraph>' );
  121. const paragraph = model.document.getRoot().getChild( 0 );
  122. model.change( writer => {
  123. writer.addMarker( 'restrictedEditingException:1', {
  124. range: writer.createRange( writer.createPositionAt( paragraph, 0 ), writer.createPositionAt( paragraph, 'end' ) ),
  125. usingOperation: true,
  126. affectsData: true
  127. } );
  128. } );
  129. expect( editor.getData() ).to.equal(
  130. '<p><span class="restricted-editing-exception"><b>foo bar baz</b></span></p>'
  131. );
  132. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal(
  133. '<p>' +
  134. '<span class="restricted-editing-exception restricted-editing-exception_selected"><b>foo bar baz</b></span>' +
  135. '</p>'
  136. );
  137. } );
  138. it( 'converted <span> should be the outermost attribute element', () => {
  139. editor.conversion.for( 'downcast' ).attributeToElement( { model: 'bold', view: 'b' } );
  140. setModelData( model,
  141. '<table><tableRow><tableCell>' +
  142. '<paragraph><$text bold="true">foo bar baz</$text></paragraph>' +
  143. '</tableCell></tableRow></table>'
  144. );
  145. const paragraph = model.document.getRoot().getChild( 0 ).getChild( 0 ).getChild( 0 ).getChild( 0 );
  146. model.change( writer => {
  147. writer.addMarker( 'restrictedEditingException:1', {
  148. range: writer.createRange( writer.createPositionAt( paragraph, 0 ), writer.createPositionAt( paragraph, 'end' ) ),
  149. usingOperation: true,
  150. affectsData: true
  151. } );
  152. } );
  153. assertEqualMarkup( editor.getData(),
  154. '<figure class="table"><table><tbody><tr><td>' +
  155. '<span class="restricted-editing-exception"><b>foo bar baz</b></span>' +
  156. '</td></tr></tbody></table></figure>'
  157. );
  158. assertEqualMarkup( getViewData( editor.editing.view, { withoutSelection: true } ),
  159. '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
  160. '<div class="ck ck-widget__selection-handle"></div>' +
  161. '<table><tbody><tr><td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
  162. '<span><span class="restricted-editing-exception"><b>foo bar baz</b></span></span>' +
  163. '</td></tr></tbody></table>' +
  164. '</figure>'
  165. );
  166. } );
  167. } );
  168. } );
  169. describe( 'editing behavior', () => {
  170. beforeEach( async () => {
  171. editor = await VirtualTestEditor.create( { plugins: [ Paragraph, Typing, RestrictedEditingModeEditing ] } );
  172. model = editor.model;
  173. } );
  174. afterEach( () => {
  175. return editor.destroy();
  176. } );
  177. it( 'should keep markers in the view when editable region is edited', () => {
  178. setModelData( model,
  179. '<paragraph>foo bar baz</paragraph>' +
  180. '<paragraph>xxx y[]yy zzz</paragraph>'
  181. );
  182. const firstParagraph = model.document.getRoot().getChild( 0 );
  183. const secondParagraph = model.document.getRoot().getChild( 1 );
  184. model.change( writer => {
  185. writer.addMarker( 'restrictedEditingException:1', {
  186. range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ), writer.createPositionAt( firstParagraph, 7 ) ),
  187. usingOperation: true,
  188. affectsData: true
  189. } );
  190. writer.addMarker( 'restrictedEditingException:2', {
  191. range: writer.createRange(
  192. writer.createPositionAt( secondParagraph, 4 ),
  193. writer.createPositionAt( secondParagraph, 7 )
  194. ),
  195. usingOperation: true,
  196. affectsData: true
  197. } );
  198. } );
  199. model.change( writer => {
  200. model.insertContent( writer.createText( 'R', model.document.selection.getAttributes() ) );
  201. } );
  202. expect( editor.getData() ).to.equal(
  203. '<p>foo <span class="restricted-editing-exception">bar</span> baz</p>' +
  204. '<p>xxx <span class="restricted-editing-exception">yRyy</span> zzz</p>' );
  205. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal(
  206. '<p>foo <span class="restricted-editing-exception">bar</span> baz</p>' +
  207. '<p>xxx <span class="restricted-editing-exception restricted-editing-exception_selected">yRyy</span> zzz</p>' );
  208. } );
  209. it( 'should block user typing outside exception markers', () => {
  210. setModelData( model, '<paragraph>foo []bar baz</paragraph>' );
  211. editor.execute( 'input', { text: 'X' } );
  212. assertEqualMarkup( getModelData( model ), '<paragraph>foo []bar baz</paragraph>' );
  213. } );
  214. it( 'should not block user typing inside exception marker', () => {
  215. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  216. const firstParagraph = model.document.getRoot().getChild( 0 );
  217. model.change( writer => {
  218. writer.addMarker( 'restrictedEditingException:1', {
  219. range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ), writer.createPositionAt( firstParagraph, 7 ) ),
  220. usingOperation: true,
  221. affectsData: true
  222. } );
  223. } );
  224. model.change( writer => {
  225. writer.setSelection( firstParagraph, 5 );
  226. } );
  227. editor.execute( 'input', { text: 'X' } );
  228. assertEqualMarkup( getModelData( model ), '<paragraph>foo bX[]ar baz</paragraph>' );
  229. } );
  230. it( 'should extend maker when typing on the marker boundary (end)', () => {
  231. setModelData( model, '<paragraph>foo bar[] baz</paragraph>' );
  232. const firstParagraph = model.document.getRoot().getChild( 0 );
  233. model.change( writer => {
  234. writer.addMarker( 'restrictedEditingException:1', {
  235. range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ), writer.createPositionAt( firstParagraph, 7 ) ),
  236. usingOperation: true,
  237. affectsData: true
  238. } );
  239. } );
  240. editor.execute( 'input', { text: 'X' } );
  241. assertEqualMarkup( getModelData( model ), '<paragraph>foo barX[] baz</paragraph>' );
  242. const markerRange = editor.model.markers.get( 'restrictedEditingException:1' ).getRange();
  243. const expectedRange = model.createRange(
  244. model.createPositionAt( firstParagraph, 4 ),
  245. model.createPositionAt( firstParagraph, 8 )
  246. );
  247. expect( markerRange.isEqual( expectedRange ) ).to.be.true;
  248. } );
  249. it( 'should extend marker when typing on the marker boundary (start)', () => {
  250. setModelData( model, '<paragraph>foo []bar baz</paragraph>' );
  251. const firstParagraph = model.document.getRoot().getChild( 0 );
  252. model.change( writer => {
  253. writer.addMarker( 'restrictedEditingException:1', {
  254. range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ), writer.createPositionAt( firstParagraph, 7 ) ),
  255. usingOperation: true,
  256. affectsData: true
  257. } );
  258. } );
  259. editor.execute( 'input', { text: 'X' } );
  260. assertEqualMarkup( getModelData( model ), '<paragraph>foo X[]bar baz</paragraph>' );
  261. const markerRange = editor.model.markers.get( 'restrictedEditingException:1' ).getRange();
  262. const expectedRange = model.createRange(
  263. model.createPositionAt( firstParagraph, 4 ),
  264. model.createPositionAt( firstParagraph, 8 )
  265. );
  266. expect( markerRange.isEqual( expectedRange ) ).to.be.true;
  267. } );
  268. it( 'should extend marker when typing on the marker boundary (collapsed marker)', () => {
  269. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  270. const firstParagraph = model.document.getRoot().getChild( 0 );
  271. model.change( writer => {
  272. writer.addMarker( 'restrictedEditingException:1', {
  273. range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ) ),
  274. usingOperation: true,
  275. affectsData: true
  276. } );
  277. } );
  278. model.change( writer => {
  279. writer.setSelection( writer.createPositionAt( firstParagraph, 4 ) );
  280. } );
  281. editor.execute( 'input', { text: 'X' } );
  282. assertEqualMarkup( getModelData( model ), '<paragraph>foo X[]bar baz</paragraph>' );
  283. const markerRange = editor.model.markers.get( 'restrictedEditingException:1' ).getRange();
  284. const expectedRange = model.createRange(
  285. model.createPositionAt( firstParagraph, 4 ),
  286. model.createPositionAt( firstParagraph, 5 )
  287. );
  288. expect( markerRange.isEqual( expectedRange ) ).to.be.true;
  289. } );
  290. it( 'should retain marker on non-typing change at the marker boundary (start)', () => {
  291. setModelData( model, '<paragraph>foo bar[] baz</paragraph>' );
  292. const firstParagraph = model.document.getRoot().getChild( 0 );
  293. addExceptionMarker( 4, 7, firstParagraph );
  294. model.change( writer => {
  295. editor.execute( 'delete', {
  296. selection: writer.createSelection( writer.createRange(
  297. writer.createPositionAt( firstParagraph, 4 ),
  298. writer.createPositionAt( firstParagraph, 6 )
  299. ) )
  300. } );
  301. editor.execute( 'input', {
  302. text: 'XX',
  303. range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ) )
  304. } );
  305. } );
  306. assertEqualMarkup( getModelData( model ), '<paragraph>foo XX[]r baz</paragraph>' );
  307. const markerRange = editor.model.markers.get( 'restrictedEditingException:1' ).getRange();
  308. const expectedRange = model.createRange(
  309. model.createPositionAt( firstParagraph, 4 ),
  310. model.createPositionAt( firstParagraph, 7 )
  311. );
  312. expect( markerRange.isEqual( expectedRange ) ).to.be.true;
  313. } );
  314. it( 'should retain marker on non-typing change at marker boundary (end)', () => {
  315. setModelData( model, '<paragraph>foo bar[] baz</paragraph>' );
  316. const firstParagraph = model.document.getRoot().getChild( 0 );
  317. addExceptionMarker( 4, 7, firstParagraph );
  318. model.change( writer => {
  319. editor.execute( 'delete', {
  320. selection: writer.createSelection( writer.createRange(
  321. writer.createPositionAt( firstParagraph, 5 ),
  322. writer.createPositionAt( firstParagraph, 7 )
  323. ) )
  324. } );
  325. editor.execute( 'input', {
  326. text: 'XX',
  327. range: writer.createRange( writer.createPositionAt( firstParagraph, 5 ) )
  328. } );
  329. } );
  330. assertEqualMarkup( getModelData( model ), '<paragraph>foo bXX[] baz</paragraph>' );
  331. const markerRange = editor.model.markers.get( 'restrictedEditingException:1' ).getRange();
  332. const expectedRange = model.createRange(
  333. model.createPositionAt( firstParagraph, 4 ),
  334. model.createPositionAt( firstParagraph, 7 )
  335. );
  336. expect( markerRange.isEqual( expectedRange ) ).to.be.true;
  337. } );
  338. it( 'should not move collapsed marker to $graveyard', () => {
  339. setModelData( model, '<paragraph>foo b[]ar baz</paragraph>' );
  340. const firstParagraph = model.document.getRoot().getChild( 0 );
  341. model.change( writer => {
  342. writer.addMarker( 'restrictedEditingException:1', {
  343. range: writer.createRange(
  344. writer.createPositionAt( firstParagraph, 4 ),
  345. writer.createPositionAt( firstParagraph, 5 )
  346. ),
  347. usingOperation: true,
  348. affectsData: true
  349. } );
  350. } );
  351. editor.execute( 'delete' );
  352. assertEqualMarkup( getModelData( model ), '<paragraph>foo []ar baz</paragraph>' );
  353. const markerRange = editor.model.markers.get( 'restrictedEditingException:1' ).getRange();
  354. const expectedRange = model.createRange(
  355. model.createPositionAt( firstParagraph, 4 ),
  356. model.createPositionAt( firstParagraph, 4 )
  357. );
  358. expect( markerRange.isEqual( expectedRange ) ).to.be.true;
  359. } );
  360. } );
  361. describe( 'enforcing restrictions on deleteContent', () => {
  362. beforeEach( async () => {
  363. editor = await VirtualTestEditor.create( { plugins: [ Paragraph, Typing, RestrictedEditingModeEditing ] } );
  364. model = editor.model;
  365. } );
  366. afterEach( async () => {
  367. await editor.destroy();
  368. } );
  369. it( 'should not allow to delete content outside restricted area', () => {
  370. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  371. const firstParagraph = model.document.getRoot().getChild( 0 );
  372. addExceptionMarker( 3, 9, firstParagraph );
  373. model.change( writer => {
  374. writer.setSelection( firstParagraph, 2 );
  375. } );
  376. model.deleteContent( model.document.selection );
  377. assertEqualMarkup( getModelData( model ), '<paragraph>fo[]o bar baz</paragraph>' );
  378. } );
  379. it( 'should trim deleted content to a exception marker (focus in marker)', () => {
  380. setModelData( model, '<paragraph>[]foofoo bar baz</paragraph>' );
  381. const firstParagraph = model.document.getRoot().getChild( 0 );
  382. addExceptionMarker( 3, 9, firstParagraph );
  383. model.change( writer => {
  384. const selection = writer.createSelection( writer.createRange(
  385. writer.createPositionAt( firstParagraph, 0 ),
  386. writer.createPositionAt( firstParagraph, 6 )
  387. ) );
  388. model.deleteContent( selection );
  389. } );
  390. assertEqualMarkup( getModelData( model ), '<paragraph>[]foo bar baz</paragraph>' );
  391. } );
  392. it( 'should trim deleted content to a exception marker (anchor in marker)', () => {
  393. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  394. const firstParagraph = model.document.getRoot().getChild( 0 );
  395. addExceptionMarker( 4, 7, firstParagraph );
  396. model.change( writer => {
  397. const selection = writer.createSelection( writer.createRange(
  398. writer.createPositionAt( firstParagraph, 5 ),
  399. writer.createPositionAt( firstParagraph, 8 )
  400. ) );
  401. model.deleteContent( selection );
  402. } );
  403. assertEqualMarkup( getModelData( model ), '<paragraph>[]foo b baz</paragraph>' );
  404. } );
  405. it( 'should trim deleted content to a exception marker and alter the selection argument (delete command integration)', () => {
  406. setModelData( model, '<paragraph>[]foofoo bar baz</paragraph>' );
  407. const firstParagraph = model.document.getRoot().getChild( 0 );
  408. addExceptionMarker( 3, 9, firstParagraph );
  409. model.change( writer => {
  410. writer.setSelection( firstParagraph, 6 );
  411. } );
  412. editor.execute( 'delete', { unit: 'word' } );
  413. assertEqualMarkup( getModelData( model ), '<paragraph>foo[] bar baz</paragraph>' );
  414. } );
  415. it( 'should work with document selection', () => {
  416. setModelData( model, '<paragraph>f[oo bar] baz</paragraph>' );
  417. const firstParagraph = model.document.getRoot().getChild( 0 );
  418. addExceptionMarker( 2, 'end', firstParagraph );
  419. model.change( () => {
  420. model.deleteContent( model.document.selection );
  421. } );
  422. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), '<paragraph>fo baz</paragraph>' );
  423. } );
  424. } );
  425. describe( 'enforcing restrictions on input command', () => {
  426. let firstParagraph;
  427. beforeEach( async () => {
  428. editor = await VirtualTestEditor.create( { plugins: [ Paragraph, Typing, RestrictedEditingModeEditing ] } );
  429. model = editor.model;
  430. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  431. firstParagraph = model.document.getRoot().getChild( 0 );
  432. } );
  433. afterEach( async () => {
  434. await editor.destroy();
  435. } );
  436. it( 'should prevent changing text before exception marker', () => {
  437. addExceptionMarker( 4, 7, firstParagraph );
  438. model.change( writer => {
  439. writer.setSelection( firstParagraph, 5 );
  440. } );
  441. // Simulate native spell-check action.
  442. editor.execute( 'input', {
  443. text: 'xxxxxxx',
  444. range: model.createRange(
  445. model.createPositionAt( firstParagraph, 0 ),
  446. model.createPositionAt( firstParagraph, 7 )
  447. )
  448. } );
  449. assertEqualMarkup( getModelData( model ), '<paragraph>foo b[]ar baz</paragraph>' );
  450. } );
  451. it( 'should prevent changing text before exception marker', () => {
  452. addExceptionMarker( 4, 7, firstParagraph );
  453. model.change( writer => {
  454. writer.setSelection( firstParagraph, 5 );
  455. } );
  456. // Simulate native spell-check action.
  457. editor.execute( 'input', {
  458. text: 'xxxxxxx',
  459. range: model.createRange(
  460. model.createPositionAt( firstParagraph, 4 ),
  461. model.createPositionAt( firstParagraph, 9 )
  462. )
  463. } );
  464. assertEqualMarkup( getModelData( model ), '<paragraph>foo b[]ar baz</paragraph>' );
  465. } );
  466. it( 'should prevent changing text before (change crossing different markers)', () => {
  467. addExceptionMarker( 0, 4, firstParagraph );
  468. addExceptionMarker( 7, 9, firstParagraph, 2 );
  469. model.change( writer => {
  470. writer.setSelection( firstParagraph, 2 );
  471. } );
  472. // Simulate native spell-check action.
  473. editor.execute( 'input', {
  474. text: 'xxxxxxx',
  475. range: model.createRange(
  476. model.createPositionAt( firstParagraph, 2 ),
  477. model.createPositionAt( firstParagraph, 8 )
  478. )
  479. } );
  480. assertEqualMarkup( getModelData( model ), '<paragraph>fo[]o bar baz</paragraph>' );
  481. } );
  482. it( 'should allow changing text inside single marker', () => {
  483. addExceptionMarker( 0, 9, firstParagraph );
  484. model.change( writer => {
  485. writer.setSelection( firstParagraph, 2 );
  486. } );
  487. // Simulate native spell-check action.
  488. editor.execute( 'input', {
  489. text: 'xxxxxxx',
  490. range: model.createRange(
  491. model.createPositionAt( firstParagraph, 2 ),
  492. model.createPositionAt( firstParagraph, 8 )
  493. )
  494. } );
  495. assertEqualMarkup( getModelData( model ), '<paragraph>foxxxxxxx[]baz</paragraph>' );
  496. } );
  497. } );
  498. describe( 'clipboard', () => {
  499. let model, viewDoc;
  500. beforeEach( async () => {
  501. editor = await VirtualTestEditor.create( { plugins: [ Paragraph, Typing, Clipboard, RestrictedEditingModeEditing ] } );
  502. model = editor.model;
  503. viewDoc = editor.editing.view.document;
  504. } );
  505. afterEach( () => {
  506. return editor.destroy();
  507. } );
  508. describe( 'cut', () => {
  509. it( 'should be blocked outside exception markers', () => {
  510. setModelData( model, '<paragraph>foo []bar baz</paragraph>' );
  511. const spy = sinon.spy();
  512. viewDoc.on( 'clipboardOutput', spy, { priority: 'high' } );
  513. viewDoc.fire( 'clipboardOutput', {
  514. content: {
  515. isEmpty: true
  516. },
  517. method: 'cut'
  518. } );
  519. sinon.assert.notCalled( spy );
  520. assertEqualMarkup( getModelData( model ), '<paragraph>foo []bar baz</paragraph>' );
  521. } );
  522. it( 'should be blocked inside exception marker', () => {
  523. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  524. const firstParagraph = model.document.getRoot().getChild( 0 );
  525. const spy = sinon.spy();
  526. viewDoc.on( 'clipboardOutput', spy, { priority: 'high' } );
  527. model.change( writer => {
  528. writer.addMarker( 'restrictedEditingException:1', {
  529. range: writer.createRange(
  530. writer.createPositionAt( firstParagraph, 4 ),
  531. writer.createPositionAt( firstParagraph, 7 )
  532. ),
  533. usingOperation: true,
  534. affectsData: true
  535. } );
  536. } );
  537. model.change( writer => {
  538. writer.setSelection( firstParagraph, 5 );
  539. } );
  540. viewDoc.fire( 'clipboardOutput', {
  541. content: {
  542. isEmpty: true
  543. },
  544. method: 'cut'
  545. } );
  546. sinon.assert.notCalled( spy );
  547. assertEqualMarkup( getModelData( model ), '<paragraph>foo b[]ar baz</paragraph>' );
  548. } );
  549. } );
  550. describe( 'copy', () => {
  551. it( 'should not be blocked outside exception markers', () => {
  552. setModelData( model, '<paragraph>foo []bar baz</paragraph>' );
  553. const spy = sinon.spy();
  554. viewDoc.on( 'clipboardOutput', spy, { priority: 'high' } );
  555. viewDoc.fire( 'clipboardOutput', {
  556. content: {
  557. isEmpty: true
  558. },
  559. method: 'copy'
  560. } );
  561. sinon.assert.calledOnce( spy );
  562. assertEqualMarkup( getModelData( model ), '<paragraph>foo []bar baz</paragraph>' );
  563. } );
  564. it( 'should not be blocked inside exception marker', () => {
  565. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  566. const firstParagraph = model.document.getRoot().getChild( 0 );
  567. const spy = sinon.spy();
  568. viewDoc.on( 'clipboardOutput', spy, { priority: 'high' } );
  569. model.change( writer => {
  570. writer.addMarker( 'restrictedEditingException:1', {
  571. range: writer.createRange(
  572. writer.createPositionAt( firstParagraph, 4 ),
  573. writer.createPositionAt( firstParagraph, 7 )
  574. ),
  575. usingOperation: true,
  576. affectsData: true
  577. } );
  578. } );
  579. model.change( writer => {
  580. writer.setSelection( firstParagraph, 5 );
  581. } );
  582. viewDoc.fire( 'clipboardOutput', {
  583. content: {
  584. isEmpty: true
  585. },
  586. method: 'copy'
  587. } );
  588. sinon.assert.calledOnce( spy );
  589. assertEqualMarkup( getModelData( model ), '<paragraph>foo b[]ar baz</paragraph>' );
  590. } );
  591. } );
  592. describe( 'paste', () => {
  593. it( 'should be blocked outside exception markers', () => {
  594. setModelData( model, '<paragraph>foo []bar baz</paragraph>' );
  595. const spy = sinon.spy();
  596. viewDoc.on( 'clipboardInput', spy, { priority: 'high' } );
  597. viewDoc.fire( 'clipboardInput', {
  598. dataTransfer: {
  599. getData: sinon.spy()
  600. }
  601. } );
  602. sinon.assert.notCalled( spy );
  603. assertEqualMarkup( getModelData( model ), '<paragraph>foo []bar baz</paragraph>' );
  604. } );
  605. it( 'should be blocked inside exception marker', () => {
  606. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  607. const firstParagraph = model.document.getRoot().getChild( 0 );
  608. const spy = sinon.spy();
  609. viewDoc.on( 'clipboardInput', spy, { priority: 'high' } );
  610. model.change( writer => {
  611. writer.addMarker( 'restrictedEditingException:1', {
  612. range: writer.createRange(
  613. writer.createPositionAt( firstParagraph, 4 ),
  614. writer.createPositionAt( firstParagraph, 7 )
  615. ),
  616. usingOperation: true,
  617. affectsData: true
  618. } );
  619. } );
  620. model.change( writer => {
  621. writer.setSelection( firstParagraph, 5 );
  622. } );
  623. viewDoc.fire( 'clipboardInput', {
  624. dataTransfer: {
  625. getData: sinon.spy()
  626. }
  627. } );
  628. sinon.assert.notCalled( spy );
  629. assertEqualMarkup( getModelData( model ), '<paragraph>foo b[]ar baz</paragraph>' );
  630. } );
  631. } );
  632. } );
  633. describe( 'exception highlighting', () => {
  634. let model, view;
  635. beforeEach( async () => {
  636. editor = await VirtualTestEditor.create( {
  637. plugins: [ Paragraph, RestrictedEditingModeEditing, BoldEditing ]
  638. } );
  639. model = editor.model;
  640. view = editor.editing.view;
  641. } );
  642. afterEach( () => {
  643. return editor.destroy();
  644. } );
  645. it( 'should convert the highlight to a proper view classes', () => {
  646. setModelData( model, '<paragraph>foo b[a]r baz</paragraph>' );
  647. const paragraph = model.document.getRoot().getChild( 0 );
  648. // <paragraph>foo <$marker>b[a]r</$marker> baz</paragraph>
  649. model.change( writer => {
  650. writer.addMarker( 'restrictedEditingException:1', {
  651. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  652. usingOperation: true,
  653. affectsData: true
  654. } );
  655. } );
  656. expect( getViewData( view ) ).to.equal(
  657. '<p>foo <span class="restricted-editing-exception restricted-editing-exception_selected">b{a}r</span> baz</p>'
  658. );
  659. } );
  660. it( 'should remove classes when selection is moved away from an exception', () => {
  661. setModelData( model, '<paragraph>foo b[a]r baz</paragraph>' );
  662. const paragraph = model.document.getRoot().getChild( 0 );
  663. // <paragraph>foo <$marker>b[a]r</$marker> baz</paragraph>
  664. model.change( writer => {
  665. writer.addMarker( 'restrictedEditingException:1', {
  666. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  667. usingOperation: true,
  668. affectsData: true
  669. } );
  670. } );
  671. expect( getViewData( view ) ).to.equal(
  672. '<p>foo <span class="restricted-editing-exception restricted-editing-exception_selected">b{a}r</span> baz</p>'
  673. );
  674. model.change( writer => writer.setSelection( model.document.getRoot().getChild( 0 ), 0 ) );
  675. expect( getViewData( view ) ).to.equal(
  676. '<p>{}foo <span class="restricted-editing-exception">bar</span> baz</p>'
  677. );
  678. } );
  679. it( 'should work correctly when selection is moved inside an exception', () => {
  680. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  681. const paragraph = model.document.getRoot().getChild( 0 );
  682. // <paragraph>[]foo <$marker>bar</$marker> baz</paragraph>
  683. model.change( writer => {
  684. writer.addMarker( 'restrictedEditingException:1', {
  685. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  686. usingOperation: true,
  687. affectsData: true
  688. } );
  689. } );
  690. expect( getViewData( view ) ).to.equal(
  691. '<p>{}foo <span class="restricted-editing-exception">bar</span> baz</p>'
  692. );
  693. model.change( writer => writer.setSelection( model.document.getRoot().getChild( 0 ), 6 ) );
  694. expect( getViewData( view ) ).to.equal(
  695. '<p>foo <span class="restricted-editing-exception restricted-editing-exception_selected">ba{}r</span> baz</p>'
  696. );
  697. } );
  698. describe( 'editing downcast conversion integration', () => {
  699. it( 'works for the #insert event', () => {
  700. setModelData( model, '<paragraph>foo b[a]r baz</paragraph>' );
  701. const paragraph = model.document.getRoot().getChild( 0 );
  702. // <paragraph>foo <$marker>b[a]r</$marker> baz</paragraph>
  703. model.change( writer => {
  704. writer.addMarker( 'restrictedEditingException:1', {
  705. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  706. usingOperation: true,
  707. affectsData: true
  708. } );
  709. } );
  710. model.change( writer => {
  711. writer.insertText( 'FOO', { linkHref: 'url' }, model.document.selection.getFirstPosition() );
  712. } );
  713. expect( getViewData( view ) ).to.equal(
  714. '<p>foo <span class="restricted-editing-exception restricted-editing-exception_selected">bFOO{a}r</span> baz</p>'
  715. );
  716. } );
  717. it( 'works for the #remove event', () => {
  718. setModelData( model, '<paragraph>foo b[a]r baz</paragraph>' );
  719. const paragraph = model.document.getRoot().getChild( 0 );
  720. // <paragraph>foo <$marker>b[a]r</$marker> baz</paragraph>
  721. model.change( writer => {
  722. writer.addMarker( 'restrictedEditingException:1', {
  723. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  724. usingOperation: true,
  725. affectsData: true
  726. } );
  727. } );
  728. model.change( writer => {
  729. writer.remove( writer.createRange(
  730. writer.createPositionAt( model.document.getRoot().getChild( 0 ), 5 ),
  731. writer.createPositionAt( model.document.getRoot().getChild( 0 ), 6 )
  732. ) );
  733. } );
  734. expect( getViewData( view ) ).to.equal(
  735. '<p>foo <span class="restricted-editing-exception restricted-editing-exception_selected">b{}r</span> baz</p>'
  736. );
  737. } );
  738. it( 'works for the #attribute event', () => {
  739. setModelData( model, '<paragraph>foo b[a]r baz</paragraph>' );
  740. const paragraph = model.document.getRoot().getChild( 0 );
  741. // <paragraph>foo <$marker>b[a]r</$marker> baz</paragraph>
  742. model.change( writer => {
  743. writer.addMarker( 'restrictedEditingException:1', {
  744. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  745. usingOperation: true,
  746. affectsData: true
  747. } );
  748. } );
  749. model.change( writer => {
  750. writer.setAttribute( 'bold', true, writer.createRange(
  751. model.document.selection.getFirstPosition().getShiftedBy( -1 ),
  752. model.document.selection.getFirstPosition().getShiftedBy( 1 ) )
  753. );
  754. } );
  755. expect( getViewData( view ) ).to.equal(
  756. '<p>foo ' +
  757. '<span class="restricted-editing-exception restricted-editing-exception_selected">' +
  758. '<strong>b{a</strong>' +
  759. '}r</span>' +
  760. ' baz</p>'
  761. );
  762. } );
  763. it( 'works for the #selection event', () => {
  764. setModelData( model, '<paragraph>foo b[a]r baz</paragraph>' );
  765. const paragraph = model.document.getRoot().getChild( 0 );
  766. // <paragraph>foo <$marker>b[a]r</$marker> baz</paragraph>
  767. model.change( writer => {
  768. writer.addMarker( 'restrictedEditingException:1', {
  769. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  770. usingOperation: true,
  771. affectsData: true
  772. } );
  773. } );
  774. model.change( writer => {
  775. writer.setSelection( writer.createRange(
  776. model.document.selection.getFirstPosition().getShiftedBy( -1 ),
  777. model.document.selection.getFirstPosition().getShiftedBy( 1 ) )
  778. );
  779. } );
  780. expect( getViewData( view ) ).to.equal(
  781. '<p>foo {<span class="restricted-editing-exception restricted-editing-exception_selected">ba}r</span> baz</p>'
  782. );
  783. } );
  784. it( 'works for the addMarker and removeMarker events', () => {
  785. editor.conversion.for( 'editingDowncast' ).markerToHighlight( { model: 'fooMarker', view: {} } );
  786. setModelData( model, '<paragraph>foo b[a]r baz</paragraph>' );
  787. const paragraph = model.document.getRoot().getChild( 0 );
  788. // <paragraph>foo <$marker>b[a]r</$marker> baz</paragraph>
  789. model.change( writer => {
  790. writer.addMarker( 'restrictedEditingException:1', {
  791. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  792. usingOperation: true,
  793. affectsData: true
  794. } );
  795. } );
  796. model.change( writer => {
  797. const range = writer.createRange(
  798. writer.createPositionAt( model.document.getRoot().getChild( 0 ), 0 ),
  799. writer.createPositionAt( model.document.getRoot().getChild( 0 ), 5 )
  800. );
  801. writer.addMarker( 'fooMarker', { range, usingOperation: true } );
  802. } );
  803. expect( getViewData( view ) ).to.equal(
  804. '<p>' +
  805. '<span>foo </span>' +
  806. '<span class="restricted-editing-exception restricted-editing-exception_selected">' +
  807. '<span>b</span>{a}r' +
  808. '</span>' +
  809. ' baz</p>'
  810. );
  811. model.change( writer => writer.removeMarker( 'fooMarker' ) );
  812. expect( getViewData( view ) ).to.equal(
  813. '<p>foo <span class="restricted-editing-exception restricted-editing-exception_selected">b{a}r</span> baz</p>'
  814. );
  815. } );
  816. } );
  817. } );
  818. describe( 'exception cycling with the keyboard', () => {
  819. let model, view, domEvtDataStub;
  820. beforeEach( async () => {
  821. editor = await VirtualTestEditor.create( {
  822. plugins: [ Paragraph, RestrictedEditingModeEditing, BoldEditing ]
  823. } );
  824. model = editor.model;
  825. view = editor.editing.view;
  826. domEvtDataStub = {
  827. keyCode: getCode( 'Tab' ),
  828. preventDefault: sinon.spy(),
  829. stopPropagation: sinon.spy()
  830. };
  831. sinon.spy( editor, 'execute' );
  832. } );
  833. afterEach( () => {
  834. return editor.destroy();
  835. } );
  836. it( 'should move to the closest next exception on tab key', () => {
  837. setModelData( model, '<paragraph>[]foo bar baz qux</paragraph>' );
  838. const paragraph = model.document.getRoot().getChild( 0 );
  839. // <paragraph>[]foo <marker>bar</marker> baz qux</paragraph>
  840. model.change( writer => {
  841. writer.addMarker( 'restrictedEditingException:1', {
  842. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  843. usingOperation: true,
  844. affectsData: true
  845. } );
  846. } );
  847. // <paragraph>[]foo <marker>bar</marker> <marker>baz</marker≥ qux</paragraph>
  848. model.change( writer => {
  849. writer.addMarker( 'restrictedEditingException:2', {
  850. range: writer.createRange( writer.createPositionAt( paragraph, 8 ), writer.createPositionAt( paragraph, 11 ) ),
  851. usingOperation: true,
  852. affectsData: true
  853. } );
  854. } );
  855. view.document.fire( 'keydown', domEvtDataStub );
  856. sinon.assert.calledOnce( editor.execute );
  857. sinon.assert.calledWithExactly( editor.execute, 'goToNextRestrictedEditingException' );
  858. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  859. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  860. } );
  861. it( 'should not move to the closest next exception on tab key when there is none', () => {
  862. setModelData( model, '<paragraph>foo qux[]</paragraph>' );
  863. const paragraph = model.document.getRoot().getChild( 0 );
  864. // <paragraph><marker>foo</marker> qux[]</paragraph>
  865. model.change( writer => {
  866. writer.addMarker( 'restrictedEditingException:1', {
  867. range: writer.createRange( writer.createPositionAt( paragraph, 0 ), writer.createPositionAt( paragraph, 3 ) ),
  868. usingOperation: true,
  869. affectsData: true
  870. } );
  871. } );
  872. view.document.fire( 'keydown', domEvtDataStub );
  873. sinon.assert.notCalled( editor.execute );
  874. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  875. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  876. } );
  877. it( 'should move to the closest previous exception on shift+tab key', () => {
  878. setModelData( model, '<paragraph>foo bar baz qux[]</paragraph>' );
  879. const paragraph = model.document.getRoot().getChild( 0 );
  880. // <paragraph>foo <marker>bar</marker> baz qux[]</paragraph>
  881. model.change( writer => {
  882. writer.addMarker( 'restrictedEditingException:1', {
  883. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  884. usingOperation: true,
  885. affectsData: true
  886. } );
  887. } );
  888. // <paragraph>foo <marker>bar</marker> <marker>baz</marker≥ qux[]</paragraph>
  889. model.change( writer => {
  890. writer.addMarker( 'restrictedEditingException:2', {
  891. range: writer.createRange( writer.createPositionAt( paragraph, 8 ), writer.createPositionAt( paragraph, 11 ) ),
  892. usingOperation: true,
  893. affectsData: true
  894. } );
  895. } );
  896. domEvtDataStub.keyCode += getCode( 'Shift' );
  897. view.document.fire( 'keydown', domEvtDataStub );
  898. sinon.assert.calledOnce( editor.execute );
  899. sinon.assert.calledWithExactly( editor.execute, 'goToPreviousRestrictedEditingException' );
  900. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  901. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  902. } );
  903. it( 'should not move to the closest previous exception on shift+tab key when there is none', () => {
  904. setModelData( model, '<paragraph>[]foo qux</paragraph>' );
  905. const paragraph = model.document.getRoot().getChild( 0 );
  906. // <paragraph>[]foo <marker>qux</marker></paragraph>
  907. model.change( writer => {
  908. writer.addMarker( 'restrictedEditingException:1', {
  909. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  910. usingOperation: true,
  911. affectsData: true
  912. } );
  913. } );
  914. domEvtDataStub.keyCode += getCode( 'Shift' );
  915. view.document.fire( 'keydown', domEvtDataStub );
  916. sinon.assert.notCalled( editor.execute );
  917. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  918. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  919. } );
  920. } );
  921. // Helper method that creates an exception marker inside given parent.
  922. // Marker range is set to given position offsets (start, end).
  923. function addExceptionMarker( startOffset, endOffset = startOffset, parent, id = 1 ) {
  924. model.change( writer => {
  925. writer.addMarker( `restrictedEditingException:${ id }`, {
  926. range: writer.createRange(
  927. writer.createPositionAt( parent, startOffset ),
  928. writer.createPositionAt( parent, endOffset )
  929. ),
  930. usingOperation: true,
  931. affectsData: true
  932. } );
  933. } );
  934. }
  935. } );