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

Merge branch 'master' into i/3287

Maciej Gołaszewski 6 лет назад
Родитель
Сommit
bfa40512be

+ 13 - 12
packages/ckeditor5-indent/src/indentblock.js

@@ -48,26 +48,16 @@ export default class IndentBlock extends Plugin {
 	 */
 	 */
 	init() {
 	init() {
 		const editor = this.editor;
 		const editor = this.editor;
-		const schema = editor.model.schema;
-		const conversion = editor.conversion;
 		const configuration = editor.config.get( 'indentBlock' );
 		const configuration = editor.config.get( 'indentBlock' );
 
 
-		// Enable block indentation by default in paragraph and default headings.
-		const knownElements = [ 'paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6' ];
-
-		knownElements.forEach( elementName => {
-			if ( schema.isRegistered( elementName ) ) {
-				schema.extend( elementName, { allowAttributes: 'blockIndent' } );
-			}
-		} );
-
 		const useOffsetConfig = !configuration.classes || !configuration.classes.length;
 		const useOffsetConfig = !configuration.classes || !configuration.classes.length;
 
 
 		const indentConfig = Object.assign( { direction: 'forward' }, configuration );
 		const indentConfig = Object.assign( { direction: 'forward' }, configuration );
 		const outdentConfig = Object.assign( { direction: 'backward' }, configuration );
 		const outdentConfig = Object.assign( { direction: 'backward' }, configuration );
 
 
 		if ( useOffsetConfig ) {
 		if ( useOffsetConfig ) {
-			this._setupConversionUsingOffset( conversion );
+			this._setupConversionUsingOffset( editor.conversion );
+
 			editor.commands.add( 'indentBlock', new IndentBlockCommand( editor, new IndentUsingOffset( indentConfig ) ) );
 			editor.commands.add( 'indentBlock', new IndentBlockCommand( editor, new IndentUsingOffset( indentConfig ) ) );
 			editor.commands.add( 'outdentBlock', new IndentBlockCommand( editor, new IndentUsingOffset( outdentConfig ) ) );
 			editor.commands.add( 'outdentBlock', new IndentBlockCommand( editor, new IndentUsingOffset( outdentConfig ) ) );
 		} else {
 		} else {
@@ -82,9 +72,20 @@ export default class IndentBlock extends Plugin {
 	 */
 	 */
 	afterInit() {
 	afterInit() {
 		const editor = this.editor;
 		const editor = this.editor;
+		const schema = editor.model.schema;
+
 		const indentCommand = editor.commands.get( 'indent' );
 		const indentCommand = editor.commands.get( 'indent' );
 		const outdentCommand = editor.commands.get( 'outdent' );
 		const outdentCommand = editor.commands.get( 'outdent' );
 
 
+		// Enable block indentation by default in paragraph and default headings.
+		const knownElements = [ 'paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6' ];
+
+		knownElements.forEach( elementName => {
+			if ( schema.isRegistered( elementName ) ) {
+				schema.extend( elementName, { allowAttributes: 'blockIndent' } );
+			}
+		} );
+
 		indentCommand.registerChildCommand( editor.commands.get( 'indentBlock' ) );
 		indentCommand.registerChildCommand( editor.commands.get( 'indentBlock' ) );
 		outdentCommand.registerChildCommand( editor.commands.get( 'outdentBlock' ) );
 		outdentCommand.registerChildCommand( editor.commands.get( 'outdentBlock' ) );
 	}
 	}

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

@@ -13,7 +13,7 @@ import IndentEditing from '../src/indentediting';
 import IndentBlock from '../src/indentblock';
 import IndentBlock from '../src/indentblock';
 
 
 describe( 'IndentBlock - integration', () => {
 describe( 'IndentBlock - integration', () => {
-	let editor, model, doc;
+	let editor, doc;
 
 
 	testUtils.createSinonSandbox();
 	testUtils.createSinonSandbox();
 
 
@@ -28,8 +28,7 @@ describe( 'IndentBlock - integration', () => {
 			return createTestEditor( { indentBlock: { offset: 50, unit: 'px' } } )
 			return createTestEditor( { indentBlock: { offset: 50, unit: 'px' } } )
 				.then( newEditor => {
 				.then( newEditor => {
 					editor = 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' }
 				indentBlock: { offset: 50, unit: 'px' }
 			} ).then( newEditor => {
 			} ).then( newEditor => {
 				editor = newEditor;
 				editor = newEditor;
-				model = editor.model;
-				doc = model.document;
+				doc = editor.model.document;
 			} );
 			} );
 		} );
 		} );
 
 
@@ -73,6 +71,23 @@ describe( 'IndentBlock - integration', () => {
 		} );
 		} );
 	} );
 	} );
 
 
+	// https://github.com/ckeditor/ckeditor5/issues/2359
+	it( 'should work with paragraphs 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 = {} ) {
 	function createTestEditor( extraConfig = {} ) {
 		return VirtualTestEditor
 		return VirtualTestEditor
 			.create( Object.assign( {
 			.create( Object.assign( {