Forráskód Böngészése

Added styles cloning to treeView.Element#clone method.

Szymon Kupś 9 éve
szülő
commit
5d188be5b4

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

@@ -119,9 +119,10 @@ export default class Element extends Node {
 
 		const cloned = new Element( this.name, this._attrs, childrenClone );
 
-		// Classes are cloned separately - it solution is faster than adding them back to attributes and
+		// Classes and styles are cloned separately - it solution is faster than adding them back to attributes and
 		// parse once again in constructor.
 		cloned._classes = new Set( this._classes );
+		cloned._styles = new Map( this._styles );
 
 		return cloned;
 	}

+ 13 - 1
packages/ckeditor5-engine/tests/treeview/element.js

@@ -123,7 +123,7 @@ describe( 'Element', () => {
 			expect( clone.getChildCount() ).to.equal( 0 );
 		} );
 
-		it( 'should clone when with class attribute', () => {
+		it( 'should clone class attribute', () => {
 			const el = new ViewElement( 'p', { foo: 'bar' } );
 			el.addClass( 'baz', 'qux' );
 			const clone = el.clone( false );
@@ -133,6 +133,18 @@ describe( 'Element', () => {
 			expect( clone.getAttribute( 'foo' ) ).to.equal( 'bar' );
 			expect( clone.getAttribute( 'class' ) ).to.equal( 'baz qux' );
 		} );
+
+		it( 'should clone style attribute', () => {
+			const el = new ViewElement( 'p', { style: 'color: red; font-size: 12px;' } );
+			const clone = el.clone( false );
+
+			expect( clone ).to.not.equal( el );
+			expect( clone.name ).to.equal( el.name );
+			expect( clone._styles.has( 'color' ) ).to.be.true;
+			expect( clone._styles.get( 'color' ) ).to.equal( 'red' );
+			expect( clone._styles.has( 'font-size' ) ).to.be.true;
+			expect( clone._styles.get( 'font-size' ) ).to.equal( '12px' );
+		} );
 	} );
 
 	describe( 'isSimilar', () => {