Parcourir la source

Added last missing test, removed dead code.

Maciej Bukowski il y a 8 ans
Parent
commit
98cf87612b

+ 2 - 4
packages/ckeditor5-engine/src/model/documentselection.js

@@ -740,10 +740,8 @@ class LiveSelection extends Selection {
 				continue;
 			}
 
-			// Attribute still might not get removed because of priorities.
-			if ( this._removeAttribute( oldKey, false ) ) {
-				changed.add( oldKey );
-			}
+			// All rest attributes will be removed so changed attributes won't change .
+			this._removeAttribute( oldKey, false );
 		}
 
 		for ( const [ key, value ] of attrs ) {

+ 20 - 0
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -619,6 +619,26 @@ describe( 'DocumentSelection', () => {
 				expect( spyAttribute.called ).to.be.false;
 			} );
 
+			it( 'should not overwrite previously set attributes with same values', () => {
+				selection._setAttribute( 'foo', 'xyz' );
+
+				const spyAttribute = sinon.spy();
+				selection.on( 'change:attribute', spyAttribute );
+
+				model.applyOperation( wrapInDelta(
+					new AttributeOperation(
+						new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 5 ] ) ),
+						'foo',
+						null,
+						'xyz',
+						doc.version
+					)
+				) );
+
+				expect( selection.getAttribute( 'foo' ) ).to.equal( 'xyz' );
+				expect( spyAttribute.called ).to.be.false;
+			} );
+
 			it( 'should not overwrite previously removed attributes', () => {
 				selection._setAttribute( 'foo', 'xyz' );
 				selection._removeAttribute( 'foo' );