8
0

undoediting-integration.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  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. /* global document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import UndoEditing from '../src/undoediting';
  8. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  9. import HeadingEditing from '@ckeditor/ckeditor5-heading/src/headingediting';
  10. import Typing from '@ckeditor/ckeditor5-typing/src/typing';
  11. import Enter from '@ckeditor/ckeditor5-enter/src/enter';
  12. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  13. import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting';
  14. import TableEditing from '@ckeditor/ckeditor5-table/src/tableediting';
  15. import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  16. describe( 'UndoEditing integration', () => {
  17. let editor, model, doc, root, div;
  18. beforeEach( () => {
  19. div = document.createElement( 'div' );
  20. document.body.appendChild( div );
  21. return ClassicEditor.create( div, {
  22. plugins: [ Paragraph, HeadingEditing, Typing, Enter, Clipboard, BoldEditing, UndoEditing, TableEditing ]
  23. } ).then( newEditor => {
  24. editor = newEditor;
  25. model = editor.model;
  26. doc = model.document;
  27. root = doc.getRoot();
  28. } );
  29. } );
  30. afterEach( () => {
  31. div.remove();
  32. return editor.destroy();
  33. } );
  34. function setSelection( pathA, pathB ) {
  35. model.change( writer => {
  36. writer.setSelection( writer.createRange(
  37. writer.createPositionFromPath( root, pathA ), writer.createPositionFromPath( root, pathB )
  38. ) );
  39. } );
  40. }
  41. function input( input ) {
  42. model.enqueueChange( 'transparent', () => {
  43. setData( model, input );
  44. } );
  45. }
  46. function output( output ) {
  47. expect( getData( model ) ).to.equal( output );
  48. }
  49. function undoDisabled() {
  50. expect( editor.commands.get( 'undo' ).isEnabled ).to.be.false;
  51. }
  52. function redoDisabled() {
  53. expect( editor.commands.get( 'redo' ).isEnabled ).to.be.false;
  54. }
  55. describe( 'adding and removing content', () => {
  56. it( 'add and undo', () => {
  57. input( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  58. model.change( writer => {
  59. writer.insertText( 'zzz', doc.selection.getFirstPosition() );
  60. } );
  61. output( '<paragraph>fozzz[]o</paragraph><paragraph>bar</paragraph>' );
  62. editor.execute( 'undo' );
  63. output( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  64. undoDisabled();
  65. } );
  66. it( 'multiple adding and undo', () => {
  67. input( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  68. model.change( writer => {
  69. writer.insertText( 'zzz', doc.selection.getFirstPosition() );
  70. writer.insertText( 'xxx', writer.createPositionFromPath( root, [ 1, 0 ] ) );
  71. } );
  72. output( '<paragraph>fozzz[]o</paragraph><paragraph>xxxbar</paragraph>' );
  73. model.change( writer => {
  74. setSelection( [ 1, 0 ], [ 1, 0 ] );
  75. writer.insertText( 'yyy', doc.selection.getFirstPosition() );
  76. } );
  77. output( '<paragraph>fozzzo</paragraph><paragraph>yyy[]xxxbar</paragraph>' );
  78. editor.execute( 'undo' );
  79. output( '<paragraph>fozzzo</paragraph><paragraph>[]xxxbar</paragraph>' );
  80. editor.execute( 'undo' );
  81. output( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  82. undoDisabled();
  83. } );
  84. it( 'multiple adding mixed with undo', () => {
  85. input( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  86. model.change( writer => {
  87. writer.insertText( 'zzz', doc.selection.getFirstPosition() );
  88. } );
  89. output( '<paragraph>fozzz[]o</paragraph><paragraph>bar</paragraph>' );
  90. model.change( writer => {
  91. setSelection( [ 1, 0 ], [ 1, 0 ] );
  92. writer.insertText( 'yyy', doc.selection.getFirstPosition() );
  93. } );
  94. output( '<paragraph>fozzzo</paragraph><paragraph>yyy[]bar</paragraph>' );
  95. editor.execute( 'undo' );
  96. output( '<paragraph>fozzzo</paragraph><paragraph>[]bar</paragraph>' );
  97. model.change( writer => {
  98. setSelection( [ 0, 0 ], [ 0, 0 ] );
  99. writer.insertText( 'xxx', doc.selection.getFirstPosition() );
  100. } );
  101. output( '<paragraph>xxx[]fozzzo</paragraph><paragraph>bar</paragraph>' );
  102. editor.execute( 'undo' );
  103. output( '<paragraph>[]fozzzo</paragraph><paragraph>bar</paragraph>' );
  104. editor.execute( 'undo' );
  105. output( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  106. undoDisabled();
  107. } );
  108. it( 'multiple remove and undo', () => {
  109. input( '<paragraph>[]foo</paragraph><paragraph>bar</paragraph>' );
  110. model.change( writer => {
  111. const start = doc.selection.getFirstPosition();
  112. writer.remove( writer.createRange( start, start.getShiftedBy( 2 ) ) );
  113. } );
  114. output( '<paragraph>[]o</paragraph><paragraph>bar</paragraph>' );
  115. model.change( writer => {
  116. setSelection( [ 1, 1 ], [ 1, 1 ] );
  117. const start = doc.selection.getFirstPosition();
  118. writer.remove( writer.createRange( start, start.getShiftedBy( 2 ) ) );
  119. } );
  120. output( '<paragraph>o</paragraph><paragraph>b[]</paragraph>' );
  121. editor.execute( 'undo' );
  122. // Here is an edge case that selection could be before or after `ar`.
  123. output( '<paragraph>o</paragraph><paragraph>bar[]</paragraph>' );
  124. editor.execute( 'undo' );
  125. // As above.
  126. output( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  127. undoDisabled();
  128. } );
  129. it( 'add and remove different parts and undo', () => {
  130. input( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  131. model.change( writer => {
  132. writer.insertText( 'zzz', doc.selection.getFirstPosition() );
  133. } );
  134. output( '<paragraph>fozzz[]o</paragraph><paragraph>bar</paragraph>' );
  135. model.change( writer => {
  136. setSelection( [ 1, 2 ], [ 1, 2 ] );
  137. const start = writer.createPositionFromPath( root, [ 1, 1 ] );
  138. writer.remove( writer.createRange( start, start.getShiftedBy( 1 ) ) );
  139. } );
  140. output( '<paragraph>fozzzo</paragraph><paragraph>b[]r</paragraph>' );
  141. editor.execute( 'undo' );
  142. output( '<paragraph>fozzzo</paragraph><paragraph>ba[]r</paragraph>' );
  143. editor.execute( 'undo' );
  144. output( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  145. undoDisabled();
  146. } );
  147. it( 'add and remove same part and undo', () => {
  148. input( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  149. model.change( writer => {
  150. writer.insertText( 'zzz', doc.selection.getFirstPosition() );
  151. } );
  152. output( '<paragraph>fozzz[]o</paragraph><paragraph>bar</paragraph>' );
  153. model.change( writer => {
  154. const start = writer.createPositionFromPath( root, [ 0, 2 ] );
  155. writer.remove( writer.createRange( start, start.getShiftedBy( 3 ) ) );
  156. } );
  157. output( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  158. editor.execute( 'undo' );
  159. output( '<paragraph>fozzz[]o</paragraph><paragraph>bar</paragraph>' );
  160. editor.execute( 'undo' );
  161. output( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
  162. undoDisabled();
  163. } );
  164. it( 'undo remove all content', () => {
  165. input( '<paragraph>foo[]</paragraph>' );
  166. model.change( writer => {
  167. writer.remove( writer.createRangeIn( root ) );
  168. } );
  169. output( '<paragraph>[]</paragraph>' ); // All hail our king and savior, autoparagraphing!
  170. editor.execute( 'undo' );
  171. output( '<paragraph>foo[]</paragraph>' );
  172. undoDisabled();
  173. } );
  174. it( 'undo insert first content', () => {
  175. input( '' );
  176. output( '<paragraph>[]</paragraph>' ); // All hail our king and savior, autoparagraphing!
  177. model.change( writer => {
  178. writer.remove( writer.createRangeIn( root ) );
  179. writer.insertElement( 'heading1', doc.selection.getFirstPosition() );
  180. } );
  181. output( '<heading1>[]</heading1>' );
  182. editor.execute( 'undo' );
  183. output( '<paragraph>[]</paragraph>' );
  184. undoDisabled();
  185. } );
  186. // #72.
  187. it( 'undo paste multiple elements simulation', () => {
  188. input( '<paragraph></paragraph>' );
  189. const p = root.getChild( 0 );
  190. const pos = model.createPositionFromPath( root, [ 0 ] );
  191. model.change( writer => {
  192. writer.remove( p );
  193. writer.insertElement( 'heading1', pos );
  194. writer.insertElement( 'heading2', pos.getShiftedBy( 1 ) );
  195. } );
  196. output( '<heading1>[]</heading1><heading2></heading2>' );
  197. editor.execute( 'undo' );
  198. output( '<paragraph>[]</paragraph>' );
  199. undoDisabled();
  200. } );
  201. } );
  202. describe( 'moving', () => {
  203. it( 'move same content twice then undo', () => {
  204. input( '<paragraph>f[o]z</paragraph><paragraph>bar</paragraph>' );
  205. model.change( writer => {
  206. writer.move( doc.selection.getFirstRange(), writer.createPositionFromPath( root, [ 1, 0 ] ) );
  207. } );
  208. output( '<paragraph>fz</paragraph><paragraph>[o]bar</paragraph>' );
  209. model.change( writer => {
  210. writer.move( doc.selection.getFirstRange(), writer.createPositionFromPath( root, [ 0, 2 ] ) );
  211. } );
  212. output( '<paragraph>fz[o]</paragraph><paragraph>bar</paragraph>' );
  213. editor.execute( 'undo' );
  214. output( '<paragraph>fz</paragraph><paragraph>[o]bar</paragraph>' );
  215. editor.execute( 'undo' );
  216. output( '<paragraph>f[o]z</paragraph><paragraph>bar</paragraph>' );
  217. undoDisabled();
  218. } );
  219. it( 'move content and new parent then undo', () => {
  220. input( '<paragraph>f[o]z</paragraph><paragraph>bar</paragraph>' );
  221. model.change( writer => {
  222. writer.move( doc.selection.getFirstRange(), writer.createPositionFromPath( root, [ 1, 0 ] ) );
  223. } );
  224. output( '<paragraph>fz</paragraph><paragraph>[o]bar</paragraph>' );
  225. model.change( writer => {
  226. setSelection( [ 1 ], [ 2 ] );
  227. writer.move( doc.selection.getFirstRange(), writer.createPositionFromPath( root, [ 0 ] ) );
  228. } );
  229. output( '<paragraph>[obar]</paragraph><paragraph>fz</paragraph>' );
  230. editor.execute( 'undo' );
  231. output( '<paragraph>fz</paragraph><paragraph>[obar]</paragraph>' );
  232. editor.execute( 'undo' );
  233. output( '<paragraph>f[o]z</paragraph><paragraph>bar</paragraph>' );
  234. undoDisabled();
  235. } );
  236. } );
  237. describe( 'attributes with other', () => {
  238. it( 'attributes then insert inside then undo', () => {
  239. input( '<paragraph>fo[ob]ar</paragraph>' );
  240. model.change( writer => {
  241. writer.setAttribute( 'bold', true, doc.selection.getFirstRange() );
  242. } );
  243. output( '<paragraph>fo[<$text bold="true">ob</$text>]ar</paragraph>' );
  244. expect( doc.selection.getAttribute( 'bold' ) ).to.be.true;
  245. model.change( writer => {
  246. setSelection( [ 0, 3 ], [ 0, 3 ] );
  247. writer.insertText( 'zzz', doc.selection.getFirstPosition() );
  248. } );
  249. output( '<paragraph>fo<$text bold="true">o</$text>zzz[]<$text bold="true">b</$text>ar</paragraph>' );
  250. expect( doc.selection.getAttribute( 'bold' ) ).to.be.undefined;
  251. editor.execute( 'undo' );
  252. output( '<paragraph>fo<$text bold="true">o[]b</$text>ar</paragraph>' );
  253. expect( doc.selection.getAttribute( 'bold' ) ).to.be.true;
  254. editor.execute( 'undo' );
  255. output( '<paragraph>fo[ob]ar</paragraph>' );
  256. expect( doc.selection.getAttribute( 'bold' ) ).to.be.undefined;
  257. undoDisabled();
  258. } );
  259. } );
  260. describe( 'wrapping, unwrapping, merging, splitting', () => {
  261. it( 'wrap and undo', () => {
  262. model.schema.extend( '$text', { allowIn: '$root' } );
  263. input( 'fo[zb]ar' );
  264. model.change( writer => {
  265. writer.wrap( doc.selection.getFirstRange(), 'paragraph' );
  266. } );
  267. output( 'fo<paragraph>[zb]</paragraph>ar' );
  268. editor.execute( 'undo' );
  269. output( 'fo[zb]ar' );
  270. undoDisabled();
  271. } );
  272. it( 'wrap, move and undo', () => {
  273. model.schema.extend( '$text', { allowIn: '$root' } );
  274. input( 'fo[zb]ar' );
  275. model.change( writer => {
  276. writer.wrap( doc.selection.getFirstRange(), 'paragraph' );
  277. } );
  278. // Would be better if selection was inside P.
  279. output( 'fo<paragraph>[zb]</paragraph>ar' );
  280. model.change( writer => {
  281. setSelection( [ 2, 0 ], [ 2, 1 ] );
  282. writer.move( doc.selection.getFirstRange(), writer.createPositionFromPath( root, [ 0 ] ) );
  283. } );
  284. output( '[z]fo<paragraph>b</paragraph>ar' );
  285. editor.execute( 'undo' );
  286. output( 'fo<paragraph>[z]b</paragraph>ar' );
  287. editor.execute( 'undo' );
  288. output( 'fo[zb]ar' );
  289. undoDisabled();
  290. } );
  291. it( 'unwrap and undo', () => {
  292. input( '<paragraph>foo[]bar</paragraph>' );
  293. model.change( writer => {
  294. writer.unwrap( doc.selection.getFirstPosition().parent );
  295. } );
  296. output( 'foo[]bar' );
  297. editor.execute( 'undo' );
  298. output( '<paragraph>foo[]bar</paragraph>' );
  299. undoDisabled();
  300. } );
  301. it( 'merge and undo', () => {
  302. input( '<paragraph>foo</paragraph><paragraph>[]bar</paragraph>' );
  303. model.change( writer => {
  304. writer.merge( writer.createPositionFromPath( root, [ 1 ] ) );
  305. } );
  306. output( '<paragraph>foo[]bar</paragraph>' );
  307. editor.execute( 'undo' );
  308. output( '<paragraph>foo[]</paragraph><paragraph>bar</paragraph>' );
  309. undoDisabled();
  310. } );
  311. it( 'split and undo', () => {
  312. input( '<paragraph>foo[]bar</paragraph>' );
  313. model.change( writer => {
  314. writer.split( doc.selection.getFirstPosition() );
  315. } );
  316. output( '<paragraph>foo[]</paragraph><paragraph>bar</paragraph>' );
  317. editor.execute( 'undo' );
  318. output( '<paragraph>foo[]bar</paragraph>' );
  319. undoDisabled();
  320. } );
  321. it.skip( 'move, merge and undo', () => {
  322. // Add a "div feature".
  323. model.schema.register( 'div', {
  324. allowWhere: '$block',
  325. allowContentOf: '$root'
  326. } );
  327. editor.conversion.for( 'downcast' ).elementToElement( { model: 'div', view: 'div' } );
  328. editor.conversion.for( 'upcast' ).elementToElement( { model: 'div', view: 'div' } );
  329. input(
  330. '<div><paragraph>[]00.</paragraph><paragraph>01.</paragraph><paragraph>02.</paragraph></div>' +
  331. '<div><paragraph>10.</paragraph><paragraph>11.</paragraph><paragraph>12.</paragraph></div>'
  332. );
  333. const elements = [
  334. root.getNodeByPath( [ 0, 1 ] ),
  335. root.getNodeByPath( [ 1, 0 ] ),
  336. root.getNodeByPath( [ 1, 1 ] )
  337. ];
  338. model.change( writer => {
  339. for ( let i = elements.length - 1; i > 0; i-- ) {
  340. merge( elements[ i ], elements[ i - 1 ], writer );
  341. }
  342. } );
  343. output(
  344. '<div><paragraph>[]00.</paragraph><paragraph>01.10.11.</paragraph><paragraph>02.</paragraph></div>' +
  345. '<div><paragraph>12.</paragraph></div>'
  346. );
  347. editor.execute( 'undo' );
  348. output(
  349. '<div><paragraph>[]00.</paragraph><paragraph>01.</paragraph><paragraph>02.</paragraph></div>' +
  350. '<div><paragraph>10.</paragraph><paragraph>11.</paragraph><paragraph>12.</paragraph></div>'
  351. );
  352. function merge( element, targetElement, writer ) {
  353. const positionAfterTarget = writer.createPositionAfter( targetElement );
  354. const positionBeforeElement = writer.createPositionBefore( element );
  355. if ( !positionAfterTarget.isEqual( positionBeforeElement ) ) {
  356. writer.move( writer.createRangeOn( element ), positionAfterTarget );
  357. }
  358. writer.merge( positionAfterTarget );
  359. }
  360. } );
  361. } );
  362. // Restoring selection in those examples may be completely off.
  363. describe( 'multiple enters, deletes and typing', () => {
  364. it( 'split, split, split', () => {
  365. input( '<paragraph>12345678</paragraph>' );
  366. split( [ 0, 3 ] );
  367. output( '<paragraph>123</paragraph><paragraph>[]45678</paragraph>' );
  368. split( [ 1, 4 ] );
  369. output( '<paragraph>123</paragraph><paragraph>4567</paragraph><paragraph>[]8</paragraph>' );
  370. split( [ 1, 2 ] );
  371. output( '<paragraph>123</paragraph><paragraph>45</paragraph><paragraph>[]67</paragraph><paragraph>8</paragraph>' );
  372. editor.execute( 'undo' );
  373. output( '<paragraph>123</paragraph><paragraph>45[]67</paragraph><paragraph>8</paragraph>' );
  374. editor.execute( 'undo' );
  375. output( '<paragraph>123</paragraph><paragraph>4567[]8</paragraph>' );
  376. editor.execute( 'undo' );
  377. output( '<paragraph>123[]45678</paragraph>' );
  378. undoDisabled();
  379. editor.execute( 'redo' );
  380. output( '<paragraph>123[]</paragraph><paragraph>45678</paragraph>' );
  381. editor.execute( 'redo' );
  382. output( '<paragraph>123</paragraph><paragraph>4567[]</paragraph><paragraph>8</paragraph>' );
  383. editor.execute( 'redo' );
  384. output( '<paragraph>123</paragraph><paragraph>45[]</paragraph><paragraph>67</paragraph><paragraph>8</paragraph>' );
  385. redoDisabled();
  386. } );
  387. it( 'merge, merge, merge', () => {
  388. input( '<paragraph>123</paragraph><paragraph>45</paragraph><paragraph>67</paragraph><paragraph>8</paragraph>' );
  389. merge( [ 1 ] );
  390. output( '<paragraph>123[]45</paragraph><paragraph>67</paragraph><paragraph>8</paragraph>' );
  391. merge( [ 2 ] );
  392. output( '<paragraph>12345</paragraph><paragraph>67[]8</paragraph>' );
  393. merge( [ 1 ] );
  394. output( '<paragraph>12345[]678</paragraph>' );
  395. editor.execute( 'undo' );
  396. output( '<paragraph>12345[]</paragraph><paragraph>678</paragraph>' );
  397. editor.execute( 'undo' );
  398. output( '<paragraph>12345</paragraph><paragraph>67[]</paragraph><paragraph>8</paragraph>' );
  399. editor.execute( 'undo' );
  400. output( '<paragraph>123[]</paragraph><paragraph>45</paragraph><paragraph>67</paragraph><paragraph>8</paragraph>' );
  401. undoDisabled();
  402. editor.execute( 'redo' );
  403. output( '<paragraph>123[]45</paragraph><paragraph>67</paragraph><paragraph>8</paragraph>' );
  404. editor.execute( 'redo' );
  405. output( '<paragraph>12345</paragraph><paragraph>67[]8</paragraph>' );
  406. editor.execute( 'redo' );
  407. output( '<paragraph>12345[]678</paragraph>' );
  408. redoDisabled();
  409. } );
  410. it( 'split, merge, split, merge (same position)', () => {
  411. input( '<paragraph>12345678</paragraph>' );
  412. split( [ 0, 3 ] );
  413. output( '<paragraph>123</paragraph><paragraph>[]45678</paragraph>' );
  414. merge( [ 1 ] );
  415. output( '<paragraph>123[]45678</paragraph>' );
  416. split( [ 0, 3 ] );
  417. output( '<paragraph>123</paragraph><paragraph>[]45678</paragraph>' );
  418. merge( [ 1 ] );
  419. output( '<paragraph>123[]45678</paragraph>' );
  420. editor.execute( 'undo' );
  421. output( '<paragraph>123[]</paragraph><paragraph>45678</paragraph>' );
  422. editor.execute( 'undo' );
  423. output( '<paragraph>123[]45678</paragraph>' );
  424. editor.execute( 'undo' );
  425. output( '<paragraph>123[]</paragraph><paragraph>45678</paragraph>' );
  426. editor.execute( 'undo' );
  427. output( '<paragraph>123[]45678</paragraph>' );
  428. undoDisabled();
  429. editor.execute( 'redo' );
  430. output( '<paragraph>123[]</paragraph><paragraph>45678</paragraph>' );
  431. editor.execute( 'redo' );
  432. output( '<paragraph>123[]45678</paragraph>' );
  433. editor.execute( 'redo' );
  434. output( '<paragraph>123[]</paragraph><paragraph>45678</paragraph>' );
  435. editor.execute( 'redo' );
  436. output( '<paragraph>123[]45678</paragraph>' );
  437. redoDisabled();
  438. } );
  439. it( 'split, split, split, merge, merge, merge', () => {
  440. input( '<paragraph>12345678</paragraph>' );
  441. split( [ 0, 3 ] );
  442. output( '<paragraph>123</paragraph><paragraph>[]45678</paragraph>' );
  443. split( [ 1, 4 ] );
  444. output( '<paragraph>123</paragraph><paragraph>4567</paragraph><paragraph>[]8</paragraph>' );
  445. split( [ 1, 2 ] );
  446. output( '<paragraph>123</paragraph><paragraph>45</paragraph><paragraph>[]67</paragraph><paragraph>8</paragraph>' );
  447. merge( [ 1 ] );
  448. output( '<paragraph>123[]45</paragraph><paragraph>67</paragraph><paragraph>8</paragraph>' );
  449. merge( [ 2 ] );
  450. output( '<paragraph>12345</paragraph><paragraph>67[]8</paragraph>' );
  451. merge( [ 1 ] );
  452. output( '<paragraph>12345[]678</paragraph>' );
  453. editor.execute( 'undo' );
  454. output( '<paragraph>12345[]</paragraph><paragraph>678</paragraph>' );
  455. editor.execute( 'undo' );
  456. output( '<paragraph>12345</paragraph><paragraph>67[]</paragraph><paragraph>8</paragraph>' );
  457. editor.execute( 'undo' );
  458. output( '<paragraph>123[]</paragraph><paragraph>45</paragraph><paragraph>67</paragraph><paragraph>8</paragraph>' );
  459. editor.execute( 'undo' );
  460. output( '<paragraph>123</paragraph><paragraph>45[]67</paragraph><paragraph>8</paragraph>' );
  461. editor.execute( 'undo' );
  462. output( '<paragraph>123</paragraph><paragraph>4567[]8</paragraph>' );
  463. editor.execute( 'undo' );
  464. output( '<paragraph>123[]45678</paragraph>' );
  465. undoDisabled();
  466. editor.execute( 'redo' );
  467. output( '<paragraph>123[]</paragraph><paragraph>45678</paragraph>' );
  468. editor.execute( 'redo' );
  469. output( '<paragraph>123</paragraph><paragraph>4567[]</paragraph><paragraph>8</paragraph>' );
  470. editor.execute( 'redo' );
  471. output( '<paragraph>123</paragraph><paragraph>45[]</paragraph><paragraph>67</paragraph><paragraph>8</paragraph>' );
  472. editor.execute( 'redo' );
  473. output( '<paragraph>123[]45</paragraph><paragraph>67</paragraph><paragraph>8</paragraph>' );
  474. editor.execute( 'redo' );
  475. output( '<paragraph>12345</paragraph><paragraph>67[]8</paragraph>' );
  476. editor.execute( 'redo' );
  477. output( '<paragraph>12345[]678</paragraph>' );
  478. redoDisabled();
  479. } );
  480. it( 'split, split, merge, split, merge (different order)', () => {
  481. input( '<paragraph>12345678</paragraph>' );
  482. split( [ 0, 3 ] );
  483. output( '<paragraph>123</paragraph><paragraph>[]45678</paragraph>' );
  484. split( [ 1, 2 ] );
  485. output( '<paragraph>123</paragraph><paragraph>45</paragraph><paragraph>[]678</paragraph>' );
  486. merge( [ 1 ] );
  487. output( '<paragraph>123[]45</paragraph><paragraph>678</paragraph>' );
  488. split( [ 1, 1 ] );
  489. output( '<paragraph>12345</paragraph><paragraph>6</paragraph><paragraph>[]78</paragraph>' );
  490. merge( [ 1 ] );
  491. output( '<paragraph>12345[]6</paragraph><paragraph>78</paragraph>' );
  492. editor.execute( 'undo' );
  493. output( '<paragraph>12345[]</paragraph><paragraph>6</paragraph><paragraph>78</paragraph>' );
  494. editor.execute( 'undo' );
  495. output( '<paragraph>12345</paragraph><paragraph>6[]78</paragraph>' );
  496. editor.execute( 'undo' );
  497. output( '<paragraph>123[]</paragraph><paragraph>45</paragraph><paragraph>678</paragraph>' );
  498. editor.execute( 'undo' );
  499. output( '<paragraph>123</paragraph><paragraph>45[]678</paragraph>' );
  500. editor.execute( 'undo' );
  501. output( '<paragraph>123[]45678</paragraph>' );
  502. undoDisabled();
  503. editor.execute( 'redo' );
  504. output( '<paragraph>123[]</paragraph><paragraph>45678</paragraph>' );
  505. editor.execute( 'redo' );
  506. output( '<paragraph>123</paragraph><paragraph>45[]</paragraph><paragraph>678</paragraph>' );
  507. editor.execute( 'redo' );
  508. output( '<paragraph>123[]45</paragraph><paragraph>678</paragraph>' );
  509. editor.execute( 'redo' );
  510. output( '<paragraph>12345</paragraph><paragraph>6[]</paragraph><paragraph>78</paragraph>' );
  511. editor.execute( 'redo' );
  512. output( '<paragraph>12345[]6</paragraph><paragraph>78</paragraph>' );
  513. redoDisabled();
  514. } );
  515. it( 'split, remove, split, merge, merge', () => {
  516. input( '<paragraph>12345678</paragraph>' );
  517. split( [ 0, 3 ] );
  518. output( '<paragraph>123</paragraph><paragraph>[]45678</paragraph>' );
  519. remove( [ 1, 4 ] );
  520. remove( [ 1, 3 ] );
  521. output( '<paragraph>123</paragraph><paragraph>45[]8</paragraph>' );
  522. split( [ 1, 1 ] );
  523. output( '<paragraph>123</paragraph><paragraph>4</paragraph><paragraph>[]58</paragraph>' );
  524. merge( [ 1 ] );
  525. output( '<paragraph>123[]4</paragraph><paragraph>58</paragraph>' );
  526. merge( [ 1 ] );
  527. output( '<paragraph>1234[]58</paragraph>' );
  528. editor.execute( 'undo' );
  529. output( '<paragraph>1234[]</paragraph><paragraph>58</paragraph>' );
  530. editor.execute( 'undo' );
  531. output( '<paragraph>123[]</paragraph><paragraph>4</paragraph><paragraph>58</paragraph>' );
  532. editor.execute( 'undo' );
  533. output( '<paragraph>123</paragraph><paragraph>4[]58</paragraph>' );
  534. editor.execute( 'undo' );
  535. output( '<paragraph>123</paragraph><paragraph>4567[]8</paragraph>' );
  536. editor.execute( 'undo' );
  537. output( '<paragraph>123[]45678</paragraph>' );
  538. undoDisabled();
  539. editor.execute( 'redo' );
  540. output( '<paragraph>123[]</paragraph><paragraph>45678</paragraph>' );
  541. editor.execute( 'redo' );
  542. output( '<paragraph>123</paragraph><paragraph>45[]8</paragraph>' );
  543. editor.execute( 'redo' );
  544. output( '<paragraph>123</paragraph><paragraph>4[]</paragraph><paragraph>58</paragraph>' );
  545. editor.execute( 'redo' );
  546. output( '<paragraph>123[]4</paragraph><paragraph>58</paragraph>' );
  547. editor.execute( 'redo' );
  548. output( '<paragraph>1234[]58</paragraph>' );
  549. redoDisabled();
  550. } );
  551. it( 'split, typing, split, merge, merge', () => {
  552. input( '<paragraph>12345678</paragraph>' );
  553. split( [ 0, 3 ] );
  554. output( '<paragraph>123</paragraph><paragraph>[]45678</paragraph>' );
  555. type( [ 1, 4 ], 'x' );
  556. type( [ 1, 5 ], 'y' );
  557. output( '<paragraph>123</paragraph><paragraph>4567xy[]8</paragraph>' );
  558. split( [ 1, 2 ] );
  559. output( '<paragraph>123</paragraph><paragraph>45</paragraph><paragraph>[]67xy8</paragraph>' );
  560. merge( [ 1 ] );
  561. output( '<paragraph>123[]45</paragraph><paragraph>67xy8</paragraph>' );
  562. merge( [ 1 ] );
  563. output( '<paragraph>12345[]67xy8</paragraph>' );
  564. editor.execute( 'undo' );
  565. output( '<paragraph>12345[]</paragraph><paragraph>67xy8</paragraph>' );
  566. editor.execute( 'undo' );
  567. output( '<paragraph>123[]</paragraph><paragraph>45</paragraph><paragraph>67xy8</paragraph>' );
  568. editor.execute( 'undo' );
  569. output( '<paragraph>123</paragraph><paragraph>45[]67xy8</paragraph>' );
  570. editor.execute( 'undo' );
  571. output( '<paragraph>123</paragraph><paragraph>4567[]8</paragraph>' );
  572. editor.execute( 'undo' );
  573. output( '<paragraph>123[]45678</paragraph>' );
  574. undoDisabled();
  575. editor.execute( 'redo' );
  576. output( '<paragraph>123[]</paragraph><paragraph>45678</paragraph>' );
  577. editor.execute( 'redo' );
  578. output( '<paragraph>123</paragraph><paragraph>4567xy[]8</paragraph>' );
  579. editor.execute( 'redo' );
  580. output( '<paragraph>123</paragraph><paragraph>45[]</paragraph><paragraph>67xy8</paragraph>' );
  581. editor.execute( 'redo' );
  582. output( '<paragraph>123[]45</paragraph><paragraph>67xy8</paragraph>' );
  583. editor.execute( 'redo' );
  584. output( '<paragraph>12345[]67xy8</paragraph>' );
  585. redoDisabled();
  586. } );
  587. } );
  588. describe( 'other reported cases', () => {
  589. // ckeditor5-engine#t/1051
  590. it( 'rename leaks to other elements on undo #1', () => {
  591. input( '<heading1>[]Foo</heading1><paragraph>Bar</paragraph>' );
  592. model.change( writer => {
  593. writer.rename( root.getChild( 0 ), 'paragraph' );
  594. } );
  595. output( '<paragraph>[]Foo</paragraph><paragraph>Bar</paragraph>' );
  596. model.change( writer => {
  597. writer.split( writer.createPositionAt( root.getChild( 0 ), 1 ) );
  598. } );
  599. output( '<paragraph>[]F</paragraph><paragraph>oo</paragraph><paragraph>Bar</paragraph>' );
  600. model.change( writer => {
  601. writer.merge( writer.createPositionAt( root, 2 ) );
  602. } );
  603. output( '<paragraph>[]F</paragraph><paragraph>ooBar</paragraph>' );
  604. editor.execute( 'undo' );
  605. output( '<paragraph>[]F</paragraph><paragraph>oo</paragraph><paragraph>Bar</paragraph>' );
  606. editor.execute( 'undo' );
  607. output( '<paragraph>[]Foo</paragraph><paragraph>Bar</paragraph>' );
  608. editor.execute( 'undo' );
  609. output( '<heading1>[]Foo</heading1><paragraph>Bar</paragraph>' );
  610. } );
  611. // Similar issue that bases on the same error as above, however here we first merge (above we first split).
  612. it( 'rename leaks to other elements on undo #2', () => {
  613. input( '<heading1>[]Foo</heading1><paragraph>Bar</paragraph>' );
  614. model.change( writer => {
  615. writer.rename( root.getChild( 0 ), 'heading2' );
  616. } );
  617. output( '<heading2>[]Foo</heading2><paragraph>Bar</paragraph>' );
  618. model.change( writer => {
  619. writer.merge( writer.createPositionAt( root, 1 ) );
  620. } );
  621. output( '<heading2>[]FooBar</heading2>' );
  622. editor.execute( 'undo' );
  623. output( '<heading2>[]Foo</heading2><paragraph>Bar</paragraph>' );
  624. editor.execute( 'undo' );
  625. output( '<heading1>[]Foo</heading1><paragraph>Bar</paragraph>' );
  626. } );
  627. // Reverse issue, this time first operation is merge and then rename.
  628. it( 'merge, rename, undo, undo is correct', () => {
  629. input( '<heading1>[]Foo</heading1><paragraph>Bar</paragraph>' );
  630. model.change( writer => {
  631. writer.merge( writer.createPositionAt( root, 1 ) );
  632. } );
  633. output( '<heading1>[]FooBar</heading1>' );
  634. model.change( writer => {
  635. writer.rename( root.getChild( 0 ), 'heading2' );
  636. } );
  637. output( '<heading2>[]FooBar</heading2>' );
  638. editor.execute( 'undo' );
  639. output( '<heading1>[]FooBar</heading1>' );
  640. editor.execute( 'undo' );
  641. output( '<heading1>[]Foo</heading1><paragraph>Bar</paragraph>' );
  642. } );
  643. // ckeditor5-engine#t/1053
  644. it( 'wrap, split, undo, undo is correct', () => {
  645. // Add a "div feature".
  646. model.schema.register( 'div', {
  647. allowWhere: '$block',
  648. allowContentOf: '$root'
  649. } );
  650. editor.conversion.for( 'downcast' ).elementToElement( { model: 'div', view: 'div' } );
  651. editor.conversion.for( 'upcast' ).elementToElement( { model: 'div', view: 'div' } );
  652. input( '<paragraph>[]Foo</paragraph><paragraph>Bar</paragraph>' );
  653. model.change( writer => {
  654. writer.wrap( writer.createRangeIn( root ), 'div' );
  655. } );
  656. output( '<div><paragraph>[]Foo</paragraph><paragraph>Bar</paragraph></div>' );
  657. model.change( writer => {
  658. writer.split( writer.createPositionFromPath( root, [ 0, 0, 1 ] ) );
  659. } );
  660. output( '<div><paragraph>[]F</paragraph><paragraph>oo</paragraph><paragraph>Bar</paragraph></div>' );
  661. editor.execute( 'undo' );
  662. output( '<div><paragraph>[]Foo</paragraph><paragraph>Bar</paragraph></div>' );
  663. editor.execute( 'undo' );
  664. output( '<paragraph>[]Foo</paragraph><paragraph>Bar</paragraph>' );
  665. } );
  666. // ckeditor5-engine#t/1055
  667. it( 'selection attribute setting: split, bold, merge, undo, undo, undo', () => {
  668. input( '<paragraph>Foo[]</paragraph><paragraph>Bar</paragraph>' );
  669. editor.execute( 'enter' );
  670. output( '<paragraph>Foo</paragraph><paragraph>[]</paragraph><paragraph>Bar</paragraph>' );
  671. editor.execute( 'bold' );
  672. output(
  673. '<paragraph>Foo</paragraph>' +
  674. '<paragraph selection:bold="true"><$text bold="true">[]</$text></paragraph>' +
  675. '<paragraph>Bar</paragraph>'
  676. );
  677. editor.execute( 'forwardDelete' );
  678. output( '<paragraph>Foo</paragraph><paragraph>[]Bar</paragraph>' );
  679. editor.execute( 'undo' );
  680. output(
  681. '<paragraph>Foo</paragraph>' +
  682. '<paragraph selection:bold="true"><$text bold="true">[]</$text></paragraph>' +
  683. '<paragraph>Bar</paragraph>'
  684. );
  685. editor.execute( 'undo' );
  686. output( '<paragraph>Foo</paragraph><paragraph>[]</paragraph><paragraph>Bar</paragraph>' );
  687. editor.execute( 'undo' );
  688. output( '<paragraph>Foo[]</paragraph><paragraph>Bar</paragraph>' );
  689. } );
  690. // https://github.com/ckeditor/ckeditor5-undo/issues/65#issuecomment-323682195
  691. it( 'undoing split after the element created by split has been removed', () => {
  692. input( '<paragraph>Foo[]bar</paragraph>' );
  693. editor.execute( 'enter' );
  694. model.change( writer => {
  695. const range = writer.createRange(
  696. writer.createPositionFromPath( root, [ 0, 3 ] ),
  697. writer.createPositionFromPath( root, [ 1, 3 ] )
  698. );
  699. writer.setSelection( range );
  700. editor.execute( 'delete' );
  701. } );
  702. output( '<paragraph>Foo[]</paragraph>' );
  703. editor.execute( 'undo' );
  704. output( '<paragraph>Foo[</paragraph><paragraph>bar]</paragraph>' );
  705. editor.execute( 'undo' );
  706. output( '<paragraph>Foo[]bar</paragraph>' );
  707. } );
  708. } );
  709. describe( 'clipboard', () => {
  710. function pasteHtml( editor, html ) {
  711. editor.editing.view.document.fire( 'paste', {
  712. dataTransfer: createDataTransfer( { 'text/html': html } ),
  713. stopPropagation() {},
  714. preventDefault() {}
  715. } );
  716. }
  717. function createDataTransfer( data ) {
  718. return {
  719. getData( type ) {
  720. return data[ type ];
  721. },
  722. setData() {}
  723. };
  724. }
  725. // ckeditor5-engine#t/1065
  726. it( 'undo paste into non empty element should not throw and be correct', () => {
  727. model.change( () => {
  728. input( '<paragraph>Foo[]</paragraph>' );
  729. } );
  730. model.change( () => {
  731. pasteHtml( editor, '<p>a</p><p>b</p>' );
  732. } );
  733. output( '<paragraph>Fooa</paragraph><paragraph>b[]</paragraph>' );
  734. model.change( () => {
  735. pasteHtml( editor, '<p>c</p><p>d</p>' );
  736. } );
  737. output( '<paragraph>Fooa</paragraph><paragraph>bc</paragraph><paragraph>d[]</paragraph>' );
  738. editor.execute( 'undo' );
  739. output( '<paragraph>Fooa</paragraph><paragraph>b[]</paragraph>' );
  740. editor.execute( 'undo' );
  741. output( '<paragraph>Foo[]</paragraph>' );
  742. } );
  743. // ckeditor5#781
  744. it( 'cutting should not create empty undo step', () => {
  745. input( '<paragraph>Fo[oba]r</paragraph>' );
  746. editor.editing.view.document.fire( 'cut', {
  747. dataTransfer: createDataTransfer(),
  748. preventDefault() {},
  749. method: 'cut'
  750. } );
  751. editor.execute( 'undo' );
  752. output( '<paragraph>Fo[oba]r</paragraph>' );
  753. undoDisabled();
  754. } );
  755. } );
  756. describe( 'other edge cases', () => {
  757. it( 'deleteContent between two nodes', () => {
  758. input( '<paragraph>fo[o</paragraph><paragraph>b]ar</paragraph>' );
  759. editor.model.deleteContent( doc.selection );
  760. output( '<paragraph>fo[]ar</paragraph>' );
  761. editor.execute( 'undo' );
  762. output( '<paragraph>fo[o</paragraph><paragraph>b]ar</paragraph>' );
  763. } );
  764. // Related to ckeditor5-engine#891 and ckeditor5-list#51.
  765. it( 'change attribute of removed node then undo and redo', () => {
  766. input( '<paragraph></paragraph>' );
  767. const gy = doc.graveyard;
  768. const p = doc.getRoot().getChild( 0 );
  769. model.change( writer => {
  770. writer.remove( p );
  771. } );
  772. model.change( writer => {
  773. writer.setAttribute( 'bold', true, p );
  774. } );
  775. editor.execute( 'undo' );
  776. editor.execute( 'redo' );
  777. expect( p.root ).to.equal( gy );
  778. expect( p.getAttribute( 'bold' ) ).to.be.true;
  779. } );
  780. it( 'undo table cells merge', () => {
  781. input(
  782. '<table>' +
  783. '<tableRow>' +
  784. '<tableCell><paragraph>00</paragraph></tableCell>' +
  785. '[<tableCell><paragraph>01</paragraph></tableCell>]' +
  786. '[<tableCell><paragraph>02</paragraph></tableCell>]' +
  787. '<tableCell><paragraph>03</paragraph></tableCell>' +
  788. '</tableRow>' +
  789. '<tableRow>' +
  790. '<tableCell><paragraph>10</paragraph></tableCell>' +
  791. '[<tableCell><paragraph>11</paragraph></tableCell>]' +
  792. '[<tableCell><paragraph>12</paragraph></tableCell>]' +
  793. '<tableCell><paragraph>13</paragraph></tableCell>' +
  794. '</tableRow>' +
  795. '<tableRow>' +
  796. '<tableCell><paragraph>20</paragraph></tableCell>' +
  797. '<tableCell><paragraph>21</paragraph></tableCell>' +
  798. '<tableCell><paragraph>22</paragraph></tableCell>' +
  799. '<tableCell><paragraph>23</paragraph></tableCell>' +
  800. '</tableRow>' +
  801. '</table>'
  802. );
  803. editor.execute( 'mergeTableCells' );
  804. output(
  805. '<table>' +
  806. '<tableRow>' +
  807. '<tableCell><paragraph>00</paragraph></tableCell>' +
  808. '<tableCell colspan="2" rowspan="2">' +
  809. '<paragraph>[01</paragraph>' +
  810. '<paragraph>02</paragraph>' +
  811. '<paragraph>11</paragraph>' +
  812. '<paragraph>12]</paragraph>' +
  813. '</tableCell>' +
  814. '<tableCell><paragraph>03</paragraph></tableCell>' +
  815. '</tableRow>' +
  816. '<tableRow>' +
  817. '<tableCell><paragraph>10</paragraph></tableCell>' +
  818. '<tableCell><paragraph>13</paragraph></tableCell>' +
  819. '</tableRow>' +
  820. '<tableRow>' +
  821. '<tableCell><paragraph>20</paragraph></tableCell>' +
  822. '<tableCell><paragraph>21</paragraph></tableCell>' +
  823. '<tableCell><paragraph>22</paragraph></tableCell>' +
  824. '<tableCell><paragraph>23</paragraph></tableCell>' +
  825. '</tableRow>' +
  826. '</table>'
  827. );
  828. editor.execute( 'undo' );
  829. output(
  830. '<table>' +
  831. '<tableRow>' +
  832. '<tableCell><paragraph>00</paragraph></tableCell>' +
  833. '[<tableCell><paragraph>01</paragraph></tableCell>]' +
  834. '[<tableCell><paragraph>02</paragraph></tableCell>]' +
  835. '<tableCell><paragraph>03</paragraph></tableCell>' +
  836. '</tableRow>' +
  837. '<tableRow>' +
  838. '<tableCell><paragraph>10</paragraph></tableCell>' +
  839. '[<tableCell><paragraph>11</paragraph></tableCell>]' +
  840. '[<tableCell><paragraph>12</paragraph></tableCell>]' +
  841. '<tableCell><paragraph>13</paragraph></tableCell>' +
  842. '</tableRow>' +
  843. '<tableRow>' +
  844. '<tableCell><paragraph>20</paragraph></tableCell>' +
  845. '<tableCell><paragraph>21</paragraph></tableCell>' +
  846. '<tableCell><paragraph>22</paragraph></tableCell>' +
  847. '<tableCell><paragraph>23</paragraph></tableCell>' +
  848. '</tableRow>' +
  849. '</table>'
  850. );
  851. } );
  852. } );
  853. it( 'postfixers should not add another undo step when fixing undo changes', () => {
  854. input( '<paragraph>[]</paragraph>' );
  855. const paragraph = root.getChild( 0 );
  856. // 1. Step - add text and marker to the paragraph.
  857. model.change( writer => {
  858. writer.appendText( 'foo', paragraph );
  859. writer.addMarker( 'marker', { range: writer.createRangeIn( paragraph ), usingOperation: true } );
  860. } );
  861. // 2. Step - remove text from paragraph.
  862. model.change( writer => {
  863. writer.remove( writer.createRangeIn( paragraph ) );
  864. } );
  865. // Register post fixer to remove marker from non-empty paragraph.
  866. model.document.registerPostFixer( writer => {
  867. const hasMarker = model.markers.has( 'marker' );
  868. const isEmpty = paragraph.childCount === 0;
  869. // Remove marker when paragraph is empty.
  870. if ( hasMarker && !isEmpty ) {
  871. writer.removeMarker( 'marker' );
  872. return true;
  873. }
  874. return false;
  875. } );
  876. editor.execute( 'undo' );
  877. // Check if postfixer changes are executed together with undo and there is no additional undo steps.
  878. expect( model.markers.has( 'marker' ) ).to.be.false;
  879. expect( editor.commands.get( 'undo' )._stack.length ).to.equal( 1 );
  880. output( '<paragraph>foo[]</paragraph>' );
  881. } );
  882. function split( path ) {
  883. setSelection( path.slice(), path.slice() );
  884. editor.execute( 'enter' );
  885. }
  886. function merge( path ) {
  887. const selPath = path.slice();
  888. selPath.push( 0 );
  889. setSelection( selPath, selPath.slice() );
  890. editor.execute( 'delete' );
  891. }
  892. function type( path, text ) {
  893. setSelection( path.slice(), path.slice() );
  894. editor.execute( 'input', { text } );
  895. }
  896. function remove( path ) {
  897. setSelection( path.slice(), path.slice() );
  898. editor.execute( 'delete' );
  899. }
  900. } );