8
0
Просмотр исходного кода

Restore logic for model: check in Element#is() and RootElement#is().

Maciej Gołaszewski 5 лет назад
Родитель
Сommit
7e87e82928

+ 6 - 3
packages/ckeditor5-engine/src/model/element.js

@@ -117,10 +117,13 @@ export default class Element extends Node {
 	 */
 	 */
 	is( type, name = null ) {
 	is( type, name = null ) {
 		if ( !name ) {
 		if ( !name ) {
-			return type == 'element' || type == this.name || type == 'node';
-		} else {
-			return type == 'element' && name == this.name;
+			return type === 'element' || type === 'model:element' ||
+				type === this.name || type === 'model:' + this.name ||
+				// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
+				type === 'node' || type === 'model:node';
 		}
 		}
+
+		return name === this.name && ( type === 'element' || type === 'model:element' );
 	}
 	}
 
 
 	/**
 	/**

+ 0 - 9
packages/ckeditor5-engine/src/model/node.js

@@ -10,7 +10,6 @@
 import toMap from '@ckeditor/ckeditor5-utils/src/tomap';
 import toMap from '@ckeditor/ckeditor5-utils/src/tomap';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
 import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
-
 // To check if component is loaded more than once.
 // To check if component is loaded more than once.
 import '@ckeditor/ckeditor5-utils/src/version';
 import '@ckeditor/ckeditor5-utils/src/version';
 
 
@@ -500,11 +499,3 @@ export default class Node {
 		this._attrs.clear();
 		this._attrs.clear();
 	}
 	}
 }
 }
-
-/**
- * The node's parent does not contain this node.
- *
- * This error may be thrown from corrupted trees.
- *
- * @error model-node-not-found-in-parent
- */

+ 12 - 3
packages/ckeditor5-engine/src/model/rootelement.js

@@ -81,10 +81,18 @@ export default class RootElement extends Element {
 	 */
 	 */
 	is( type, name ) {
 	is( type, name ) {
 		if ( !name ) {
 		if ( !name ) {
-			return type == 'rootElement' || type == 'element' || type == this.name || type == 'node';
-		} else {
-			return ( type == 'rootElement' && name == this.name ) || ( type === 'element' && name == this.name );
+			return type === 'rootElement' || type === 'model:rootElement' ||
+				// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
+				type === 'element' || type === 'model:element' ||
+				type === this.name || type === 'model:' + this.name ||
+				type === 'node' || type === 'model:node';
 		}
 		}
+
+		return name === this.name && (
+			type === 'rootElement' || type === 'model:rootElement' ||
+			// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
+			type === 'element' || type === 'model:element'
+		);
 	}
 	}
 
 
 	/**
 	/**
@@ -104,3 +112,4 @@ export default class RootElement extends Element {
 	// @if CK_DEBUG_ENGINE // 	console.log( 'ModelRootElement: ' + this );
 	// @if CK_DEBUG_ENGINE // 	console.log( 'ModelRootElement: ' + this );
 	// @if CK_DEBUG_ENGINE // }
 	// @if CK_DEBUG_ENGINE // }
 }
 }
+