undoengine-integration.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
  6. import Range from '@ckeditor/ckeditor5-engine/src/model/range';
  7. import Position from '@ckeditor/ckeditor5-engine/src/model/position';
  8. import Element from '@ckeditor/ckeditor5-engine/src/model/element';
  9. import UndoEngine from '../src/undoengine';
  10. import DeleteCommand from '@ckeditor/ckeditor5-typing/src/deletecommand';
  11. import InputCommand from '@ckeditor/ckeditor5-typing/src/inputcommand';
  12. import EnterCommand from '@ckeditor/ckeditor5-enter/src/entercommand';
  13. import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  14. describe( 'UndoEngine integration', () => {
  15. let editor, doc, root;
  16. beforeEach( () => {
  17. return ModelTestEditor.create( { plugins: [ UndoEngine ] } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. editor.commands.add( 'delete', new DeleteCommand( editor, 'backward' ) );
  21. editor.commands.add( 'enter', new EnterCommand( editor ) );
  22. editor.commands.add( 'input', new InputCommand( editor, 5 ) );
  23. doc = editor.document;
  24. doc.schema.registerItem( 'p', '$block' );
  25. root = doc.getRoot();
  26. } );
  27. } );
  28. function setSelection( pathA, pathB ) {
  29. doc.selection.setRanges( [ new Range( new Position( root, pathA ), new Position( root, pathB ) ) ] );
  30. }
  31. function input( input ) {
  32. setData( doc, input );
  33. }
  34. function output( output ) {
  35. expect( getData( doc ) ).to.equal( output );
  36. }
  37. function undoDisabled() {
  38. expect( editor.commands.get( 'undo' ).isEnabled ).to.be.false;
  39. }
  40. function redoDisabled() {
  41. expect( editor.commands.get( 'redo' ).isEnabled ).to.be.false;
  42. }
  43. describe( 'adding and removing content', () => {
  44. it( 'add and undo', () => {
  45. input( '<p>fo[]o</p><p>bar</p>' );
  46. doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
  47. output( '<p>fozzz[]o</p><p>bar</p>' );
  48. editor.execute( 'undo' );
  49. output( '<p>fo[]o</p><p>bar</p>' );
  50. undoDisabled();
  51. } );
  52. it( 'multiple adding and undo', () => {
  53. input( '<p>fo[]o</p><p>bar</p>' );
  54. doc.batch()
  55. .insert( doc.selection.getFirstPosition(), 'zzz' )
  56. .insert( new Position( root, [ 1, 0 ] ), 'xxx' );
  57. output( '<p>fozzz[]o</p><p>xxxbar</p>' );
  58. setSelection( [ 1, 0 ], [ 1, 0 ] );
  59. doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
  60. output( '<p>fozzzo</p><p>yyy[]xxxbar</p>' );
  61. editor.execute( 'undo' );
  62. output( '<p>fozzzo</p><p>[]xxxbar</p>' );
  63. editor.execute( 'undo' );
  64. output( '<p>fo[]o</p><p>bar</p>' );
  65. undoDisabled();
  66. } );
  67. it( 'multiple adding mixed with undo', () => {
  68. input( '<p>fo[]o</p><p>bar</p>' );
  69. doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
  70. output( '<p>fozzz[]o</p><p>bar</p>' );
  71. setSelection( [ 1, 0 ], [ 1, 0 ] );
  72. doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
  73. output( '<p>fozzzo</p><p>yyy[]bar</p>' );
  74. editor.execute( 'undo' );
  75. output( '<p>fozzzo</p><p>[]bar</p>' );
  76. setSelection( [ 0, 0 ], [ 0, 0 ] );
  77. doc.batch().insert( doc.selection.getFirstPosition(), 'xxx' );
  78. output( '<p>xxx[]fozzzo</p><p>bar</p>' );
  79. editor.execute( 'undo' );
  80. output( '<p>[]fozzzo</p><p>bar</p>' );
  81. editor.execute( 'undo' );
  82. output( '<p>fo[]o</p><p>bar</p>' );
  83. undoDisabled();
  84. } );
  85. it( 'multiple remove and undo', () => {
  86. input( '<p>[]foo</p><p>bar</p>' );
  87. doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
  88. output( '<p>[]o</p><p>bar</p>' );
  89. setSelection( [ 1, 1 ], [ 1, 1 ] );
  90. doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
  91. output( '<p>o</p><p>b[]</p>' );
  92. editor.execute( 'undo' );
  93. // Here is an edge case that selection could be before or after `ar`.
  94. output( '<p>o</p><p>bar[]</p>' );
  95. editor.execute( 'undo' );
  96. // As above.
  97. output( '<p>fo[]o</p><p>bar</p>' );
  98. undoDisabled();
  99. } );
  100. it( 'add and remove different parts and undo', () => {
  101. input( '<p>fo[]o</p><p>bar</p>' );
  102. doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
  103. output( '<p>fozzz[]o</p><p>bar</p>' );
  104. setSelection( [ 1, 2 ], [ 1, 2 ] );
  105. doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 1, 1 ] ), 1 ) );
  106. output( '<p>fozzzo</p><p>b[]r</p>' );
  107. editor.execute( 'undo' );
  108. output( '<p>fozzzo</p><p>ba[]r</p>' );
  109. editor.execute( 'undo' );
  110. output( '<p>fo[]o</p><p>bar</p>' );
  111. undoDisabled();
  112. } );
  113. it( 'add and remove same part and undo', () => {
  114. input( '<p>fo[]o</p><p>bar</p>' );
  115. doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
  116. output( '<p>fozzz[]o</p><p>bar</p>' );
  117. doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 0, 2 ] ), 3 ) );
  118. output( '<p>fo[]o</p><p>bar</p>' );
  119. editor.execute( 'undo' );
  120. output( '<p>fozzz[]o</p><p>bar</p>' );
  121. editor.execute( 'undo' );
  122. output( '<p>fo[]o</p><p>bar</p>' );
  123. undoDisabled();
  124. } );
  125. } );
  126. describe( 'moving', () => {
  127. it( 'move same content twice then undo', () => {
  128. input( '<p>f[o]z</p><p>bar</p>' );
  129. doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) );
  130. output( '<p>fz</p><p>[o]bar</p>' );
  131. doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0, 2 ] ) );
  132. output( '<p>fz[o]</p><p>bar</p>' );
  133. editor.execute( 'undo' );
  134. output( '<p>fz</p><p>[o]bar</p>' );
  135. editor.execute( 'undo' );
  136. output( '<p>f[o]z</p><p>bar</p>' );
  137. undoDisabled();
  138. } );
  139. it( 'move content and new parent then undo', () => {
  140. input( '<p>f[o]z</p><p>bar</p>' );
  141. doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) );
  142. output( '<p>fz</p><p>[o]bar</p>' );
  143. setSelection( [ 1 ], [ 2 ] );
  144. doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
  145. output( '[<p>obar</p>]<p>fz</p>' );
  146. editor.execute( 'undo' );
  147. output( '<p>fz</p>[<p>obar</p>]' );
  148. editor.execute( 'undo' );
  149. output( '<p>f[o]z</p><p>bar</p>' );
  150. undoDisabled();
  151. } );
  152. } );
  153. describe( 'attributes with other', () => {
  154. it( 'attributes then insert inside then undo', () => {
  155. input( '<p>fo[ob]ar</p>' );
  156. doc.batch().setAttribute( doc.selection.getFirstRange(), 'bold', true );
  157. output( '<p>fo[<$text bold="true">ob</$text>]ar</p>' );
  158. setSelection( [ 0, 3 ], [ 0, 3 ] );
  159. doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
  160. output( '<p>fo<$text bold="true">o</$text>zzz<$text bold="true">[]b</$text>ar</p>' );
  161. expect( doc.selection.getAttribute( 'bold' ) ).to.true;
  162. editor.execute( 'undo' );
  163. output( '<p>fo<$text bold="true">o[]b</$text>ar</p>' );
  164. expect( doc.selection.getAttribute( 'bold' ) ).to.true;
  165. editor.execute( 'undo' );
  166. output( '<p>fo[ob]ar</p>' );
  167. undoDisabled();
  168. } );
  169. } );
  170. describe( 'wrapping, unwrapping, merging, splitting', () => {
  171. it( 'wrap and undo', () => {
  172. doc.schema.allow( { name: '$text', inside: '$root' } );
  173. input( 'fo[zb]ar' );
  174. doc.batch().wrap( doc.selection.getFirstRange(), 'p' );
  175. output( 'fo<p>[zb]</p>ar' );
  176. editor.execute( 'undo' );
  177. output( 'fo[zb]ar' );
  178. undoDisabled();
  179. } );
  180. it( 'wrap, move and undo', () => {
  181. doc.schema.allow( { name: '$text', inside: '$root' } );
  182. input( 'fo[zb]ar' );
  183. doc.batch().wrap( doc.selection.getFirstRange(), 'p' );
  184. // Would be better if selection was inside P.
  185. output( 'fo<p>[zb]</p>ar' );
  186. setSelection( [ 2, 0 ], [ 2, 1 ] );
  187. doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
  188. output( '[z]fo<p>b</p>ar' );
  189. editor.execute( 'undo' );
  190. output( 'fo<p>[z]b</p>ar' );
  191. editor.execute( 'undo' );
  192. output( 'fo[zb]ar' );
  193. undoDisabled();
  194. } );
  195. it( 'unwrap and undo', () => {
  196. input( '<p>foo[]bar</p>' );
  197. doc.batch().unwrap( doc.selection.getFirstPosition().parent );
  198. output( 'foo[]bar' );
  199. editor.execute( 'undo' );
  200. output( '<p>foo[]bar</p>' );
  201. undoDisabled();
  202. } );
  203. it( 'merge and undo', () => {
  204. input( '<p>foo</p><p>[]bar</p>' );
  205. doc.batch().merge( new Position( root, [ 1 ] ) );
  206. // Because selection is stuck with <p> it ends up in graveyard. We have to manually move it to correct node.
  207. setSelection( [ 0, 3 ], [ 0, 3 ] );
  208. output( '<p>foo[]bar</p>' );
  209. editor.execute( 'undo' );
  210. output( '<p>foo</p><p>bar[]</p>' );
  211. undoDisabled();
  212. } );
  213. it( 'split and undo', () => {
  214. input( '<p>foo[]bar</p>' );
  215. doc.batch().split( doc.selection.getFirstPosition() );
  216. // Because selection is stuck with <p> it ends up in wrong node. We have to manually move it to correct node.
  217. setSelection( [ 1, 0 ], [ 1, 0 ] );
  218. output( '<p>foo</p><p>[]bar</p>' );
  219. editor.execute( 'undo' );
  220. output( '<p>foobar[]</p>' );
  221. undoDisabled();
  222. } );
  223. } );
  224. // Restoring selection in those examples may be completely off.
  225. describe( 'multiple enters, deletes and typing', () => {
  226. function split( path ) {
  227. setSelection( path.slice(), path.slice() );
  228. editor.execute( 'enter' );
  229. }
  230. function merge( path ) {
  231. const selPath = path.slice();
  232. selPath.push( 0 );
  233. setSelection( selPath, selPath.slice() );
  234. editor.execute( 'delete' );
  235. }
  236. function type( path, text ) {
  237. setSelection( path.slice(), path.slice() );
  238. editor.execute( 'input', { text } );
  239. }
  240. function remove( path ) {
  241. setSelection( path.slice(), path.slice() );
  242. editor.execute( 'delete' );
  243. }
  244. it( 'split, split, split', () => {
  245. input( '<p>12345678</p>' );
  246. split( [ 0, 3 ] );
  247. output( '<p>123</p><p>[]45678</p>' );
  248. split( [ 1, 4 ] );
  249. output( '<p>123</p><p>4567</p><p>[]8</p>' );
  250. split( [ 1, 2 ] );
  251. output( '<p>123</p><p>45</p><p>[]67</p><p>8</p>' );
  252. editor.execute( 'undo' );
  253. output( '<p>123</p><p>4567[]</p><p>8</p>' );
  254. editor.execute( 'undo' );
  255. output( '<p>123</p><p>45678[]</p>' );
  256. editor.execute( 'undo' );
  257. output( '<p>12345678[]</p>' );
  258. undoDisabled();
  259. editor.execute( 'redo' );
  260. output( '<p>123[]</p><p>45678</p>' );
  261. editor.execute( 'redo' );
  262. output( '<p>123</p><p>4567[]</p><p>8</p>' );
  263. editor.execute( 'redo' );
  264. output( '<p>123</p><p>45[]</p><p>67</p><p>8</p>' );
  265. redoDisabled();
  266. } );
  267. it( 'merge, merge, merge', () => {
  268. input( '<p>123</p><p>45</p><p>67</p><p>8</p>' );
  269. merge( [ 1 ] );
  270. output( '<p>123[]45</p><p>67</p><p>8</p>' );
  271. merge( [ 2 ] );
  272. output( '<p>12345</p><p>67[]8</p>' );
  273. merge( [ 1 ] );
  274. output( '<p>12345[]678</p>' );
  275. editor.execute( 'undo' );
  276. output( '<p>12345</p><p>678[]</p>' );
  277. editor.execute( 'undo' );
  278. output( '<p>12345</p><p>67</p><p>8[]</p>' );
  279. editor.execute( 'undo' );
  280. output( '<p>123</p><p>45[]</p><p>67</p><p>8</p>' );
  281. undoDisabled();
  282. editor.execute( 'redo' );
  283. output( '<p>12345[]</p><p>67</p><p>8</p>' );
  284. editor.execute( 'redo' );
  285. output( '<p>12345</p><p>678[]</p>' );
  286. editor.execute( 'redo' );
  287. output( '<p>1234567[]8</p>' );
  288. redoDisabled();
  289. } );
  290. it( 'split, merge, split, merge (same position)', () => {
  291. input( '<p>12345678</p>' );
  292. split( [ 0, 3 ] );
  293. output( '<p>123</p><p>[]45678</p>' );
  294. merge( [ 1 ] );
  295. output( '<p>123[]45678</p>' );
  296. split( [ 0, 3 ] );
  297. output( '<p>123</p><p>[]45678</p>' );
  298. merge( [ 1 ] );
  299. output( '<p>123[]45678</p>' );
  300. editor.execute( 'undo' );
  301. output( '<p>123</p><p>45678[]</p>' );
  302. editor.execute( 'undo' );
  303. output( '<p>12345678[]</p>' );
  304. editor.execute( 'undo' );
  305. output( '<p>123</p><p>45678[]</p>' );
  306. editor.execute( 'undo' );
  307. output( '<p>12345678[]</p>' );
  308. undoDisabled();
  309. editor.execute( 'redo' );
  310. output( '<p>123[]</p><p>45678</p>' );
  311. editor.execute( 'redo' );
  312. output( '<p>12345678[]</p>' );
  313. editor.execute( 'redo' );
  314. output( '<p>123[]</p><p>45678</p>' );
  315. editor.execute( 'redo' );
  316. output( '<p>12345678[]</p>' );
  317. redoDisabled();
  318. } );
  319. it( 'split, split, split, merge, merge, merge', () => {
  320. input( '<p>12345678</p>' );
  321. split( [ 0, 3 ] );
  322. output( '<p>123</p><p>[]45678</p>' );
  323. split( [ 1, 4 ] );
  324. output( '<p>123</p><p>4567</p><p>[]8</p>' );
  325. split( [ 1, 2 ] );
  326. output( '<p>123</p><p>45</p><p>[]67</p><p>8</p>' );
  327. merge( [ 1 ] );
  328. output( '<p>123[]45</p><p>67</p><p>8</p>' );
  329. merge( [ 2 ] );
  330. output( '<p>12345</p><p>67[]8</p>' );
  331. merge( [ 1 ] );
  332. output( '<p>12345[]678</p>' );
  333. editor.execute( 'undo' );
  334. output( '<p>12345</p><p>678[]</p>' );
  335. editor.execute( 'undo' );
  336. output( '<p>12345</p><p>67</p><p>8[]</p>' );
  337. editor.execute( 'undo' );
  338. output( '<p>123</p><p>45[]</p><p>67</p><p>8</p>' );
  339. editor.execute( 'undo' );
  340. output( '<p>123</p><p>4567[]</p><p>8</p>' );
  341. editor.execute( 'undo' );
  342. output( '<p>123</p><p>45678[]</p>' );
  343. editor.execute( 'undo' );
  344. output( '<p>12345678[]</p>' );
  345. undoDisabled();
  346. editor.execute( 'redo' );
  347. output( '<p>123[]</p><p>45678</p>' );
  348. editor.execute( 'redo' );
  349. output( '<p>123</p><p>4567[]</p><p>8</p>' );
  350. editor.execute( 'redo' );
  351. output( '<p>123</p><p>45[]</p><p>67</p><p>8</p>' );
  352. editor.execute( 'redo' );
  353. output( '<p>12345[]</p><p>67</p><p>8</p>' );
  354. editor.execute( 'redo' );
  355. output( '<p>12345</p><p>678[]</p>' );
  356. editor.execute( 'redo' );
  357. output( '<p>1234567[]8</p>' );
  358. redoDisabled();
  359. } );
  360. it( 'split, split, merge, split, merge (different order)', () => {
  361. input( '<p>12345678</p>' );
  362. split( [ 0, 3 ] );
  363. output( '<p>123</p><p>[]45678</p>' );
  364. split( [ 1, 2 ] );
  365. output( '<p>123</p><p>45</p><p>[]678</p>' );
  366. merge( [ 1 ] );
  367. output( '<p>123[]45</p><p>678</p>' );
  368. split( [ 1, 1 ] );
  369. output( '<p>12345</p><p>6</p><p>[]78</p>' );
  370. merge( [ 1 ] );
  371. output( '<p>12345[]6</p><p>78</p>' );
  372. editor.execute( 'undo' );
  373. output( '<p>12345</p><p>6[]</p><p>78</p>' );
  374. editor.execute( 'undo' );
  375. output( '<p>12345</p><p>678[]</p>' );
  376. editor.execute( 'undo' );
  377. output( '<p>123</p><p>45[]</p><p>678</p>' );
  378. editor.execute( 'undo' );
  379. output( '<p>123</p><p>45678[]</p>' );
  380. editor.execute( 'undo' );
  381. output( '<p>12345678[]</p>' );
  382. undoDisabled();
  383. editor.execute( 'redo' );
  384. output( '<p>123[]</p><p>45678</p>' );
  385. editor.execute( 'redo' );
  386. output( '<p>123</p><p>45[]</p><p>678</p>' );
  387. editor.execute( 'redo' );
  388. output( '<p>12345[]</p><p>678</p>' );
  389. editor.execute( 'redo' );
  390. output( '<p>12345</p><p>6[]</p><p>78</p>' );
  391. editor.execute( 'redo' );
  392. output( '<p>123456[]</p><p>78</p>' );
  393. redoDisabled();
  394. } );
  395. it( 'split, remove, split, merge, merge', () => {
  396. input( '<p>12345678</p>' );
  397. split( [ 0, 3 ] );
  398. output( '<p>123</p><p>[]45678</p>' );
  399. remove( [ 1, 4 ] );
  400. remove( [ 1, 3 ] );
  401. output( '<p>123</p><p>45[]8</p>' );
  402. split( [ 1, 1 ] );
  403. output( '<p>123</p><p>4</p><p>[]58</p>' );
  404. merge( [ 1 ] );
  405. output( '<p>123[]4</p><p>58</p>' );
  406. merge( [ 1 ] );
  407. output( '<p>1234[]58</p>' );
  408. editor.execute( 'undo' );
  409. output( '<p>1234</p><p>58[]</p>' );
  410. editor.execute( 'undo' );
  411. output( '<p>123</p><p>4[]</p><p>58</p>' );
  412. editor.execute( 'undo' );
  413. output( '<p>123</p><p>458[]</p>' );
  414. editor.execute( 'undo' );
  415. output( '<p>123</p><p>4567[]8</p>' );
  416. editor.execute( 'undo' );
  417. output( '<p>12345678[]</p>' );
  418. undoDisabled();
  419. editor.execute( 'redo' );
  420. output( '<p>123[]</p><p>45678</p>' );
  421. editor.execute( 'redo' );
  422. output( '<p>123</p><p>458[]</p>' );
  423. editor.execute( 'redo' );
  424. output( '<p>123</p><p>4[]</p><p>58</p>' );
  425. editor.execute( 'redo' );
  426. output( '<p>1234[]</p><p>58</p>' );
  427. editor.execute( 'redo' );
  428. output( '<p>12345[]8</p>' );
  429. redoDisabled();
  430. } );
  431. it( 'split, typing, split, merge, merge', () => {
  432. input( '<p>12345678</p>' );
  433. split( [ 0, 3 ] );
  434. output( '<p>123</p><p>[]45678</p>' );
  435. type( [ 1, 4 ], 'x' );
  436. type( [ 1, 5 ], 'y' );
  437. output( '<p>123</p><p>4567xy[]8</p>' );
  438. split( [ 1, 2 ] );
  439. output( '<p>123</p><p>45</p><p>[]67xy8</p>' );
  440. merge( [ 1 ] );
  441. output( '<p>123[]45</p><p>67xy8</p>' );
  442. merge( [ 1 ] );
  443. output( '<p>12345[]67xy8</p>' );
  444. editor.execute( 'undo' );
  445. output( '<p>12345</p><p>67xy8[]</p>' );
  446. editor.execute( 'undo' );
  447. output( '<p>123</p><p>45[]</p><p>67xy8</p>' );
  448. editor.execute( 'undo' );
  449. output( '<p>123</p><p>4567xy8[]</p>' );
  450. editor.execute( 'undo' );
  451. output( '<p>123</p><p>4567[]8</p>' );
  452. editor.execute( 'undo' );
  453. output( '<p>12345678[]</p>' );
  454. undoDisabled();
  455. editor.execute( 'redo' );
  456. output( '<p>123[]</p><p>45678</p>' );
  457. editor.execute( 'redo' );
  458. output( '<p>123</p><p>4567xy8[]</p>' );
  459. editor.execute( 'redo' );
  460. output( '<p>123</p><p>45[]</p><p>67xy8</p>' );
  461. editor.execute( 'redo' );
  462. output( '<p>12345[]</p><p>67xy8</p>' );
  463. editor.execute( 'redo' );
  464. output( '<p>1234567[]xy8</p>' );
  465. redoDisabled();
  466. } );
  467. } );
  468. describe( 'other edge cases', () => {
  469. it( 'deleteContent between two nodes', () => {
  470. input( '<p>fo[o</p><p>b]ar</p>' );
  471. editor.data.deleteContent( doc.selection, doc.batch() );
  472. output( '<p>fo[]ar</p>' );
  473. editor.execute( 'undo' );
  474. output( '<p>fo[o</p><p>b]ar</p>' );
  475. } );
  476. // Related to ckeditor5-engine#891 and ckeditor5-list#51.
  477. it( 'change attribute of removed node then undo and redo', () => {
  478. const gy = doc.graveyard;
  479. const batch = doc.batch();
  480. const p = new Element( 'p' );
  481. root.appendChildren( p );
  482. batch.remove( p );
  483. batch.setAttribute( p, 'bold', true );
  484. editor.execute( 'undo' );
  485. editor.execute( 'redo' );
  486. expect( p.root ).to.equal( gy );
  487. expect( p.getAttribute( 'bold' ) ).to.be.true;
  488. } );
  489. // Related to ckeditor5-engine#891.
  490. it( 'change attribute of removed node then undo and redo', () => {
  491. const gy = doc.graveyard;
  492. const batch = doc.batch();
  493. const p1 = new Element( 'p' );
  494. const p2 = new Element( 'p' );
  495. const p3 = new Element( 'p' );
  496. root.appendChildren( [ p1, p2 ] );
  497. batch.remove( p1 ).remove( p2 ).insert( new Position( root, [ 0 ] ), p3 );
  498. editor.execute( 'undo' );
  499. editor.execute( 'redo' );
  500. expect( p1.root ).to.equal( gy );
  501. expect( p2.root ).to.equal( gy );
  502. expect( p3.root ).to.equal( root );
  503. } );
  504. } );
  505. } );