浏览代码

Changed the way of checking if operaton is a document operation.

Oskar Wróbel 8 年之前
父节点
当前提交
18b01a40fe

+ 5 - 7
packages/ckeditor5-engine/src/model/operation/attributeoperation.js

@@ -73,6 +73,11 @@ export default class AttributeOperation extends Operation {
 		 * @member {*}
 		 */
 		this.newValue = newValue === undefined ? null : newValue;
+
+		/**
+		 * @inheritDoc
+		 */
+		this.isDocumentOperation = !!this.range.root.document;
 	}
 
 	/**
@@ -89,13 +94,6 @@ export default class AttributeOperation extends Operation {
 	}
 
 	/**
-	 * @inheritDoc
-	 */
-	get isDocumentOperation() {
-		return !!this.range.root.document;
-	}
-
-	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 * @returns {module:engine/model/operation/attributeoperation~AttributeOperation} Clone of this operation.

+ 5 - 7
packages/ckeditor5-engine/src/model/operation/detachoperation.js

@@ -45,6 +45,11 @@ export default class DetachOperation extends Operation {
 		 * @member {Number} #howMany
 		 */
 		this.howMany = howMany;
+
+		/**
+		 * @inheritDoc
+		 */
+		this.isDocumentOperation = false;
 	}
 
 	/**
@@ -57,13 +62,6 @@ export default class DetachOperation extends Operation {
 	/**
 	 * @inheritDoc
 	 */
