瀏覽代碼

Aligned code with new Batch API.

Oskar Wróbel 8 年之前
父節點
當前提交
c396470125

+ 2 - 2
packages/ckeditor5-undo/tests/redocommand.js

@@ -52,7 +52,7 @@ describe( 'RedoCommand', () => {
 				editor.document.selection.setRanges( [ r( 0, 0 ) ] );
 				batch0 = doc.batch();
 				undo.addBatch( batch0 );
-				batch0.insert( p( 0 ), 'foobar' );
+				batch0.insertText( 'foobar', p( 0 ) );
 
 				/*
 				 [root]
@@ -233,7 +233,7 @@ describe( 'RedoCommand', () => {
 				undo.execute();
 
 				// Append "xx" at the beginning. Now it is "xxfoob".
-				doc.batch().insert( p( 0 ), 'xx' );
+				doc.batch().insertText( 'xx', p( 0 ) );
 
 				// Redo setting attribute on "ob". Now it is "xxfoOB".
 				redo.execute();

+ 1 - 1
packages/ckeditor5-undo/tests/undocommand.js

@@ -41,7 +41,7 @@ describe( 'UndoCommand', () => {
 				editor.document.selection.setRanges( [ r( 0, 0 ) ] );
 				batch0 = doc.batch();
 				undo.addBatch( batch0 );
-				batch0.insert( p( 0 ), 'foobar' );
+				batch0.insertText( 'foobar', p( 0 ) );
 
 				/*
 				 [root]

+ 18 - 17
packages/ckeditor5-undo/tests/undoengine-integration.js

@@ -9,7 +9,6 @@ import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'
 
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import Position from '@ckeditor/ckeditor5-engine/src/model/position';
-import Element from '@ckeditor/ckeditor5-engine/src/model/element';
 import UndoEngine from '../src/undoengine';
 
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
@@ -71,7 +70,7 @@ describe( 'UndoEngine integration', () => {
 			input( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
 
 			doc.enqueueChanges( () => {
-				doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
+				doc.batch().insertText( 'zzz', doc.selection.getFirstPosition() );
 			} );
 			output( '<paragraph>fozzz[]o</paragraph><paragraph>bar</paragraph>' );
 
@@ -85,16 +84,17 @@ describe( 'UndoEngine integration', () => {
 			input( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
 
 			doc.enqueueChanges( () => {
-				doc.batch()
-					.insert( doc.selection.getFirstPosition(), 'zzz' )
-					.insert( new Position( root, [ 1, 0 ] ), 'xxx' );
+				const batch = doc.batch();
+
+				batch.insertText( 'zzz', doc.selection.getFirstPosition() );
+				batch.insertText( 'xxx', new Position( root, [ 1, 0 ] ) );
 			} );
 
 			output( '<paragraph>fozzz[]o</paragraph><paragraph>xxxbar</paragraph>' );
 
 			doc.enqueueChanges( () => {
 				setSelection( [ 1, 0 ], [ 1, 0 ] );
-				doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
+				doc.batch().insertText( 'yyy', doc.selection.getFirstPosition() );
 			} );
 
 			output( '<paragraph>fozzzo</paragraph><paragraph>yyy[]xxxbar</paragraph>' );
@@ -112,13 +112,13 @@ describe( 'UndoEngine integration', () => {
 			input( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
 
 			doc.enqueueChanges( () => {
-				doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
+				doc.batch().insertText( 'zzz', doc.selection.getFirstPosition() );
 			} );
 			output( '<paragraph>fozzz[]o</paragraph><paragraph>bar</paragraph>' );
 
 			doc.enqueueChanges( () => {
 				setSelection( [ 1, 0 ], [ 1, 0 ] );
-				doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' );
+				doc.batch().insertText( 'yyy', doc.selection.getFirstPosition() );
 			} );
 
 			output( '<paragraph>fozzzo</paragraph><paragraph>yyy[]bar</paragraph>' );
@@ -128,7 +128,7 @@ describe( 'UndoEngine integration', () => {
 
 			doc.enqueueChanges( () => {
 				setSelection( [ 0, 0 ], [ 0, 0 ] );
-				doc.batch().insert( doc.selection.getFirstPosition(), 'xxx' );
+				doc.batch().insertText( 'xxx', doc.selection.getFirstPosition() );
 			} );
 			output( '<paragraph>xxx[]fozzzo</paragraph><paragraph>bar</paragraph>' );
 
@@ -170,7 +170,7 @@ describe( 'UndoEngine integration', () => {
 			input( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
 
 			doc.enqueueChanges( () => {
-				doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
+				doc.batch().insertText( 'zzz', doc.selection.getFirstPosition() );
 			} );
 			output( '<paragraph>fozzz[]o</paragraph><paragraph>bar</paragraph>' );
 
@@ -193,7 +193,7 @@ describe( 'UndoEngine integration', () => {
 			input( '<paragraph>fo[]o</paragraph><paragraph>bar</paragraph>' );
 
 			doc.enqueueChanges( () => {
-				doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
+				doc.batch().insertText( 'zzz', doc.selection.getFirstPosition() );
 			} );
 			output( '<paragraph>fozzz[]o</paragraph><paragraph>bar</paragraph>' );
 
@@ -229,7 +229,7 @@ describe( 'UndoEngine integration', () => {
 			input( '' );
 
 			doc.enqueueChanges( () => {
-				doc.batch().insert( doc.selection.getFirstPosition(), new Element( 'heading1' ) );
+				doc.batch().insertElement( 'heading1', doc.selection.getFirstPosition() );
 			} );
 			output( '<heading1>[]</heading1>' );
 
@@ -247,10 +247,11 @@ describe( 'UndoEngine integration', () => {
 			const pos = new Position( root, [ 0 ] );
 
 			doc.enqueueChanges( () => {
-				doc.batch()
-					.remove( p )
-					.insert( pos, new Element( 'heading1' ) )
-					.insert( pos.getShiftedBy( 1 ), new Element( 'heading2' ) );
+				const batch = doc.batch();
+
+				batch.remove( p );
+				batch.insertElement( 'heading1', pos );
+				batch.insertElement( 'heading2', pos.getShiftedBy( 1 ) );
 			} );
 
 			output( '<heading1>[]</heading1><heading2></heading2>' );
@@ -321,7 +322,7 @@ describe( 'UndoEngine integration', () => {
 
 			doc.enqueueChanges( () => {
 				setSelection( [ 0, 3 ], [ 0, 3 ] );
-				doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
+				doc.batch().insertText( 'zzz', doc.selection.getFirstPosition() );
 			} );
 			output( '<paragraph>fo<$text bold="true">o</$text>zzz<$text bold="true">[]b</$text>ar</paragraph>' );
 			expect( doc.selection.getAttribute( 'bold' ) ).to.true;

+ 4 - 4
packages/ckeditor5-undo/tests/undoengine.js

@@ -4,7 +4,6 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import UndoEngine from '../src/undoengine';
 
 describe( 'UndoEngine', () => {
@@ -38,7 +37,7 @@ describe( 'UndoEngine', () => {
 			expect( undo._undoCommand.addBatch.called ).to.be.false;
 			expect( undo._redoCommand.clearStack.called ).to.be.false;
 
-			batch.insert( new Position( root, [ 0 ] ), 'foobar' );
+			batch.insertText( 'foobar', root );
 
 			expect( undo._undoCommand.addBatch.calledOnce ).to.be.true;
 			expect( undo._redoCommand.clearStack.calledOnce ).to.be.true;
@@ -47,7 +46,8 @@ describe( 'UndoEngine', () => {
 		it( 'should add each batch only once', () => {
 			sinon.spy( undo._undoCommand, 'addBatch' );
 
-			batch.insert( new Position( root, [ 0 ] ), 'foobar' ).insert( new Position( root, [ 0 ] ), 'foobar' );
+			batch.insertText( 'foobar', root );
+			batch.insertText( 'foobar', root );
 
 			expect( undo._undoCommand.addBatch.calledOnce ).to.be.true;
 		} );
@@ -58,7 +58,7 @@ describe( 'UndoEngine', () => {
 
 			undo._redoCommand._createdBatches.add( batch );
 
-			batch.insert( new Position( root, [ 0 ] ), 'foobar' );
+			batch.insertText( 'foobar', root );
 
 			expect( undo._undoCommand.addBatch.calledOnce ).to.be.true;
 			expect( undo._redoCommand.clearStack.called ).to.be.false;