|
@@ -9,6 +9,10 @@ import Position from '@ckeditor/ckeditor5-engine/src/model/position';
|
|
|
import Element from '@ckeditor/ckeditor5-engine/src/model/element';
|
|
import Element from '@ckeditor/ckeditor5-engine/src/model/element';
|
|
|
import UndoEngine from '../src/undoengine';
|
|
import UndoEngine from '../src/undoengine';
|
|
|
|
|
|
|
|
|
|
+import DeleteCommand from '@ckeditor/ckeditor5-typing/src/deletecommand';
|
|
|
|
|
+import InputCommand from '@ckeditor/ckeditor5-typing/src/inputcommand';
|
|
|
|
|
+import EnterCommand from '@ckeditor/ckeditor5-enter/src/entercommand';
|
|
|
|
|
+
|
|
|
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
|
|
|
|
|
describe( 'UndoEngine integration', () => {
|
|
describe( 'UndoEngine integration', () => {
|
|
@@ -18,6 +22,11 @@ describe( 'UndoEngine integration', () => {
|
|
|
return ModelTestEditor.create( { plugins: [ UndoEngine ] } )
|
|
return ModelTestEditor.create( { plugins: [ UndoEngine ] } )
|
|
|
.then( newEditor => {
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
editor = newEditor;
|
|
|
|
|
+
|
|
|
|
|
+ editor.commands.add( 'delete', new DeleteCommand( editor, 'backward' ) );
|
|
|
|
|
+ editor.commands.add( 'enter', new EnterCommand( editor ) );
|
|
|
|
|
+ editor.commands.add( 'input', new InputCommand( editor, 5 ) );
|
|
|
|
|
+
|
|
|
doc = editor.document;
|
|
doc = editor.document;
|
|
|
doc.schema.registerItem( 'p', '$block' );
|
|
doc.schema.registerItem( 'p', '$block' );
|
|
|
root = doc.getRoot();
|
|
root = doc.getRoot();
|
|
@@ -40,312 +49,676 @@ describe( 'UndoEngine integration', () => {
|
|
|
expect( editor.commands.get( 'undo' ).isEnabled ).to.be.false;
|
|
expect( editor.commands.get( 'undo' ).isEnabled ).to.be.false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- describe( 'UndoEngine integration', () => {
|
|
|
|
|
- describe( 'adding and removing content', () => {
|
|
|
|
|
- it( 'add and undo', () => {
|
|
|
|
|
- input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ function redoDisabled() {
|
|
|
|
|
+ expect( editor.commands.get( 'redo' ).isEnabled ).to.be.false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
|
|
- output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ describe( 'adding and removing content', () => {
|
|
|
|
|
+ it( 'add and undo', () => {
|
|
|
|
|
+ input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
|
|
+ output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- it( 'multiple adding and undo', () => {
|
|
|
|
|
- input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- doc.batch()
|
|
|
|
|
- .insert( doc.selection.getFirstPosition(), 'zzz' )
|
|
|
|
|
- .insert( new Position( root, [ 1, 0 ] ), 'xxx' );
|
|
|
|
|
- output( '<p>fozzz[]o</p><p>xxxbar</p>' );
|
|
|
|
|
|
|
+ it( 'multiple adding and undo', () => {
|
|
|
|
|
+ input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- setSelection( [ 1, 0 ], [ 1, 0 ] );
|
|
|
|
|
- doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
|
|
|
|
|
- output( '<p>fozzzo</p><p>yyy[]xxxbar</p>' );
|
|
|
|
|
|
|
+ doc.batch()
|
|
|
|
|
+ .insert( doc.selection.getFirstPosition(), 'zzz' )
|
|
|
|
|
+ .insert( new Position( root, [ 1, 0 ] ), 'xxx' );
|
|
|
|
|
+ output( '<p>fozzz[]o</p><p>xxxbar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fozzzo</p><p>[]xxxbar</p>' );
|
|
|
|
|
|
|
+ setSelection( [ 1, 0 ], [ 1, 0 ] );
|
|
|
|
|
+ doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
|
|
|
|
|
+ output( '<p>fozzzo</p><p>yyy[]xxxbar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fozzzo</p><p>[]xxxbar</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- it( 'multiple adding mixed with undo', () => {
|
|
|
|
|
- input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
|
|
- output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ it( 'multiple adding mixed with undo', () => {
|
|
|
|
|
+ input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- setSelection( [ 1, 0 ], [ 1, 0 ] );
|
|
|
|
|
- doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
|
|
|
|
|
- output( '<p>fozzzo</p><p>yyy[]bar</p>' );
|
|
|
|
|
|
|
+ doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
|
|
+ output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fozzzo</p><p>[]bar</p>' );
|
|
|
|
|
|
|
+ setSelection( [ 1, 0 ], [ 1, 0 ] );
|
|
|
|
|
+ doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
|
|
|
|
|
+ output( '<p>fozzzo</p><p>yyy[]bar</p>' );
|
|
|
|
|
|
|
|
- setSelection( [ 0, 0 ], [ 0, 0 ] );
|
|
|
|
|
- doc.batch().insert( doc.selection.getFirstPosition(), 'xxx' );
|
|
|
|
|
- output( '<p>xxx[]fozzzo</p><p>bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fozzzo</p><p>[]bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>[]fozzzo</p><p>bar</p>' );
|
|
|
|
|
|
|
+ setSelection( [ 0, 0 ], [ 0, 0 ] );
|
|
|
|
|
+ doc.batch().insert( doc.selection.getFirstPosition(), 'xxx' );
|
|
|
|
|
+ output( '<p>xxx[]fozzzo</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>[]fozzzo</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- it( 'multiple remove and undo', () => {
|
|
|
|
|
- input( '<p>[]foo</p><p>bar</p>' );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
|
|
|
|
|
- output( '<p>[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ it( 'multiple remove and undo', () => {
|
|
|
|
|
+ input( '<p>[]foo</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- setSelection( [ 1, 1 ], [ 1, 1 ] );
|
|
|
|
|
- doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
|
|
|
|
|
- output( '<p>o</p><p>b[]</p>' );
|
|
|
|
|
|
|
+ doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
|
|
|
|
|
+ output( '<p>[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- // Here is an edge case that selection could be before or after `ar`.
|
|
|
|
|
- output( '<p>o</p><p>b[]ar</p>' );
|
|
|
|
|
|
|
+ setSelection( [ 1, 1 ], [ 1, 1 ] );
|
|
|
|
|
+ doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
|
|
|
|
|
+ output( '<p>o</p><p>b[]</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- // As above.
|
|
|
|
|
- output( '<p>[]foo</p><p>bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ // Here is an edge case that selection could be before or after `ar`.
|
|
|
|
|
+ output( '<p>o</p><p>bar[]</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ // As above.
|
|
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- it( 'add and remove different parts and undo', () => {
|
|
|
|
|
- input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
|
|
- output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ it( 'add and remove different parts and undo', () => {
|
|
|
|
|
+ input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- setSelection( [ 1, 2 ], [ 1, 2 ] );
|
|
|
|
|
- doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 1, 1 ] ), 1 ) );
|
|
|
|
|
- output( '<p>fozzzo</p><p>b[]r</p>' );
|
|
|
|
|
|
|
+ doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
|
|
+ output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fozzzo</p><p>ba[]r</p>' );
|
|
|
|
|
|
|
+ setSelection( [ 1, 2 ], [ 1, 2 ] );
|
|
|
|
|
+ doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 1, 1 ] ), 1 ) );
|
|
|
|
|
+ output( '<p>fozzzo</p><p>b[]r</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fozzzo</p><p>ba[]r</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- it( 'add and remove same part and undo', () => {
|
|
|
|
|
- input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
|
|
- output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ it( 'add and remove same part and undo', () => {
|
|
|
|
|
+ input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 0, 2 ] ), 3 ) );
|
|
|
|
|
- output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
|
|
+ output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 0, 2 ] ), 3 ) );
|
|
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ undoDisabled();
|
|
|
} );
|
|
} );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- describe( 'moving', () => {
|
|
|
|
|
- it( 'move same content twice then undo', () => {
|
|
|
|
|
- input( '<p>f[o]z</p><p>bar</p>' );
|
|
|
|
|
|
|
+ describe( 'moving', () => {
|
|
|
|
|
+ it( 'move same content twice then undo', () => {
|
|
|
|
|
+ input( '<p>f[o]z</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) );
|
|
|
|
|
- output( '<p>fz</p><p>[o]bar</p>' );
|
|
|
|
|
|
|
+ doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) );
|
|
|
|
|
+ output( '<p>fz</p><p>[o]bar</p>' );
|
|
|
|
|
|
|
|
- doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0, 2 ] ) );
|
|
|
|
|
- output( '<p>fz[o]</p><p>bar</p>' );
|
|
|
|
|
|
|
+ doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0, 2 ] ) );
|
|
|
|
|
+ output( '<p>fz[o]</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fz</p><p>[o]bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fz</p><p>[o]bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>f[o]z</p><p>bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>f[o]z</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- it( 'move content and new parent then undo', () => {
|
|
|
|
|
- input( '<p>f[o]z</p><p>bar</p>' );
|
|
|
|
|
|
|
+ it( 'move content and new parent then undo', () => {
|
|
|
|
|
+ input( '<p>f[o]z</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) );
|
|
|
|
|
- output( '<p>fz</p><p>[o]bar</p>' );
|
|
|
|
|
|
|
+ doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) );
|
|
|
|
|
+ output( '<p>fz</p><p>[o]bar</p>' );
|
|
|
|
|
|
|
|
- setSelection( [ 1 ], [ 2 ] );
|
|
|
|
|
- doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
|
|
|
|
|
- output( '[<p>obar</p>]<p>fz</p>' );
|
|
|
|
|
|
|
+ setSelection( [ 1 ], [ 2 ] );
|
|
|
|
|
+ doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
|
|
|
|
|
+ output( '[<p>obar</p>]<p>fz</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fz</p>[<p>obar</p>]' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fz</p>[<p>obar</p>]' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>f[o]z</p><p>bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>f[o]z</p><p>bar</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
} );
|
|
} );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- describe( 'attributes with other', () => {
|
|
|
|
|
- it( 'attributes then insert inside then undo', () => {
|
|
|
|
|
- input( '<p>fo[ob]ar</p>' );
|
|
|
|
|
|
|
+ describe( 'attributes with other', () => {
|
|
|
|
|
+ it( 'attributes then insert inside then undo', () => {
|
|
|
|
|
+ input( '<p>fo[ob]ar</p>' );
|
|
|
|
|
|
|
|
- doc.batch().setAttribute( doc.selection.getFirstRange(), 'bold', true );
|
|
|
|
|
- output( '<p>fo[<$text bold="true">ob</$text>]ar</p>' );
|
|
|
|
|
|
|
+ doc.batch().setAttribute( doc.selection.getFirstRange(), 'bold', true );
|
|
|
|
|
+ output( '<p>fo[<$text bold="true">ob</$text>]ar</p>' );
|
|
|
|
|
|
|
|
- setSelection( [ 0, 3 ], [ 0, 3 ] );
|
|
|
|
|
- doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
|
|
- output( '<p>fo<$text bold="true">o</$text>zzz<$text bold="true">[]b</$text>ar</p>' );
|
|
|
|
|
- expect( doc.selection.getAttribute( 'bold' ) ).to.true;
|
|
|
|
|
|
|
+ setSelection( [ 0, 3 ], [ 0, 3 ] );
|
|
|
|
|
+ doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
|
|
+ output( '<p>fo<$text bold="true">o</$text>zzz<$text bold="true">[]b</$text>ar</p>' );
|
|
|
|
|
+ expect( doc.selection.getAttribute( 'bold' ) ).to.true;
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fo<$text bold="true">o[]b</$text>ar</p>' );
|
|
|
|
|
- expect( doc.selection.getAttribute( 'bold' ) ).to.true;
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fo<$text bold="true">o[]b</$text>ar</p>' );
|
|
|
|
|
+ expect( doc.selection.getAttribute( 'bold' ) ).to.true;
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fo[ob]ar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fo[ob]ar</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
} );
|
|
} );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- describe( 'wrapping, unwrapping, merging, splitting', () => {
|
|
|
|
|
- it( 'wrap and undo', () => {
|
|
|
|
|
- doc.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
|
|
- input( 'fo[zb]ar' );
|
|
|
|
|
|
|
+ describe( 'wrapping, unwrapping, merging, splitting', () => {
|
|
|
|
|
+ it( 'wrap and undo', () => {
|
|
|
|
|
+ doc.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
|
|
+ input( 'fo[zb]ar' );
|
|
|
|
|
|
|
|
- doc.batch().wrap( doc.selection.getFirstRange(), 'p' );
|
|
|
|
|
- output( 'fo<p>[zb]</p>ar' );
|
|
|
|
|
|
|
+ doc.batch().wrap( doc.selection.getFirstRange(), 'p' );
|
|
|
|
|
+ output( 'fo<p>[zb]</p>ar' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( 'fo[zb]ar' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( 'fo[zb]ar' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- it( 'wrap, move and undo', () => {
|
|
|
|
|
- doc.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
|
|
- input( 'fo[zb]ar' );
|
|
|
|
|
|
|
+ it( 'wrap, move and undo', () => {
|
|
|
|
|
+ doc.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
|
|
+ input( 'fo[zb]ar' );
|
|
|
|
|
|
|
|
- doc.batch().wrap( doc.selection.getFirstRange(), 'p' );
|
|
|
|
|
- // Would be better if selection was inside P.
|
|
|
|
|
- output( 'fo<p>[zb]</p>ar' );
|
|
|
|
|
|
|
+ doc.batch().wrap( doc.selection.getFirstRange(), 'p' );
|
|
|
|
|
+ // Would be better if selection was inside P.
|
|
|
|
|
+ output( 'fo<p>[zb]</p>ar' );
|
|
|
|
|
|
|
|
- setSelection( [ 2, 0 ], [ 2, 1 ] );
|
|
|
|
|
- doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
|
|
|
|
|
- output( '[z]fo<p>b</p>ar' );
|
|
|
|
|
|
|
+ setSelection( [ 2, 0 ], [ 2, 1 ] );
|
|
|
|
|
+ doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
|
|
|
|
|
+ output( '[z]fo<p>b</p>ar' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( 'fo<p>[z]b</p>ar' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( 'fo<p>[z]b</p>ar' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( 'fo[zb]ar' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( 'fo[zb]ar' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- it( 'unwrap and undo', () => {
|
|
|
|
|
- input( '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
+ it( 'unwrap and undo', () => {
|
|
|
|
|
+ input( '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
|
- doc.batch().unwrap( doc.selection.getFirstPosition().parent );
|
|
|
|
|
- output( 'foo[]bar' );
|
|
|
|
|
|
|
+ doc.batch().unwrap( doc.selection.getFirstPosition().parent );
|
|
|
|
|
+ output( 'foo[]bar' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- it( 'merge and undo', () => {
|
|
|
|
|
- input( '<p>foo</p><p>[]bar</p>' );
|
|
|
|
|
|
|
+ it( 'merge and undo', () => {
|
|
|
|
|
+ input( '<p>foo</p><p>[]bar</p>' );
|
|
|
|
|
|
|
|
- doc.batch().merge( new Position( root, [ 1 ] ) );
|
|
|
|
|
- // Because selection is stuck with <p> it ends up in graveyard. We have to manually move it to correct node.
|
|
|
|
|
- setSelection( [ 0, 3 ], [ 0, 3 ] );
|
|
|
|
|
- output( '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
+ doc.batch().merge( new Position( root, [ 1 ] ) );
|
|
|
|
|
+ // Because selection is stuck with <p> it ends up in graveyard. We have to manually move it to correct node.
|
|
|
|
|
+ setSelection( [ 0, 3 ], [ 0, 3 ] );
|
|
|
|
|
+ output( '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>foo</p><p>[]bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>foo</p><p>bar[]</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- it( 'split and undo', () => {
|
|
|
|
|
- input( '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
+ it( 'split and undo', () => {
|
|
|
|
|
+ input( '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
|
- doc.batch().split( doc.selection.getFirstPosition() );
|
|
|
|
|
- // Because selection is stuck with <p> it ends up in wrong node. We have to manually move it to correct node.
|
|
|
|
|
- setSelection( [ 1, 0 ], [ 1, 0 ] );
|
|
|
|
|
- output( '<p>foo</p><p>[]bar</p>' );
|
|
|
|
|
|
|
+ doc.batch().split( doc.selection.getFirstPosition() );
|
|
|
|
|
+ // Because selection is stuck with <p> it ends up in wrong node. We have to manually move it to correct node.
|
|
|
|
|
+ setSelection( [ 1, 0 ], [ 1, 0 ] );
|
|
|
|
|
+ output( '<p>foo</p><p>[]bar</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>foo[]bar</p>' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>foobar[]</p>' );
|
|
|
|
|
|
|
|
- undoDisabled();
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
} );
|
|
} );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- describe( 'other edge cases', () => {
|
|
|
|
|
- it( 'deleteContent between two nodes', () => {
|
|
|
|
|
- input( '<p>fo[o</p><p>b]ar</p>' );
|
|
|
|
|
|
|
+ // Restoring selection in those examples may be completely off.
|
|
|
|
|
+ describe( 'multiple enters, deletes and typing', () => {
|
|
|
|
|
+ function split( path ) {
|
|
|
|
|
+ setSelection( path.slice(), path.slice() );
|
|
|
|
|
+ editor.execute( 'enter' );
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- editor.data.deleteContent( doc.selection, doc.batch() );
|
|
|
|
|
- output( '<p>fo[]ar</p>' );
|
|
|
|
|
|
|
+ function merge( path ) {
|
|
|
|
|
+ const selPath = path.slice();
|
|
|
|
|
+ selPath.push( 0 );
|
|
|
|
|
+ setSelection( selPath, selPath.slice() );
|
|
|
|
|
+ editor.execute( 'delete' );
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- output( '<p>fo[o</p><p>b]ar</p>' );
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ function type( path, text ) {
|
|
|
|
|
+ setSelection( path.slice(), path.slice() );
|
|
|
|
|
+ editor.execute( 'input', { text } );
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Related to ckeditor5-engine#891 and ckeditor5-list#51.
|
|
|
|
|
- it( 'change attribute of removed node then undo and redo', () => {
|
|
|
|
|
- const gy = doc.graveyard;
|
|
|
|
|
- const batch = doc.batch();
|
|
|
|
|
- const p = new Element( 'p' );
|
|
|
|
|
|
|
+ function remove( path ) {
|
|
|
|
|
+ setSelection( path.slice(), path.slice() );
|
|
|
|
|
+ editor.execute( 'delete' );
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- root.appendChildren( p );
|
|
|
|
|
|
|
+ it( 'split, split, split', () => {
|
|
|
|
|
+ input( '<p>12345678</p>' );
|
|
|
|
|
|
|
|
- batch.remove( p );
|
|
|
|
|
- batch.setAttribute( p, 'bold', true );
|
|
|
|
|
|
|
+ split( [ 0, 3 ] );
|
|
|
|
|
+ output( '<p>123</p><p>[]45678</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- editor.execute( 'redo' );
|
|
|
|
|
|
|
+ split( [ 1, 4 ] );
|
|
|
|
|
+ output( '<p>123</p><p>4567</p><p>[]8</p>' );
|
|
|
|
|
|
|
|
- expect( p.root ).to.equal( gy );
|
|
|
|
|
- expect( p.getAttribute( 'bold' ) ).to.be.true;
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ split( [ 1, 2 ] );
|
|
|
|
|
+ output( '<p>123</p><p>45</p><p>[]67</p><p>8</p>' );
|
|
|
|
|
|
|
|
- // Related to ckeditor5-engine#891.
|
|
|
|
|
- it( 'change attribute of removed node then undo and redo', () => {
|
|
|
|
|
- const gy = doc.graveyard;
|
|
|
|
|
- const batch = doc.batch();
|
|
|
|
|
- const p1 = new Element( 'p' );
|
|
|
|
|
- const p2 = new Element( 'p' );
|
|
|
|
|
- const p3 = new Element( 'p' );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>4567[]</p><p>8</p>' );
|
|
|
|
|
|
|
|
- root.appendChildren( [ p1, p2 ] );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>45678[]</p>' );
|
|
|
|
|
|
|
|
- batch.remove( p1 ).remove( p2 ).insert( new Position( root, [ 0 ] ), p3 );
|
|
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345678[]</p>' );
|
|
|
|
|
|
|
|
- editor.execute( 'undo' );
|
|
|
|
|
- editor.execute( 'redo' );
|
|
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
|
|
|
- expect( p1.root ).to.equal( gy );
|
|
|
|
|
- expect( p2.root ).to.equal( gy );
|
|
|
|
|
- expect( p3.root ).to.equal( root );
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123[]</p><p>45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123</p><p>4567[]</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123</p><p>45[]</p><p>67</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ redoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'merge, merge, merge', () => {
|
|
|
|
|
+ input( '<p>123</p><p>45</p><p>67</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>123[]45</p><p>67</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 2 ] );
|
|
|
|
|
+ output( '<p>12345</p><p>67[]8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>12345[]678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345</p><p>678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345</p><p>67</p><p>8[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>45[]</p><p>67</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>12345[]</p><p>67</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>12345</p><p>678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>1234567[]8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ redoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'split, merge, split, merge (same position)', () => {
|
|
|
|
|
+ input( '<p>12345678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 0, 3 ] );
|
|
|
|
|
+ output( '<p>123</p><p>[]45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>123[]45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 0, 3 ] );
|
|
|
|
|
+ output( '<p>123</p><p>[]45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>123[]45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>45678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>45678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123[]</p><p>45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>12345678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123[]</p><p>45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>12345678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ redoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'split, split, split, merge, merge, merge', () => {
|
|
|
|
|
+ input( '<p>12345678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 0, 3 ] );
|
|
|
|
|
+ output( '<p>123</p><p>[]45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 1, 4 ] );
|
|
|
|
|
+ output( '<p>123</p><p>4567</p><p>[]8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 1, 2 ] );
|
|
|
|
|
+ output( '<p>123</p><p>45</p><p>[]67</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>123[]45</p><p>67</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 2 ] );
|
|
|
|
|
+ output( '<p>12345</p><p>67[]8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>12345[]678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345</p><p>678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345</p><p>67</p><p>8[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>45[]</p><p>67</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>4567[]</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>45678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123[]</p><p>45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123</p><p>4567[]</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123</p><p>45[]</p><p>67</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>12345[]</p><p>67</p><p>8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>12345</p><p>678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>1234567[]8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ redoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'split, split, merge, split, merge (different order)', () => {
|
|
|
|
|
+ input( '<p>12345678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 0, 3 ] );
|
|
|
|
|
+ output( '<p>123</p><p>[]45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 1, 2 ] );
|
|
|
|
|
+ output( '<p>123</p><p>45</p><p>[]678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>123[]45</p><p>678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 1, 1 ] );
|
|
|
|
|
+ output( '<p>12345</p><p>6</p><p>[]78</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>12345[]6</p><p>78</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345</p><p>6[]</p><p>78</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345</p><p>678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>45[]</p><p>678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>45678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123[]</p><p>45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123</p><p>45[]</p><p>678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>12345[]</p><p>678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>12345</p><p>6[]</p><p>78</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123456[]</p><p>78</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ redoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'split, remove, split, merge, merge', () => {
|
|
|
|
|
+ input( '<p>12345678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 0, 3 ] );
|
|
|
|
|
+ output( '<p>123</p><p>[]45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ remove( [ 1, 4 ] );
|
|
|
|
|
+ remove( [ 1, 3 ] );
|
|
|
|
|
+ output( '<p>123</p><p>45[]8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 1, 1 ] );
|
|
|
|
|
+ output( '<p>123</p><p>4</p><p>[]58</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>123[]4</p><p>58</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>1234[]58</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>1234</p><p>58[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>4[]</p><p>58</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>458[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>4567[]8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123[]</p><p>45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123</p><p>458[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123</p><p>4[]</p><p>58</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>1234[]</p><p>58</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>12345[]8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ redoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'split, typing, split, merge, merge', () => {
|
|
|
|
|
+ input( '<p>12345678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 0, 3 ] );
|
|
|
|
|
+ output( '<p>123</p><p>[]45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ type( [ 1, 4 ], 'x' );
|
|
|
|
|
+ type( [ 1, 5 ], 'y' );
|
|
|
|
|
+ output( '<p>123</p><p>4567xy[]8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ split( [ 1, 2 ] );
|
|
|
|
|
+ output( '<p>123</p><p>45</p><p>[]67xy8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>123[]45</p><p>67xy8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ merge( [ 1 ] );
|
|
|
|
|
+ output( '<p>12345[]67xy8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345</p><p>67xy8[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>45[]</p><p>67xy8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>4567xy8[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>123</p><p>4567[]8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>12345678[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ undoDisabled();
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123[]</p><p>45678</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123</p><p>4567xy8[]</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>123</p><p>45[]</p><p>67xy8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>12345[]</p><p>67xy8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+ output( '<p>1234567[]xy8</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ redoDisabled();
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ describe( 'other edge cases', () => {
|
|
|
|
|
+ it( 'deleteContent between two nodes', () => {
|
|
|
|
|
+ input( '<p>fo[o</p><p>b]ar</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.data.deleteContent( doc.selection, doc.batch() );
|
|
|
|
|
+ output( '<p>fo[]ar</p>' );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ output( '<p>fo[o</p><p>b]ar</p>' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ // Related to ckeditor5-engine#891 and ckeditor5-list#51.
|
|
|
|
|
+ it( 'change attribute of removed node then undo and redo', () => {
|
|
|
|
|
+ const gy = doc.graveyard;
|
|
|
|
|
+ const batch = doc.batch();
|
|
|
|
|
+ const p = new Element( 'p' );
|
|
|
|
|
+
|
|
|
|
|
+ root.appendChildren( p );
|
|
|
|
|
+
|
|
|
|
|
+ batch.remove( p );
|
|
|
|
|
+ batch.setAttribute( p, 'bold', true );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( p.root ).to.equal( gy );
|
|
|
|
|
+ expect( p.getAttribute( 'bold' ) ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ // Related to ckeditor5-engine#891.
|
|
|
|
|
+ it( 'change attribute of removed node then undo and redo', () => {
|
|
|
|
|
+ const gy = doc.graveyard;
|
|
|
|
|
+ const batch = doc.batch();
|
|
|
|
|
+ const p1 = new Element( 'p' );
|
|
|
|
|
+ const p2 = new Element( 'p' );
|
|
|
|
|
+ const p3 = new Element( 'p' );
|
|
|
|
|
+
|
|
|
|
|
+ root.appendChildren( [ p1, p2 ] );
|
|
|
|
|
+
|
|
|
|
|
+ batch.remove( p1 ).remove( p2 ).insert( new Position( root, [ 0 ] ), p3 );
|
|
|
|
|
+
|
|
|
|
|
+ editor.execute( 'undo' );
|
|
|
|
|
+ editor.execute( 'redo' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( p1.root ).to.equal( gy );
|
|
|
|
|
+ expect( p2.root ).to.equal( gy );
|
|
|
|
|
+ expect( p3.root ).to.equal( root );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|