Explorar el Código

Added setter for changing name of Rooteditableelement.

Oskar Wróbel hace 8 años
padre
commit
2df8fb3cce

+ 12 - 1
packages/ckeditor5-engine/src/view/rooteditableelement.js

@@ -23,7 +23,6 @@ export default class RootEditableElement extends EditableElement {
 	/**
 	 * Creates root editable element.
 	 *
-	 * @param {module:engine/view/document~Document} document {@link module:engine/view/document~Document} that is an owner of the root.
 	 * @param {String} name Node name.
 	 */
 	constructor( name ) {
@@ -56,4 +55,16 @@ export default class RootEditableElement extends EditableElement {
 	set rootName( rootName ) {
 		this.setCustomProperty( rootNameSymbol, rootName );
 	}
+
+	/**
+	 * Overrides old element name and sets new one.
+	 * This is needed because name of view root has to be changed as the same as dom root name
+	 * when dom root is attached to view root.
+	 *
+	 * @protected
+	 * @param {String} name The new name of element.
+	 */
+	set _name( name ) {
+		this.name = name;
+	}
 }

+ 12 - 0
packages/ckeditor5-engine/tests/view/rooteditableelement.js

@@ -69,6 +69,18 @@ describe( 'RootEditableElement', () => {
 		} );
 	} );
 
+	describe( '_name', () => {
+		it( 'should set new name to element', () => {
+			const el = new RootEditableElement( '$root' );
+
+			expect( el.name ).to.equal( '$root' );
+
+			el._name = 'div';
+
+			expect( el.name ).to.equal( 'div' );
+		} );
+	} );
+
 	it( 'should be cloned properly', () => {
 		const root = new RootEditableElement( 'h1' );
 		root.document = createDocumentMock();