Răsfoiți Sursa

Split indent block feature initialization to init and afterInit.

The schema extending rules must be done in afterInit and
all core indent block behavior should be done during
the init phase.
Maciej Gołaszewski 6 ani în urmă
părinte
comite
0e06819c23
1 a modificat fișierele cu 19 adăugiri și 11 ștergeri
  1. 19 11
      packages/ckeditor5-indent/src/indentblock.js

+ 19 - 11
packages/ckeditor5-indent/src/indentblock.js

@@ -46,20 +46,10 @@ export default class IndentBlock extends Plugin {
 	/**
 	 * @inheritDoc
 	 */
-	afterInit() {
+	init() {
 		const editor = this.editor;
-		const schema = editor.model.schema;
 		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 indentConfig = Object.assign( { direction: 'forward' }, configuration );
@@ -67,6 +57,7 @@ export default class IndentBlock extends Plugin {
 
 		if ( useOffsetConfig ) {
 			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 {
@@ -74,10 +65,27 @@ 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 schema = editor.model.schema;
 
 		const indentCommand = editor.commands.get( 'indent' );
 		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' ) );
 		outdentCommand.registerChildCommand( editor.commands.get( 'outdentBlock' ) );
 	}