8
0
Quellcode durchsuchen

Updated treeView.Element#clone() to clone classes too.

Szymon Kupś vor 9 Jahren
Ursprung
Commit
ee723ae6cd

+ 4 - 1
packages/ckeditor5-engine/src/treeview/element.js

@@ -97,7 +97,10 @@ export default class Element extends Node {
 			}
 		}
 
-		return new Element( this.name, this._attrs, childrenClone );
+		const cloned = new Element( this.name, this._attrs, childrenClone );
+		cloned._classes = new Set( this._classes );
+
+		return cloned;
 	}
 
 	/**

+ 11 - 0
packages/ckeditor5-engine/tests/treeview/element.js

@@ -109,6 +109,17 @@ describe( 'Element', () => {
 			expect( clone.getAttribute( 'attr2' ) ).to.equal( 'bar' );
 			expect( clone.getChildCount() ).to.equal( 0 );
 		} );
+
+		it( 'should clone when with class attribute', () => {
+			const el = new ViewElement( 'p', { foo: 'bar' } );
+			el.addClass( 'baz', 'qux' );
+			const clone = el.clone( false );
+
+			expect( clone ).to.not.equal( el );
+			expect( clone.name ).to.equal( el.name );
+			expect( clone.getAttribute( 'foo' ) ).to.equal( 'bar' );
+			expect( clone.getAttribute( 'class' ) ).to.equal( 'baz qux' );
+		} );
 	} );
 
 	describe( 'isSimilar', () => {