Procházet zdrojové kódy

Merge branch t/ckeditor5-engine/858

Internal: Update API usage after merge t/858 on engine.
Piotr Jasiun před 8 roky
rodič
revize
29f5f7c212

+ 2 - 2
packages/ckeditor5-autoformat/src/inlineautoformatengine.js

@@ -62,7 +62,7 @@ export default class InlineAutoformatEngine {
 	 *		// Use formatting callback:
 	 *		new InlineAutoformatEngine( editor, /(\*\*)([^\*]+?)(\*\*)$/g, ( batch, validRanges ) => {
 	 *			for ( let range of validRanges ) {
-	 *				batch.setAttribute( range, command, true );
+	 *				batch.setAttribute( command, true, range );
 	 *			}
 	 *		} );
 	 */
@@ -132,7 +132,7 @@ export default class InlineAutoformatEngine {
 		// A format callback run on matched text.
 		formatCallback = formatCallback || ( ( batch, validRanges ) => {
 			for ( const range of validRanges ) {
-				batch.setAttribute( range, command, true );
+				batch.setAttribute( command, true, range );
 			}
 		} );
 

+ 29 - 29
packages/ckeditor5-autoformat/tests/autoformat.js

@@ -56,7 +56,7 @@ describe( 'Autoformat', () => {
 		it( 'should replace asterisk with bulleted list item', () => {
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
@@ -65,7 +65,7 @@ describe( 'Autoformat', () => {
 		it( 'should replace minus character with bulleted list item', () => {
 			setData( doc, '<paragraph>-[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
@@ -74,7 +74,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace minus character when inside bulleted list item', () => {
 			setData( doc, '<listItem indent="0" type="bulleted">-[]</listItem>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">- []</listItem>' );
@@ -85,7 +85,7 @@ describe( 'Autoformat', () => {
 		it( 'should replace digit with numbered list item', () => {
 			setData( doc, '<paragraph>1.[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
@@ -94,7 +94,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace digit character when inside numbered list item', () => {
 			setData( doc, '<listItem indent="0" type="numbered">1.[]</listItem>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">1. []</listItem>' );
@@ -105,7 +105,7 @@ describe( 'Autoformat', () => {
 		it( 'should replace hash character with heading', () => {
 			setData( doc, '<paragraph>#[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<heading1>[]</heading1>' );
@@ -114,7 +114,7 @@ describe( 'Autoformat', () => {
 		it( 'should replace two hash characters with heading level 2', () => {
 			setData( doc, '<paragraph>##[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<heading2>[]</heading2>' );
@@ -123,7 +123,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace hash character when inside heading', () => {
 			setData( doc, '<heading1>#[]</heading1>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<heading1># []</heading1>' );
@@ -160,14 +160,14 @@ describe( 'Autoformat', () => {
 
 					setData( doc, '<paragraph>#[]</paragraph>' );
 					doc.enqueueChanges( () => {
-						doc.batch().insert( doc.selection.getFirstPosition(), ' ' );
+						doc.batch().insertText( ' ', doc.selection.getFirstPosition() );
 					} );
 
 					expect( spy1.calledOnce ).to.be.true;
 
 					setData( doc, '<paragraph>######[]</paragraph>' );
 					doc.enqueueChanges( () => {
-						doc.batch().insert( doc.selection.getFirstPosition(), ' ' );
+						doc.batch().insertText( ' ', doc.selection.getFirstPosition() );
 					} );
 
 					expect( spy6.calledOnce ).to.be.true;
@@ -181,7 +181,7 @@ describe( 'Autoformat', () => {
 		it( 'should replace greater-than character with heading', () => {
 			setData( doc, '<paragraph>>[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<blockQuote><paragraph>[]</paragraph></blockQuote>' );
@@ -190,7 +190,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace greater-than character when inside heading', () => {
 			setData( doc, '<heading1>>[]</heading1>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<heading1>> []</heading1>' );
@@ -199,7 +199,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace greater-than character when inside numbered list', () => {
 			setData( doc, '<listItem indent="0" type="numbered">1. >[]</listItem>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">1. > []</listItem>' );
@@ -208,7 +208,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace greater-than character when inside buletted list', () => {
 			setData( doc, '<listItem indent="0" type="bulleted">1. >[]</listItem>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">1. > []</listItem>' );
@@ -219,7 +219,7 @@ describe( 'Autoformat', () => {
 		it( 'should replace both "**" with bold', () => {
 			setData( doc, '<paragraph>**foobar*[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '*' );
+				batch.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph><$text bold="true">foobar</$text>[]</paragraph>' );
@@ -228,7 +228,7 @@ describe( 'Autoformat', () => {
 		it( 'should replace both "*" with italic', () => {
 			setData( doc, '<paragraph>*foobar[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '*' );
+				batch.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph><$text italic="true">foobar</$text>[]</paragraph>' );
@@ -237,7 +237,7 @@ describe( 'Autoformat', () => {
 		it( 'should replace both "`" with code', () => {
 			setData( doc, '<paragraph>`foobar[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '`' );
+				batch.insertText( '`', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph><$text code="true">foobar</$text>[]</paragraph>' );
@@ -246,7 +246,7 @@ describe( 'Autoformat', () => {
 		it( 'nothing should be replaces when typing "*"', () => {
 			setData( doc, '<paragraph>foobar[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '*' );
+				batch.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>foobar*[]</paragraph>' );
@@ -255,7 +255,7 @@ describe( 'Autoformat', () => {
 		it( 'should format inside the text', () => {
 			setData( doc, '<paragraph>foo **bar*[] baz</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '*' );
+				batch.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>foo <$text bold="true">bar</$text>[] baz</paragraph>' );
@@ -278,7 +278,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace asterisk with bulleted list item', () => {
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>* []</paragraph>' );
@@ -287,7 +287,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace minus character with bulleted list item', () => {
 			setData( doc, '<paragraph>-[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>- []</paragraph>' );
@@ -296,7 +296,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace digit with numbered list item', () => {
 			setData( doc, '<paragraph>1.[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>1. []</paragraph>' );
@@ -305,7 +305,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace hash character with heading', () => {
 			setData( doc, '<paragraph>#[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph># []</paragraph>' );
@@ -314,7 +314,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace two hash characters with heading level 2', () => {
 			setData( doc, '<paragraph>##[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>## []</paragraph>' );
@@ -323,7 +323,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace both "**" with bold', () => {
 			setData( doc, '<paragraph>**foobar*[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '*' );
+				batch.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>**foobar**[]</paragraph>' );
@@ -332,7 +332,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace both "*" with italic', () => {
 			setData( doc, '<paragraph>*foobar[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '*' );
+				batch.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
@@ -341,7 +341,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace both "`" with code', () => {
 			setData( doc, '<paragraph>`foobar[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '`' );
+				batch.insertText( '`', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>`foobar`[]</paragraph>' );
@@ -350,7 +350,7 @@ describe( 'Autoformat', () => {
 		it( 'should not replace ">" with block quote', () => {
 			setData( doc, '<paragraph>>[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>> []</paragraph>' );
@@ -373,7 +373,7 @@ describe( 'Autoformat', () => {
 
 					setData( doc, '<paragraph>##[]</paragraph>' );
 					doc.enqueueChanges( () => {
-						batch.insert( doc.selection.getFirstPosition(), ' ' );
+						batch.insertText( ' ', doc.selection.getFirstPosition() );
 					} );
 
 					expect( getData( doc ) ).to.equal( '<paragraph>## []</paragraph>' );

+ 7 - 7
packages/ckeditor5-autoformat/tests/blockautoformatengine.js

@@ -36,7 +36,7 @@ describe( 'BlockAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			sinon.assert.calledOnce( spy );
@@ -49,7 +49,7 @@ describe( 'BlockAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insert( doc.selection.getFirstPosition(), ' ' );
+				doc.batch( 'transparent' ).insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			sinon.assert.notCalled( spy );
@@ -62,7 +62,7 @@ describe( 'BlockAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			sinon.assert.calledOnce( spy );
@@ -77,7 +77,7 @@ describe( 'BlockAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			sinon.assert.calledOnce( spy );
@@ -89,7 +89,7 @@ describe( 'BlockAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insert( doc.selection.getFirstPosition(), ' ' );
+				doc.batch( 'transparent' ).insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			sinon.assert.notCalled( spy );
@@ -113,7 +113,7 @@ describe( 'BlockAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			sinon.assert.notCalled( spy );
@@ -128,7 +128,7 @@ class TestCommand extends Command {
 	/**
 	 * Creates an instance of the command.
 	 *
-	 * @param {module:core/editor~Editor} editor Editor instance.
+	 * @param {module:core/editor/editor~Editor} editor Editor instance.
 	 * @param {Function} onExecuteCallback execute call hook
 	 */
 	constructor( editor, onExecuteCallback ) {

+ 9 - 9
packages/ckeditor5-autoformat/tests/inlineautoformatengine.js

@@ -34,7 +34,7 @@ describe( 'InlineAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*foobar[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '*' );
+				batch.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
@@ -45,7 +45,7 @@ describe( 'InlineAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*foobar[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '*' );
+				batch.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph><$text testAttribute="true">foobar</$text>[]</paragraph>' );
@@ -56,7 +56,7 @@ describe( 'InlineAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*foobar[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insert( doc.selection.getFirstPosition(), '*' );
+				doc.batch( 'transparent' ).insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
@@ -67,7 +67,7 @@ describe( 'InlineAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*foob[ar]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '*' );
+				batch.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			expect( getData( doc ) ).to.equal( '<paragraph>*foob*[ar]</paragraph>' );
@@ -81,7 +81,7 @@ describe( 'InlineAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*foobar[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insert( doc.selection.getFirstPosition(), '*' );
+				doc.batch( 'transparent' ).insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			sinon.assert.notCalled( spy );
@@ -98,7 +98,7 @@ describe( 'InlineAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			sinon.assert.notCalled( formatSpy );
@@ -115,7 +115,7 @@ describe( 'InlineAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			sinon.assert.notCalled( formatSpy );
@@ -132,7 +132,7 @@ describe( 'InlineAutoformatEngine', () => {
 
 			setData( doc, '<paragraph>[]</paragraph>' );
 			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), ' ' );
+				batch.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 
 			sinon.assert.notCalled( formatSpy );
@@ -150,7 +150,7 @@ describe( 'InlineAutoformatEngine', () => {
 			setData( doc, '<paragraph>*foobar[]</paragraph>' );
 
 			doc.enqueueChanges( () => {
-				doc.batch().insert( doc.selection.getFirstPosition(), '*' );
+				doc.batch().insertText( '*', doc.selection.getFirstPosition() );
 			} );
 
 			// There should be two removed ranges and one range used to apply autoformat.