8
0
Просмотр исходного кода

Tests: added additional test that checks empty root fixing for multiple roots.

Szymon Cofalik 8 лет назад
Родитель
Сommit
3b68698749

+ 3 - 1
packages/ckeditor5-paragraph/src/paragraph.js

@@ -243,7 +243,9 @@ function findEmptyRoots( doc, batch ) {
 		const root = doc.getRoot( rootName );
 
 		if ( root.isEmpty ) {
-			rootsToFix.set( root, batch );
+			if ( !rootsToFix.has( root ) ) {
+				rootsToFix.set( root, batch );
+			}
 		} else {
 			rootsToFix.delete( root );
 		}

+ 34 - 1
packages/ckeditor5-paragraph/tests/paragraph-intergration.js

@@ -157,7 +157,6 @@ describe( 'Paragraph feature – integration', () => {
 					const doc = editor.document;
 					const root = doc.getRoot();
 
-					// Selection is in <p>, hence &nbsp;
 					expect( editor.getData() ).to.equal( '<p>&nbsp;</p>' );
 					expect( editor.commands.get( 'undo' ).isEnabled ).to.be.false;
 
@@ -182,5 +181,39 @@ describe( 'Paragraph feature – integration', () => {
 					expect( editor.getData() ).to.equal( '<p>Foobar.</p>' );
 				} );
 		} );
+
+		it( 'fixing empty roots should be transparent to undo - multiple roots', () => {
+			return VirtualTestEditor.create( {
+				plugins: [ Paragraph, UndoEngine ]
+			} )
+				.then( newEditor => {
+					const editor = newEditor;
+					const doc = editor.document;
+					const root = doc.getRoot();
+					const otherRoot = doc.createRoot( '$root', 'otherRoot' );
+					editor.editing.createRoot( 'div', 'otherRoot' );
+
+					editor.data.set( '<p>Foobar.</p>', 'main' );
+					editor.data.set( '<p>Foobar.</p>', 'otherRoot' );
+
+					doc.enqueueChanges( () => {
+						doc.batch().remove( root.getChild( 0 ) );
+						doc.batch().remove( otherRoot.getChild( 0 ) );
+					} );
+
+					expect( editor.data.get( 'main' ) ).to.equal( '<p>&nbsp;</p>' );
+					expect( editor.data.get( 'otherRoot' ) ).to.equal( '<p>&nbsp;</p>' );
+
+					editor.execute( 'undo' );
+
+					expect( editor.data.get( 'main' ) ).to.equal( '<p>&nbsp;</p>' );
+					expect( editor.data.get( 'otherRoot' ) ).to.equal( '<p>Foobar.</p>' );
+
+					editor.execute( 'undo' );
+
+					expect( editor.data.get( 'main' ) ).to.equal( '<p>Foobar.</p>' );
+					expect( editor.data.get( 'otherRoot' ) ).to.equal( '<p>Foobar.</p>' );
+				} );
+		} );
 	} );
 } );