Browse Source

Removed config.heading.defaultOptionId.

Aleksander Nowodzinski 8 years ago
parent
commit
7a66802f01

+ 11 - 2
packages/ckeditor5-heading/src/headingcommand.js

@@ -22,7 +22,7 @@ export default class HeadingCommand extends Command {
 	 * @param {module:core/editor/editor~Editor} editor Editor instance.
 	 * @param {Array.<module:heading/headingcommand~HeadingOption>} options Heading options to be used by the command instance.
 	 */
-	constructor( editor, options ) {
+	constructor( editor, options, defaultOptionId ) {
 		super( editor );
 
 		/**
@@ -34,6 +34,15 @@ export default class HeadingCommand extends Command {
 		this.options = options;
 
 		/**
+		 * The id of the default option among {@link #options}.
+		 *
+		 * @readonly
+		 * @private
+		 * @member {module:heading/headingcommand~HeadingOption#id}
+		 */
+		this._defaultOptionId = defaultOptionId;
+
+		/**
 		 * The currently selected heading option.
 		 *
 		 * @readonly
@@ -53,7 +62,7 @@ export default class HeadingCommand extends Command {
 	 */
 	get defaultOption() {
 		// See https://github.com/ckeditor/ckeditor5/issues/98.
-		return this._getOptionById( this.editor.config.get( 'heading.defaultOptionId' ) );
+		return this._getOptionById( this._defaultOptionId );
 	}
 
 	/**

+ 4 - 4
packages/ckeditor5-heading/src/headingengine.js

@@ -13,6 +13,8 @@ import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildv
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import HeadingCommand from './headingcommand';
 
+const defaultOptionId = 'paragraph';
+
 /**
  * The headings engine feature. It handles switching between block formats &ndash; headings and paragraph.
  * This class represents the engine part of the heading feature. See also {@link module:heading/heading~Heading}.
@@ -32,8 +34,7 @@ export default class HeadingEngine extends Plugin {
 				{ id: 'heading1', element: 'h2', label: 'Heading 1' },
 				{ id: 'heading2', element: 'h3', label: 'Heading 2' },
 				{ id: 'heading3', element: 'h4', label: 'Heading 3' }
-			],
-			defaultOptionId: 'paragraph'
+			]
 		} );
 	}
 
@@ -52,7 +53,6 @@ export default class HeadingEngine extends Plugin {
 		const data = editor.data;
 		const editing = editor.editing;
 		const options = this._getLocalizedOptions();
-		const defaultOptionId = editor.config.get( 'heading.defaultOptionId' );
 
 		for ( let option of options ) {
 			// Skip paragraph - it is defined in required Paragraph feature.
@@ -73,7 +73,7 @@ export default class HeadingEngine extends Plugin {
 		}
 
 		// Register the heading command.
-		const command = new HeadingCommand( editor, options );
+		const command = new HeadingCommand( editor, options, defaultOptionId );
 		editor.commands.set( 'heading', command );
 	}
 

+ 4 - 9
packages/ckeditor5-heading/tests/headingcommand.js

@@ -9,7 +9,7 @@ import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 const options = [
-	{ id: 'paragraph', element: 'p', default: true },
+	{ id: 'paragraph', element: 'p' },
 	{ id: 'heading1', element: 'h2' },
 	{ id: 'heading2', element: 'h3' },
 	{ id: 'heading3', element: 'h4' }
@@ -19,15 +19,10 @@ describe( 'HeadingCommand', () => {
 	let editor, document, command, root, schema;
 
 	beforeEach( () => {
-		return ModelTestEditor.create( {
-			heading: {
-				defaultOptionId: 'paragraph'
-			}
-		} )
-		.then( newEditor => {
+		return ModelTestEditor.create().then( newEditor => {
 			editor = newEditor;
 			document = editor.document;
-			command = new HeadingCommand( editor, options );
+			command = new HeadingCommand( editor, options, 'paragraph' );
 			schema = document.schema;
 
 			for ( let option of options ) {
@@ -57,7 +52,7 @@ describe( 'HeadingCommand', () => {
 			} );
 		}
 
-		it( 'should be equal to defaultOption if option has not been found', () => {
+		it( 'should be equal to #defaultOption if option has not been found', () => {
 			schema.registerItem( 'div', '$block' );
 			setData( document, '<div>xyz</div>' );
 			const element = root.getChild( 0 );

+ 0 - 31
packages/ckeditor5-heading/tests/headingengine.js

@@ -140,36 +140,5 @@ describe( 'HeadingEngine', () => {
 				} );
 			} );
 		} );
-
-		describe( 'defaultOptionId', () => {
-			it( 'should have default value', () => {
-				expect( editor.config.get( 'heading.defaultOptionId' ) ).to.equal( 'paragraph' );
-			} );
-
-			it( 'should customize options', () => {
-				return VirtualTestEditor.create( {
-					plugins: [ Enter, HeadingEngine ],
-					heading: {
-						options: [
-							{ id: 'foo', element: 'f', label: 'Foo' },
-							{ id: 'bar', element: 'b', label: 'Bar' }
-						],
-						defaultOptionId: 'bar'
-					}
-				} )
-				.then( editor => {
-					document = editor.document;
-
-					expect( editor.commands.get( 'heading' ).value ).to.deep.equal( {
-						id: 'bar',
-						element: 'b',
-						label: 'Bar'
-					} );
-
-					expect( document.schema.hasItem( 'foo' ) ).to.be.true;
-					expect( document.schema.hasItem( 'bar' ) ).to.be.false;
-				} );
-			} );
-		} );
 	} );
 } );