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

Changed: RenameOperation should do nothing and return undefined if it's oldName and newName are same.

Szymon Cofalik 9 лет назад
Родитель
Сommit
676a6a473d

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

@@ -100,6 +100,14 @@ export default class RenameOperation extends Operation {
 			);
 		}
 
+		// If value to set is same as old value, don't do anything.
+		// By not returning `undefined`, this operation will be seen as `NoOperation` - that means
+		// that it won't generate any events, etc. `RenameOperation` with such parameters may be
+		// a result of Operational Transformation.
+		if ( this.oldName == this.newName ) {
+			return;
+		}
+
 		element.name = this.newName;
 
 		return { element, oldName: this.oldName };

+ 7 - 0
packages/ckeditor5-engine/tests/model/operation/renameoperation.js

@@ -94,6 +94,13 @@ describe( 'RenameOperation', () => {
 		expect( clone.newName ).to.equal( newName );
 	} );
 
+	it( 'should return undefined on execution if old name and new name is same', () => {
+		const op = new RenameOperation( Position.createAt( root, 0 ), oldName, oldName, doc.version );
+		const result = op._execute();
+
+		expect( result ).to.be.undefined;
+	} );
+
 	describe( 'toJSON', () => {
 		it( 'should create proper serialized object', () => {
 			const op = new RenameOperation( Position.createAt( root, 'end' ), oldName, newName, doc.version );