-	get isDocumentOperation() {
-		return false;
-	}
-
-	/**
-	 * @inheritDoc
-	 */
 	_execute() {
 		if ( this.sourcePosition.root.document ) {
 			/**

+ 5 - 7
packages/ckeditor5-engine/src/model/operation/insertoperation.js

@@ -46,6 +46,11 @@ export default class InsertOperation extends Operation {
 		 * @member {module:engine/model/nodelist~NodeList} module:engine/model/operation/insertoperation~InsertOperation#nodeList
 		 */
 		this.nodes = new NodeList( normalizeNodes( nodes ) );
+
+		/**
+		 * @inheritDoc
+		 */
+		this.isDocumentOperation = !!this.position.root.document;
 	}
 
 	/**
@@ -56,13 +61,6 @@ export default class InsertOperation extends Operation {
 	}
 
 	/**
-	 * @inheritDoc
-	 */
-	get isDocumentOperation() {
-		return !!this.position.root.document;
-	}
-
-	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 * @returns {module:engine/model/operation/insertoperation~InsertOperation} Clone of this operation.

+ 9 - 2
packages/ckeditor5-engine/src/model/operation/markeroperation.js

@@ -55,6 +55,11 @@ export default class MarkerOperation extends Operation {
 		 * @member {module:engine/model/markercollection~MarkerCollection}
 		 */
 		this._markers = markers;
+
+		/**
+		 * @inheritDoc
+		 */
+		this.isDocumentOperation = this._isDocumentOperation();
 	}
 
 	/**
@@ -65,9 +70,11 @@ export default class MarkerOperation extends Operation {
 	}
 
 	/**
-	 * @inheritDoc
+	 * Checks if operation is executed on document or document fragment nodes.
+	 *
+	 * @private
 	 */
-	get isDocumentOperation() {
+	_isDocumentOperation() {
 		if ( this.newRange ) {
 			return !!this.newRange.root.document;
 		}

+ 11 - 9
packages/ckeditor5-engine/src/model/operation/moveoperation.js

@@ -64,6 +64,17 @@ export default class MoveOperation extends Operation {
 		 * @member {Boolean} module:engine/model/operation/moveoperation~MoveOperation#isSticky
 		 */
 		this.isSticky = false;
+
+		/**
+		 * Defines whether operation is executed on attached or detached {@link module:engine/model/item~Item items}.
+		 *
+		 * Note that range cannot be moved within different documents e.g. from docFrag to document root so
+		 * root of source and target positions is always the same.
+		 *
+		 * @readonly
+		 * @member {Boolean} #isDocumentOperation
+		 */
+		this.isDocumentOperation = !!this.targetPosition.root.document;
 	}
 
 	/**
@@ -74,15 +85,6 @@ export default class MoveOperation extends Operation {
 	}
 
 	/**
-	 * @inheritDoc
-	 */
-	get isDocumentOperation() {
-		// Note that range cannot be moved within different documents e.g. from docFrag to document root so
-		// root of source and target positions will be always the same.
-		return !!this.targetPosition.root.document;
-	}
-
-	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 * @returns {module:engine/model/operation/moveoperation~MoveOperation} Clone of this operation.

+ 12 - 7
packages/ckeditor5-engine/src/model/operation/nooperation.js

@@ -20,6 +20,18 @@ import Operation from './operation';
  * @extends module:engine/model/operation/operation~Operation
  */
 export default class NoOperation extends Operation {
+	/**
+	 * @inheritDoc
+	 */
+	constructor( baseVersion ) {
+		super( baseVersion );
+
+		/**
+		 * @inheritDoc
+		 */
+		this.isDocumentOperation = true;
+	}
+
 	get type() {
 		return 'noop';
 	}
@@ -45,13 +57,6 @@ export default class NoOperation extends Operation {
 	/**
 	 * @inheritDoc
 	 */
-	get isDocumentOperation() {
-		return true;
-	}
-
-	/**
-	 * @inheritDoc
-	 */
 	_execute() {
 		return {};
 	}

+ 3 - 0
packages/ckeditor5-engine/src/model/operation/operation.js

@@ -97,6 +97,9 @@ export default class Operation {
 		// Remove parent delta to avoid circular dependencies.
 		delete json.delta;
 
+		// Only document operations are shared with other clients so it is not necessary to keep this information.
+		delete json.isDocumentOperation;
+
 		return json;
 	}
 

+ 15 - 9
packages/ckeditor5-engine/src/model/operation/reinsertoperation.js

@@ -19,6 +19,21 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  */
 export default class ReinsertOperation extends MoveOperation {
 	/**
+	 * @inheritDocs
+	 */
+	constructor( sourcePosition, howMany, targetPosition, baseVersion ) {
+		super( sourcePosition, howMany, targetPosition, baseVersion );
+
+		/**
+		 * Reinsert operation is always executed on attached items.
+		 *
+		 * @readonly
+		 * @member {Boolean}
+		 */
+		this.isDocumentOperation = true;
+	}
+
+	/**
 	 * Position where nodes will be re-inserted.
 	 *
 	 * @type {module:engine/model/position~Position}
@@ -42,15 +57,6 @@ export default class ReinsertOperation extends MoveOperation {
 	}
 
 	/**
-	 * Reinsert operation is always executed on attached items.
-	 *
-	 * @member {Boolean}
-	 */
-	get isDocumentOperation() {
-		return true;
-	}
-
-	/**
 	 * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
 	 *
 	 * @returns {module:engine/model/operation/removeoperation~RemoveOperation}

+ 15 - 9
packages/ckeditor5-engine/src/model/operation/removeoperation.js

@@ -16,20 +16,26 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  */
 export default class RemoveOperation extends MoveOperation {
 	/**
-	 * @inheritDoc
+	 * @inheritDocs
 	 */
-	get type() {
-		return 'remove';
+	constructor( sourcePosition, howMany, targetPosition, baseVersion ) {
+		super( sourcePosition, howMany, targetPosition, baseVersion );
+
+		/**
+		 * Remove operation cannot be applied on element that is not inside the document
+		 * so this will always be a document operation.
+		 *
+		 * @readonly
+		 * @member {Boolean}
+		 */
+		this.isDocumentOperation = true;
 	}
 
 	/**
-	 * Remove operation cannot be applied on element that is not inside the document
-	 * so this will always be a document operation.
-	 *
-	 * @member {Boolean}
+	 * @inheritDoc
 	 */
-	get isDocumentOperation() {
-		return true;
+	get type() {
+		return 'remove';
 	}
 
 	/**

+ 5 - 7
packages/ckeditor5-engine/src/model/operation/renameoperation.js

@@ -51,6 +51,11 @@ export default class RenameOperation extends Operation {
 		 * @member {String} module:engine/model/operation/renameoperation~RenameOperation#newName
 		 */
 		this.newName = newName;
+
+		/**
+		 * @inheritDoc
+		 */
+		this.isDocumentOperation = !!this.position.root.document;
 	}
 
 	/**
@@ -61,13 +66,6 @@ export default class RenameOperation extends Operation {
 	}
 
 	/**
-	 * @inheritDoc
-	 */
-	get isDocumentOperation() {
-		return !!this.position.root.document;
-	}
-
-	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 * @returns {module:engine/model/operation/renameoperation~RenameOperation} Clone of this operation.

+ 5 - 7
packages/ckeditor5-engine/src/model/operation/rootattributeoperation.js

@@ -67,6 +67,11 @@ export default class RootAttributeOperation extends Operation {
 		 * @member {*}
 		 */
 		this.newValue = newValue;
+
+		/**
+		 * @inheritDoc
+		 */
+		this.isDocumentOperation = !!this.root.document;
 	}
 
 	/**
@@ -83,13 +88,6 @@ export default class RootAttributeOperation extends Operation {
 	}
 
 	/**
-	 * @inheritDoc
-	 */
-	get isDocumentOperation() {
-		return !!this.root.document;
-	}
-
-	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 * @returns {module:engine/model/operation/rootattributeoperation~RootAttributeOperation} Clone of this operation.