Преглед изворни кода

Changed: Refactor FontFamilyCommand to match FontSizeCommand.

Maciej Gołaszewski пре 8 година
родитељ
комит
9243445988
1 измењених фајлова са 18 додато и 21 уклоњено
  1. 18 21
      packages/ckeditor5-font/src/fontfamily/fontfamilycommand.js

+ 18 - 21
packages/ckeditor5-font/src/fontfamily/fontfamilycommand.js

@@ -13,16 +13,16 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
  * The font family command. It is used by the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing}
  * The font family command. It is used by the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing}
  * to apply font family.
  * to apply font family.
  *
  *
+ * TODO: those commands are duplicated here and there - maybe make them one?
+ *
  * @extends module:core/command~Command
  * @extends module:core/command~Command
  */
  */
 export default class FontFamilyCommand extends Command {
 export default class FontFamilyCommand extends Command {
-	constructor( editor, fontFamily ) {
-		super( editor );
-
-		/**
-		 * Name of font family config.
-		 */
-		this.fontFamily = fontFamily;
+	/**
+	 * @inheritDoc
+	 */
+	refresh() {
+		const doc = this.editor.model.document;
 
 
 		/**
 		/**
 		 * A flag indicating whether the command is active, which means that the selection has fontFamily attribute set.
 		 * A flag indicating whether the command is active, which means that the selection has fontFamily attribute set.
@@ -31,15 +31,7 @@ export default class FontFamilyCommand extends Command {
 		 * @readonly
 		 * @readonly
 		 * @member {Boolean} module:font/fontfamilycommand~FontFamilyCommand#value
 		 * @member {Boolean} module:font/fontfamilycommand~FontFamilyCommand#value
 		 */
 		 */
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	refresh() {
-		const doc = this.editor.model.document;
-
-		this.value = doc.selection.getAttribute( 'fontFamily' ) === this.fontFamily;
+		this.value = doc.selection.getAttribute( 'fontFamily' );
 		this.isEnabled = this.editor.model.schema.checkAttributeInSelection( doc.selection, 'fontFamily' );
 		this.isEnabled = this.editor.model.schema.checkAttributeInSelection( doc.selection, 'fontFamily' );
 	}
 	}
 
 
@@ -48,24 +40,29 @@ export default class FontFamilyCommand extends Command {
 	 *
 	 *
 	 * @protected
 	 * @protected
 	 * @param {Object} [options] Options for the executed command.
 	 * @param {Object} [options] Options for the executed command.
-	 * @param {module:engine/model/batch~Batch} [options.batch] A batch to collect all the change steps.
-	 * A new batch will be created if this option is not set.
+	 * @param {String} [options.fontSize] FontSize value to apply.
 	 */
 	 */
-	execute() {
+	execute( options ) {
 		const model = this.editor.model;
 		const model = this.editor.model;
 		const document = model.document;
 		const document = model.document;
 		const selection = document.selection;
 		const selection = document.selection;
 
 
-		// Do not apply fontFamily on collapsed selection.
+		// Do not apply fontSize on collapsed selection.
 		if ( selection.isCollapsed ) {
 		if ( selection.isCollapsed ) {
 			return;
 			return;
 		}
 		}
 
 
+		const value = options.fontSize;
+
 		model.change( writer => {
 		model.change( writer => {
 			const ranges = model.schema.getValidRanges( selection.getRanges(), 'fontFamily' );
 			const ranges = model.schema.getValidRanges( selection.getRanges(), 'fontFamily' );
 
 
 			for ( const range of ranges ) {
 			for ( const range of ranges ) {
-				writer.setAttribute( 'fontFamily', this.fontFamily, range );
+				if ( value !== 'normal' ) {
+					writer.setAttribute( 'fontFamily', value, range );
+				} else {
+					writer.removeAttribute( 'fontFamily', range );
+				}
 			}
 			}
 		} );
 		} );
 	}
 	}