|
|
@@ -21,6 +21,7 @@ beforeEach( () => {
|
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
|
doc = editor.document;
|
|
|
+ doc.schema.registerItem( 'p', '$block' );
|
|
|
root = doc.getRoot();
|
|
|
} );
|
|
|
} );
|
|
|
@@ -44,118 +45,118 @@ function undoDisabled() {
|
|
|
describe( 'UndoEngine integration', () => {
|
|
|
describe( 'adding and removing content', () => {
|
|
|
it( 'add and undo', () => {
|
|
|
- input( '<p>fo<selection />o</p><p>bar</p>' );
|
|
|
+ input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
- output( '<p>fozzz<selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fo<selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
|
|
|
it( 'multiple adding and undo', () => {
|
|
|
- input( '<p>fo<selection />o</p><p>bar</p>' );
|
|
|
+ input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
doc.batch()
|
|
|
.insert( doc.selection.getFirstPosition(), 'zzz' )
|
|
|
.insert( new Position( root, [ 1, 0 ] ), 'xxx' );
|
|
|
- output( '<p>fozzz<selection />o</p><p>xxxbar</p>' );
|
|
|
+ output( '<p>fozzz[]o</p><p>xxxbar</p>' );
|
|
|
|
|
|
setSelection( [ 1, 0 ], [ 1, 0 ] );
|
|
|
doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
|
|
|
- output( '<p>fozzzo</p><p>yyy<selection />xxxbar</p>' );
|
|
|
+ output( '<p>fozzzo</p><p>yyy[]xxxbar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fozzzo</p><p><selection />xxxbar</p>' );
|
|
|
+ output( '<p>fozzzo</p><p>[]xxxbar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fo<selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
|
|
|
it( 'multiple adding mixed with undo', () => {
|
|
|
- input( '<p>fo<selection />o</p><p>bar</p>' );
|
|
|
+ input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
- output( '<p>fozzz<selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
setSelection( [ 1, 0 ], [ 1, 0 ] );
|
|
|
doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
|
|
|
- output( '<p>fozzzo</p><p>yyy<selection />bar</p>' );
|
|
|
+ output( '<p>fozzzo</p><p>yyy[]bar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fozzzo</p><p><selection />bar</p>' );
|
|
|
+ output( '<p>fozzzo</p><p>[]bar</p>' );
|
|
|
|
|
|
setSelection( [ 0, 0 ], [ 0, 0 ] );
|
|
|
doc.batch().insert( doc.selection.getFirstPosition(), 'xxx' );
|
|
|
- output( '<p>xxx<selection />fozzzo</p><p>bar</p>' );
|
|
|
+ output( '<p>xxx[]fozzzo</p><p>bar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p><selection />fozzzo</p><p>bar</p>' );
|
|
|
+ output( '<p>[]fozzzo</p><p>bar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fo<selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
|
|
|
it( 'multiple remove and undo', () => {
|
|
|
- input( '<p><selection />foo</p><p>bar</p>' );
|
|
|
+ input( '<p>[]foo</p><p>bar</p>' );
|
|
|
|
|
|
doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
|
|
|
- output( '<p><selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>[]o</p><p>bar</p>' );
|
|
|
|
|
|
setSelection( [ 1, 1 ], [ 1, 1 ] );
|
|
|
doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) );
|
|
|
- output( '<p>o</p><p>b<selection /></p>' );
|
|
|
+ output( '<p>o</p><p>b[]</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
// Here is an edge case that selection could be before or after `ar`.
|
|
|
- output( '<p>o</p><p>b<selection />ar</p>' );
|
|
|
+ output( '<p>o</p><p>b[]ar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
// As above.
|
|
|
- output( '<p><selection />foo</p><p>bar</p>' );
|
|
|
+ output( '<p>[]foo</p><p>bar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
|
|
|
it( 'add and remove different parts and undo', () => {
|
|
|
- input( '<p>fo<selection />o</p><p>bar</p>' );
|
|
|
+ input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
- output( '<p>fozzz<selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>fozzz[]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<selection />r</p>' );
|
|
|
+ output( '<p>fozzzo</p><p>b[]r</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fozzzo</p><p>ba<selection />r</p>' );
|
|
|
+ output( '<p>fozzzo</p><p>ba[]r</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fo<selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
|
|
|
it( 'add and remove same part and undo', () => {
|
|
|
- input( '<p>fo<selection />o</p><p>bar</p>' );
|
|
|
+ input( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
|
|
|
- output( '<p>fozzz<selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 0, 2 ] ) , 3 ) );
|
|
|
- output( '<p>fo<selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fozzz<selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>fozzz[]o</p><p>bar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fo<selection />o</p><p>bar</p>' );
|
|
|
+ output( '<p>fo[]o</p><p>bar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
@@ -163,38 +164,38 @@ describe( 'UndoEngine integration', () => {
|
|
|
|
|
|
describe( 'moving', () => {
|
|
|
it( 'move same content twice then undo', () => {
|
|
|
- input( '<p>f<selection>o</selection>z</p><p>bar</p>' );
|
|
|
+ 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><selection>o</selection>bar</p>' );
|
|
|
+ output( '<p>fz</p><p>[o]bar</p>' );
|
|
|
|
|
|
doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0, 2 ] ) );
|
|
|
- output( '<p>fz<selection>o</selection></p><p>bar</p>' );
|
|
|
+ output( '<p>fz[o]</p><p>bar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fz</p><p><selection>o</selection>bar</p>' );
|
|
|
+ output( '<p>fz</p><p>[o]bar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>f<selection>o</selection>z</p><p>bar</p>' );
|
|
|
+ output( '<p>f[o]z</p><p>bar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
|
|
|
it( 'move content and new parent then undo', () => {
|
|
|
- input( '<p>f<selection>o</selection>z</p><p>bar</p>' );
|
|
|
+ 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><selection>o</selection>bar</p>' );
|
|
|
+ output( '<p>fz</p><p>[o]bar</p>' );
|
|
|
|
|
|
setSelection( [ 1 ], [ 2 ] );
|
|
|
doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
|
|
|
- output( '<selection><p>obar</p></selection><p>fz</p>' );
|
|
|
+ output( '[<p>obar</p>]<p>fz</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fz</p><selection><p>obar</p></selection>' );
|
|
|
+ output( '<p>fz</p>[<p>obar</p>]' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>f<selection>o</selection>z</p><p>bar</p>' );
|
|
|
+ output( '<p>f[o]z</p><p>bar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
@@ -202,20 +203,22 @@ describe( 'UndoEngine integration', () => {
|
|
|
|
|
|
describe( 'attributes with other', () => {
|
|
|
it( 'attributes then insert inside then undo', () => {
|
|
|
- input( '<p>fo<selection>ob</selection>ar</p>' );
|
|
|
+ input( '<p>fo[ob]ar</p>' );
|
|
|
|
|
|
doc.batch().setAttribute( doc.selection.getFirstRange(), 'bold', true );
|
|
|
- output( '<p>fo<selection><$text bold=true>ob</$text></selection>ar</p>' );
|
|
|
+ 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<selection bold=true /><$text bold=true>b</$text>ar</p>' );
|
|
|
+ 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<selection bold=true />b</$text>ar</p>' );
|
|
|
+ output( '<p>fo<$text bold="true">o[]b</$text>ar</p>' );
|
|
|
+ expect( doc.selection.getAttribute( 'bold' ) ).to.true;
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fo<selection>ob</selection>ar</p>' );
|
|
|
+ output( '<p>fo[ob]ar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
@@ -223,73 +226,75 @@ describe( 'UndoEngine integration', () => {
|
|
|
|
|
|
describe( 'wrapping, unwrapping, merging, splitting', () => {
|
|
|
it( 'wrap and undo', () => {
|
|
|
- input( 'fo<selection>zb</selection>ar' );
|
|
|
+ doc.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
+ input( 'fo[zb]ar' );
|
|
|
|
|
|
doc.batch().wrap( doc.selection.getFirstRange(), 'p' );
|
|
|
- output( 'fo<selection><p>zb</p></selection>ar' );
|
|
|
+ output( 'fo[<p>zb</p>]ar' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( 'fo<selection>zb</selection>ar' );
|
|
|
+ output( 'fo[zb]ar' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
|
|
|
it( 'wrap, move and undo', () => {
|
|
|
- input( 'fo<selection>zb</selection>ar' );
|
|
|
+ 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<selection><p>zb</p></selection>ar' );
|
|
|
+ output( 'fo[<p>zb</p>]ar' );
|
|
|
|
|
|
setSelection( [ 2, 0 ], [ 2, 1 ] );
|
|
|
doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) );
|
|
|
- output( '<selection>z</selection>fo<p>b</p>ar' );
|
|
|
+ output( '[z]fo<p>b</p>ar' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( 'fo<p><selection>z</selection>b</p>ar' );
|
|
|
+ output( 'fo<p>[z]b</p>ar' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( 'fo<selection>zb</selection>ar' );
|
|
|
+ output( 'fo[zb]ar' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
|
|
|
it( 'unwrap and undo', () => {
|
|
|
- input( '<p>foo<selection />bar</p>' );
|
|
|
+ input( '<p>foo[]bar</p>' );
|
|
|
|
|
|
doc.batch().unwrap( doc.selection.getFirstPosition().parent );
|
|
|
- output( 'foo<selection />bar' );
|
|
|
+ output( 'foo[]bar' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>foo<selection />bar</p>' );
|
|
|
+ output( '<p>foo[]bar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
|
|
|
it( 'merge and undo', () => {
|
|
|
- input( '<p>foo</p><p><selection />bar</p>' );
|
|
|
+ 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<selection />bar</p>' );
|
|
|
+ output( '<p>foo[]bar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>foo</p><p><selection />bar</p>' );
|
|
|
+ output( '<p>foo</p><p>[]bar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
|
|
|
it( 'split and undo', () => {
|
|
|
- input( '<p>foo<selection />bar</p>' );
|
|
|
+ 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><selection />bar</p>' );
|
|
|
+ output( '<p>foo</p><p>[]bar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>foo<selection />bar</p>' );
|
|
|
+ output( '<p>foo[]bar</p>' );
|
|
|
|
|
|
undoDisabled();
|
|
|
} );
|
|
|
@@ -297,13 +302,13 @@ describe( 'UndoEngine integration', () => {
|
|
|
|
|
|
describe( 'other edge cases', () => {
|
|
|
it( 'deleteContents between two nodes', () => {
|
|
|
- input( '<p>fo<selection>o</p><p>b</selection>ar</p>' );
|
|
|
+ input( '<p>fo[o</p><p>b]ar</p>' );
|
|
|
|
|
|
deleteContents( doc.batch(), doc.selection, { merge: true } );
|
|
|
- output( '<p>fo<selection />ar</p>' );
|
|
|
+ output( '<p>fo[]ar</p>' );
|
|
|
|
|
|
editor.execute( 'undo' );
|
|
|
- output( '<p>fo<selection>o</p><p>b</selection>ar</p>' );
|
|
|
+ output( '<p>fo[o</p><p>b]ar</p>' );
|
|
|
} );
|
|
|
} );
|
|
|
} );
|