Browse Source

Check if oldAttr.key != newAttr.key may be done before a loop.

Piotr Jasiun 10 years ago
parent
commit
352f7de7ad
1 changed files with 14 additions and 15 deletions
  1. 14 15
      packages/ckeditor5-utils/src/document/changeoperation.js

+ 14 - 15
packages/ckeditor5-utils/src/document/changeoperation.js

@@ -76,23 +76,22 @@ CKEDITOR.define( [ 'document/operation', 'ckeditorerror', 'utils' ], function( O
 			}
 			// Change.
 			else {
+				if ( oldAttr.key != newAttr.key ) {
+					/**
+					 * Old and new attributes should have the same keys.
+					 *
+					 * @error operation-change-different-keys
+					 * @param {document.ChangeOperation} changeOperation
+					 * @param {document.Attribute} oldAttr
+					 * @param {document.Attribute} newAttr
+					 */
+					throw new CKEditorError(
+						'operation-change-different-keys: Old and new attributes should have the same keys.',
+						{ changeOperation: this, oldAttr: oldAttr, newAttr: newAttr } );
+				}
+
 				for ( range of ranges ) {
 					for ( value of range ) {
-						if ( oldAttr.key != newAttr.key ) {
-							/**
-							 * Old and new attributes should have the same keys.
-							 *
-							 * @error operation-change-different-keys
-							 * @param {document.ChangeOperation} changeOperation
-							 * @param {document.Node} node
-							 * @param {document.Attribute} oldAttr
-							 * @param {document.Attribute} newAttr
-							 */
-							throw new CKEditorError(
-								'operation-change-different-keys: Old and new attributes should have the same keys.',
-								{ changeOperation: this, node: value.node, oldAttr: oldAttr, newAttr: newAttr } );
-						}
-
 						if ( !value.node.hasAttr( oldAttr ) ) {
 							/**
 							 * The attribute which should be changed does not exists.