ソースを参照

Changed order of methods in classes.

Szymon Cofalik 9 年 前
コミット
a4cd392c34

+ 12 - 12
packages/ckeditor5-engine/src/command/command.js

@@ -73,6 +73,18 @@ export default class Command {
 		this.isEnabled = this.fire( 'refreshState' ) !== false;
 	}
 
+	/**
+	 * Executes the command if it is enabled.
+	 *
+	 * @protected
+	 * @param {*} param Parameter passed to {@link core.command.Command#execute execute} method of this command.
+	 */
+	doExecute( param ) {
+		if ( this.isEnabled ) {
+			this._execute( param );
+		}
+	}
+
 	/**
 	 * Disables the command. This should be used only by the command itself. Other parts of code should add
 	 * listeners to `refreshState` event.
@@ -96,18 +108,6 @@ export default class Command {
 		this.refreshState();
 	}
 
-	/**
-	 * Executes the command if it is enabled.
-	 *
-	 * @protected
-	 * @param {*} param Parameter passed to {@link core.command.Command#execute execute} method of this command.
-	 */
-	doExecute( param ) {
-		if ( this.isEnabled ) {
-			this._execute( param );
-		}
-	}
-
 	/**
 	 * Executes command.
 	 * This is an abstract method that should be overwritten in child classes.

+ 0 - 9
packages/ckeditor5-engine/src/editor.js

@@ -9,7 +9,6 @@ import ObservableMixin from './observablemixin.js';
 import EditorConfig from './editorconfig.js';
 import PluginCollection from './plugincollection.js';
 import Document from './treemodel/document.js';
-import Mapper from './treecontroller/mapper.js';
 import CKEditorError from './ckeditorerror.js';
 import Locale from './locale.js';
 import isArray from './lib/lodash/isArray.js';
@@ -75,14 +74,6 @@ export default class Editor {
 		 */
 		this.commands = new Map();
 
