Procházet zdrojové kódy

Make IndentBlock work regardless of editor plugins order.

Checking schema for registered elements should be done
in afterInit call to prevent plugin ordering related bugs.
Maciej Gołaszewski před 6 roky
rodič
revize
6212f9770e

+ 2 - 9
packages/ckeditor5-indent/src/indentblock.js

@@ -46,10 +46,9 @@ export default class IndentBlock extends Plugin {
 	/**
 	 * @inheritDoc
 	 */
-	init() {
+	afterInit() {
 		const editor = this.editor;
 		const schema = editor.model.schema;
-		const conversion = editor.conversion;
 		const configuration = editor.config.get( 'indentBlock' );
 
 		// Enable block indentation by default in paragraph and default headings.
@@ -67,7 +66,7 @@ export default class IndentBlock extends Plugin {
 		const outdentConfig = Object.assign( { direction: 'backward' }, configuration );
 
 		if ( useOffsetConfig ) {
-			this._setupConversionUsingOffset( conversion );
+			this._setupConversionUsingOffset( editor.conversion );
 			editor.commands.add( 'indentBlock', new IndentBlockCommand( editor, new IndentUsingOffset( indentConfig ) ) );
 			editor.commands.add( 'outdentBlock', new IndentBlockCommand( editor, new IndentUsingOffset( outdentConfig ) ) );
 		} else {
@@ -75,13 +74,7 @@ export default class IndentBlock extends Plugin {
 			editor.commands.add( 'indentBlock', new IndentBlockCommand( editor, new IndentUsingClasses( indentConfig ) ) );
 			editor.commands.add( 'outdentBlock', new IndentBlockCommand( editor, new IndentUsingClasses( outdentConfig ) ) );
 		}
-	}
 
-	/**
-	 * @inheritDoc
-	 */
-	afterInit() {
-		const editor = this.editor;
 		const indentCommand = editor.commands.get( 'indent' );
 		const outdentCommand = editor.commands.get( 'outdent' );
 

+ 19 - 5
packages/ckeditor5-indent/tests/indentblock-integration.js

@@ -13,7 +13,7 @@ import IndentEditing from '../src/indentediting';
 import IndentBlock from '../src/indentblock';
 
 describe( 'IndentBlock - integration', () => {
-	let editor, model, doc;
+	let editor, doc;
 
 	testUtils.createSinonSandbox();
 
@@ -28,8 +28,7 @@ describe( 'IndentBlock - integration', () => {
 			return createTestEditor( { indentBlock: { offset: 50, unit: 'px' } } )
 				.then( newEditor => {
 					editor = newEditor;
-					model = editor.model;
-					doc = model.document;
+					doc = editor.model.document;
 				} );
 		} );
 
@@ -54,8 +53,7 @@ describe( 'IndentBlock - integration', () => {
 				indentBlock: { offset: 50, unit: 'px' }
 			} ).then( newEditor => {
 				editor = newEditor;
-				model = editor.model;
-				doc = model.document;
+				doc = editor.model.document;
 			} );
 		} );
 
@@ -73,6 +71,22 @@ describe( 'IndentBlock - integration', () => {
 		} );
 	} );
 
+	it( 'should work with paragraph regardless of plugin order', () => {
+		return createTestEditor( {
+			plugins: [ IndentEditing, IndentBlock, Paragraph, HeadingEditing ],
+			indentBlock: { offset: 50, unit: 'px' }
+		} ).then( newEditor => {
+			editor = newEditor;
+			doc = editor.model.document;
+
+			editor.setData( '<p style="margin-left:50px">foo</p>' );
+
+			const paragraph = doc.getRoot().getChild( 0 );
+
+			expect( paragraph.hasAttribute( 'blockIndent' ) ).to.be.true;
+		} );
+	} );
+
 	function createTestEditor( extraConfig = {} ) {
 		return VirtualTestEditor
 			.create( Object.assign( {