-		/**
-		 * Mapper that maps Tree Model into Tree View
-		 * TODO: this should probably be something else, or not here
-		 *
-		 * @member {Mapper} core.Editor#treeMapper
-		 */
-		this.treeMapper = new Mapper();
-
 		/**
 		 * @readonly
 		 * @member {core.Locale} core.Editor#locale

+ 71 - 71
packages/ckeditor5-engine/src/treemodel/schema.js

@@ -245,77 +245,6 @@ export default class Schema {
 		this._getItem( query.name ).addDisallowed( query.inside, query.attribute );
 	}
 
-	/**
-	 * Returns {@link core.treeModel.SchemaItem schema item} that was registered in the schema under given name.
-	 * If item has not been found, throws error.
-	 *
-	 * @param {String} itemName Name to look for in schema.
-	 * @returns {core.treeModel.SchemaItem} Schema item registered under given name.
-	 * @private
-	 */
-	_getItem( itemName ) {
-		if ( !this.hasItem( itemName ) ) {
-			/**
-			 * Item with specified name does not exist in schema.
-			 *
-			 * @error schema-no-item
-			 */
-			throw new CKEditorError( 'schema-no-item: Item with specified name does not exist in schema.' );
-		}
-
-		return this._items.get( itemName );
-	}
-
-	/**
-	 * Checks whether there is an item registered under given name in schema.
-	 *
-	 * @param itemName
-	 * @returns {boolean}
-	 */
-	hasItem( itemName ) {
-		return this._items.has( itemName );
-	}
-
-	/**
-	 * Registers given item name in schema.
-	 *
-	 *		// Register P element that should be treated like all block elements.
-	 *		schema.registerItem( 'p', '$block' );
-	 *
-	 * @param {String} itemName Name to register.
-	 * @param [isExtending] If set, new item will extend item with given name.
-	 */
-	registerItem( itemName, isExtending ) {
-		if ( this.hasItem( itemName ) ) {
-			/**
-			 * Item with specified name already exists in schema.
-			 *
-			 * @error schema-item-exists
-			 */
-			throw new CKEditorError( 'schema-item-exists: Item with specified name already exists in schema.' );
-		}
-
-		if ( !!isExtending && !this.hasItem( isExtending ) ) {
-			/**
-			 * Item with specified name does not exist in schema.
-			 *
-			 * @error schema-no-item
-			 */
-			throw new CKEditorError( 'schema-no-item: Item with specified name does not exist in schema.' );
-		}
-
-		// Create new SchemaItem and add it to the items store.
-		this._items.set( itemName, new SchemaItem( this ) );
-
-		// Create an extension chain.
-		// Extension chain has all item names that should be checked when that item is on path to check.
-		// This simply means, that if item is not extending anything, it should have only itself in it's extension chain.
-		// Since extending is not dynamic, we can simply get extension chain of extended item and expand it with registered name,
-		// if the registered item is extending something.
-		const chain = this.hasItem( isExtending ) ? this._extensionChains.get( isExtending ).concat( itemName ) : [ itemName ];
-		this._extensionChains.set( itemName, chain );
-	}
-
 	/**
 	 * Checks whether entity with given name (and optionally, with given attribute) is allowed at given position.
 	 *
@@ -385,6 +314,77 @@ export default class Schema {
 		return false;
 	}
 
+	/**
+	 * Checks whether there is an item registered under given name in schema.
+	 *
+	 * @param itemName
+	 * @returns {boolean}
+	 */
+	hasItem( itemName ) {
+		return this._items.has( itemName );
+	}
+
+	/**
+	 * Registers given item name in schema.
+	 *
+	 *		// Register P element that should be treated like all block elements.
+	 *		schema.registerItem( 'p', '$block' );
+	 *
+	 * @param {String} itemName Name to register.
+	 * @param [isExtending] If set, new item will extend item with given name.
+	 */
+	registerItem( itemName, isExtending ) {
+		if ( this.hasItem( itemName ) ) {
+			/**
+			 * Item with specified name already exists in schema.
+			 *
+			 * @error schema-item-exists
+			 */
+			throw new CKEditorError( 'schema-item-exists: Item with specified name already exists in schema.' );
+		}
+
+		if ( !!isExtending && !this.hasItem( isExtending ) ) {
+			/**
+			 * Item with specified name does not exist in schema.
+			 *
+			 * @error schema-no-item
+			 */
+			throw new CKEditorError( 'schema-no-item: Item with specified name does not exist in schema.' );
+		}
+
+		// Create new SchemaItem and add it to the items store.
+		this._items.set( itemName, new SchemaItem( this ) );
+
+		// Create an extension chain.
+		// Extension chain has all item names that should be checked when that item is on path to check.
+		// This simply means, that if item is not extending anything, it should have only itself in it's extension chain.
+		// Since extending is not dynamic, we can simply get extension chain of extended item and expand it with registered name,
+		// if the registered item is extending something.
+		const chain = this.hasItem( isExtending ) ? this._extensionChains.get( isExtending ).concat( itemName ) : [ itemName ];
+		this._extensionChains.set( itemName, chain );
+	}
+
+	/**
+	 * Returns {@link core.treeModel.SchemaItem schema item} that was registered in the schema under given name.
+	 * If item has not been found, throws error.
+	 *
+	 * @param {String} itemName Name to look for in schema.
+	 * @returns {core.treeModel.SchemaItem} Schema item registered under given name.
+	 * @private
+	 */
+	_getItem( itemName ) {
+		if ( !this.hasItem( itemName ) ) {
+			/**
+			 * Item with specified name does not exist in schema.
+			 *
+			 * @error schema-no-item
+			 */
+			throw new CKEditorError( 'schema-no-item: Item with specified name does not exist in schema.' );
+		}
+
+		return this._items.get( itemName );
+	}
+
 	/**
 	 * Gets position and traverses through it's parents to get their names and returns them.
 	 *

+ 54 - 57
packages/ckeditor5-engine/src/treemodel/selection.js

@@ -130,7 +130,7 @@ export default class Selection {
 	 * or backward - from end to start (`true`). Defaults to `false`.
 	 */
 	addRange( range, isBackward ) {
-		pushRange.call( this, range );
+		this._pushRange( range );
 		this._lastRangeBackward = !!isBackward;
 
 		this.fire( 'update' );
@@ -217,7 +217,7 @@ export default class Selection {
 		this._ranges = [];
 
 		for ( let i = 0; i < newRanges.length; i++ ) {
-			pushRange.call( this, newRanges[ i ] );
+			this._pushRange( newRanges[ i ] );
 		}
 
 		this._lastRangeBackward = !!isLastBackward;
@@ -225,13 +225,10 @@ export default class Selection {
 	}
 
 	/**
-	 * Checks if the selection has an attribute for given key.
-	 *
-	 * @param {String} key Key of attribute to check.
-	 * @returns {Boolean} `true` if attribute with given key is set on selection, `false` otherwise.
+	 * Removes all attributes from the selection.
 	 */
-	hasAttribute( key ) {
-		return this._attrs.has( key );
+	clearAttributes() {
+		this._attrs.clear();
 	}
 
 	/**
@@ -253,6 +250,26 @@ export default class Selection {
 		return this._attrs[ Symbol.iterator ]();
 	}
 
+	/**
+	 * Checks if the selection has an attribute for given key.
+	 *
+	 * @param {String} key Key of attribute to check.
+	 * @returns {Boolean} `true` if attribute with given key is set on selection, `false` otherwise.
+	 */
+	hasAttribute( key ) {
+		return this._attrs.has( key );
+	}
+
+	/**
+	 * Removes an attribute with given key from the selection.
+	 *
+	 * @param {String} key Key of attribute to remove.
+	 * @returns {Boolean} `true` if the attribute was set on the selection, `false` otherwise.
+	 */
+	removeAttribute( key ) {
+		return this._attrs.delete( key );
+	}
+
 	/**
 	 * Sets attribute on the selection. If attribute with the same key already is set, it overwrites its values.
 	 *
@@ -273,30 +290,30 @@ export default class Selection {
 	}
 
 	/**
-	 * Removes an attribute with given key from the selection.
+	 * Converts given range to {@link core.treeModel.LiveRange} and adds it to internal ranges array. Throws an error
+	 * if given range is intersecting with any range that is already stored in this selection.
 	 *
-	 * @param {String} key Key of attribute to remove.
-	 * @returns {Boolean} `true` if the attribute was set on the selection, `false` otherwise.
-	 */
-	removeAttribute( key ) {
-		return this._attrs.delete( key );
-	}
-
-	/**
-	 * Removes all attributes from the selection.
+	 * @private
+	 * @param {core.treeModel.Range} range Range to add.
 	 */
-	clearAttributes() {
-		this._attrs.clear();
-	}
+	_pushRange( range ) {
+		for ( let i = 0; i < this._ranges.length ; i++ ) {
+			if ( range.isIntersecting( this._ranges[ i ] ) ) {
+				/**
+				 * Trying to add a range that intersects with another range from selection.
+				 *
+				 * @error selection-range-intersects
+				 * @param {core.treeModel.Range} addedRange Range that was added to the selection.
+				 * @param {core.treeModel.Range} intersectingRange Range from selection that intersects with `addedRange`.
+				 */
+				throw new CKEditorError(
+					'selection-range-intersects: Trying to add a range that intersects with another range from selection.',
+					{ addedRange: range, intersectingRange: this._ranges[ i ] }
+				);
+			}
+		}
 
-	/**
-	 * Generates and returns an attribute key for selection attributes store, basing on original attribute key.
-	 *
-	 * @param {String} key Attribute key to convert.
-	 * @returns {String} Converted attribute key, applicable for selection store.
-	 */
-	static getStoreAttributeKey( key ) {
-		return storePrefix + key;
+		this._ranges.push( LiveRange.createFromRange( range ) );
 	}
 
 	/**
@@ -319,36 +336,16 @@ export default class Selection {
 
 		return filtered;
 	}
-}
 
-/**
- * Converts given range to {@link core.treeModel.LiveRange} and adds it to internal ranges array. Throws an error
- * if given range is intersecting with any range that is already stored in this selection.
- *
- * @private
- * @method pushRange
- * @memberOf {core.treeModel.Selection}
- * @param {core.treeModel.Range} range Range to add.
- */
-function pushRange( range ) {
-	/* jshint validthis: true */
-	for ( let i = 0; i < this._ranges.length ; i++ ) {
-		if ( range.isIntersecting( this._ranges[ i ] ) ) {
-			/**
-			 * Trying to add a range that intersects with another range from selection.
-			 *
-			 * @error selection-range-intersects
-			 * @param {core.treeModel.Range} addedRange Range that was added to the selection.
-			 * @param {core.treeModel.Range} intersectingRange Range from selection that intersects with `addedRange`.
-			 */
-			throw new CKEditorError(
-				'selection-range-intersects: Trying to add a range that intersects with another range from selection.',
-				{ addedRange: range, intersectingRange: this._ranges[ i ] }
-			);
-		}
+	/**
+	 * Generates and returns an attribute key for selection attributes store, basing on original attribute key.
+	 *
+	 * @param {String} key Attribute key to convert.
+	 * @returns {String} Converted attribute key, applicable for selection store.
+	 */
+	static getStoreAttributeKey( key ) {
+		return storePrefix + key;
 	}
-
-	this._ranges.push( LiveRange.createFromRange( range ) );
 }
 
 utils.mix( Selection, EmitterMixin );