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

Changed: enabled element name in treeModel.RootElement. Corrected error name in treeModel.Document.

Szymon Cofalik 10 лет назад
Родитель
Сommit
d0ba5aebae

+ 21 - 20
packages/ckeditor5-engine/src/treemodel/document.js

@@ -140,26 +140,27 @@ export default class Document {
 	/**
 	/**
 	 * Creates a new top-level root.
 	 * Creates a new top-level root.
 	 *
 	 *
+	 * @param {String|Symbol} id Unique root id.
 	 * @param {String|Symbol} name Unique root name.
 	 * @param {String|Symbol} name Unique root name.
 	 * @returns {core.treeModel.RootElement} Created root.
 	 * @returns {core.treeModel.RootElement} Created root.
 	 */
 	 */
-	createRoot( name ) {
-		if ( this.roots.has( name ) ) {
+	createRoot( id, name ) {
+		if ( this.roots.has( id ) ) {
 			/**
 			/**
-			 * Root with specified name already exists.
+			 * Root with specified id already exists.
 			 *
 			 *
-			 * @error document-createRoot-name-exists
+			 * @error document-createRoot-id-exists
 			 * @param {core.treeModel.Document} doc
 			 * @param {core.treeModel.Document} doc
-			 * @param {String} name
+			 * @param {String} id
 			 */
 			 */
 			throw new CKEditorError(
 			throw new CKEditorError(
-				'document-createRoot-name-exists: Root with specified name already exists.',
-				{ name: name }
+				'document-createRoot-id-exists: Root with specified id already exists.',
+				{ id: id }
 			);
 			);
 		}
 		}
 
 
-		const root = new RootElement( this );
-		this.roots.set( name, root );
+		const root = new RootElement( this, name || id );
+		this.roots.set( id, root );
 
 
 		return root;
 		return root;
 	}
 	}
@@ -188,26 +189,26 @@ export default class Document {
 	}
 	}
 
 
 	/**
 	/**
-	 * Returns top-level root by it's name.
+	 * Returns top-level root by it's id.
 	 *
 	 *
-	 * @param {String|Symbol} name Name of the root to get.
-	 * @returns {core.treeModel.RootElement} Root registered under given name.
+	 * @param {String|Symbol} id Unique root id.
+	 * @returns {core.treeModel.RootElement} Root registered under given id.
 	 */
 	 */
-	getRoot( name ) {
-		if ( !this.roots.has( name ) ) {
+	getRoot( id ) {
+		if ( !this.roots.has( id ) ) {
 			/**
 			/**
-			 * Root with specified name does not exist.
+			 * Root with specified id does not exist.
 			 *
 			 *
-			 * @error document-createRoot-root-not-exist
-			 * @param {String} name
+			 * @error document-getRoot-root-not-exist
+			 * @param {String} id
 			 */
 			 */
 			throw new CKEditorError(
 			throw new CKEditorError(
-				'document-createRoot-root-not-exist: Root with specified name does not exist.',
-				{ name: name }
+				'document-getRoot-root-not-exist: Root with specified id does not exist.',
+				{ id: id }
 			);
 			);
 		}
 		}
 
 
-		return this.roots.get( name );
+		return this.roots.get( id );
 	}
 	}
 
 
 	_updateSelectionAttributes() {
 	_updateSelectionAttributes() {

+ 3 - 2
packages/ckeditor5-engine/src/treemodel/rootelement.js

@@ -18,9 +18,10 @@ export default class RootElement extends Element {
 	 * Creates tree root node.
 	 * Creates tree root node.
 	 *
 	 *
 	 * @param {Document} doc {@link Document} that is an owner of the root.
 	 * @param {Document} doc {@link Document} that is an owner of the root.
+	 * @param {String} name Node name.
 	 */
 	 */
-	constructor( doc ) {
-		super( 'root' );
+	constructor( doc, name ) {
+		super( name );
 
 
 		/**
 		/**
 		 * {@link core.treeModel.Document} that is an owner of this root.
 		 * {@link core.treeModel.Document} that is an owner of this root.

+ 1 - 1
packages/ckeditor5-engine/tests/attributecommand.js

@@ -22,7 +22,7 @@ beforeEach( () => {
 
 
 	editor = new Editor( element );
 	editor = new Editor( element );
 	modelDoc = editor.document;
 	modelDoc = editor.document;
-	root = modelDoc.createRoot( 'root' );
+	root = modelDoc.createRoot( 'root', 'div' );
 
 
 	command = new AttributeCommand( editor, attrKey );
 	command = new AttributeCommand( editor, attrKey );
 
 

+ 12 - 12
packages/ckeditor5-engine/tests/treemodel/document/document.js

@@ -35,26 +35,26 @@ describe( 'Document', () => {
 
 
 	describe( 'createRoot', () => {
 	describe( 'createRoot', () => {
 		it( 'should create a new RootElement, add it to roots map and return it', () => {
 		it( 'should create a new RootElement, add it to roots map and return it', () => {
-			let root = doc.createRoot( 'root' );
+			let root = doc.createRoot( 'root', 'root' );
 
 
 			expect( doc.roots.size ).to.equal( 2 );
 			expect( doc.roots.size ).to.equal( 2 );
 			expect( root ).to.be.instanceof( RootElement );
 			expect( root ).to.be.instanceof( RootElement );
 			expect( root.getChildCount() ).to.equal( 0 );
 			expect( root.getChildCount() ).to.equal( 0 );
 		} );
 		} );
 
 
-		it( 'should throw an error when trying to create a second root with the same name', () => {
-			doc.createRoot( 'root' );
+		it( 'should throw an error when trying to create a second root with the same id', () => {
+			doc.createRoot( 'root', 'root' );
 
 
 			expect(
 			expect(
 				() => {
 				() => {
-					doc.createRoot( 'root' );
+					doc.createRoot( 'root', 'root' );
 				}
 				}
-			).to.throw( CKEditorError, /document-createRoot-name-exists/ );
+			).to.throw( CKEditorError, /document-createRoot-id-exists/ );
 		} );
 		} );
 	} );
 	} );
 
 
 	describe( 'getRoot', () => {
 	describe( 'getRoot', () => {
-		it( 'should return a RootElement previously created with given name', () => {
+		it( 'should return a RootElement previously created with given id', () => {
 			let newRoot = doc.createRoot( 'root' );
 			let newRoot = doc.createRoot( 'root' );
 			let getRoot = doc.getRoot( 'root' );
 			let getRoot = doc.getRoot( 'root' );
 
 
@@ -66,7 +66,7 @@ describe( 'Document', () => {
 				() => {
 				() => {
 					doc.getRoot( 'root' );
 					doc.getRoot( 'root' );
 				}
 				}
-			).to.throw( CKEditorError, /document-createRoot-root-not-exist/ );
+			).to.throw( CKEditorError, /document-getRoot-root-not-exist/ );
 		} );
 		} );
 	} );
 	} );
 
 
@@ -175,7 +175,7 @@ describe( 'Document', () => {
 		} );
 		} );
 	} );
 	} );
 
 
-	describe( '_setSelectionAttributes', () => {
+	describe( '_updateSelectionAttributes', () => {
 		let root;
 		let root;
 		beforeEach( () => {
 		beforeEach( () => {
 			root = doc.createRoot( 'root' );
 			root = doc.createRoot( 'root' );
@@ -194,19 +194,19 @@ describe( 'Document', () => {
 		} );
 		} );
 
 
 		it( 'should be fired whenever selection gets updated', () => {
 		it( 'should be fired whenever selection gets updated', () => {
-			sinon.spy( doc, '_setSelectionAttributes' );
+			sinon.spy( doc, '_updateSelectionAttributes' );
 
 
 			doc.selection.fire( 'update' );
 			doc.selection.fire( 'update' );
 
 
-			expect( doc._setSelectionAttributes.called ).to.be.true;
+			expect( doc._updateSelectionAttributes.called ).to.be.true;
 		} );
 		} );
 
 
 		it( 'should be fired whenever changes to Tree Model are applied', () => {
 		it( 'should be fired whenever changes to Tree Model are applied', () => {
-			sinon.spy( doc, '_setSelectionAttributes' );
+			sinon.spy( doc, '_updateSelectionAttributes' );
 
 
 			doc.fire( 'changesDone' );
 			doc.fire( 'changesDone' );
 
 
-			expect( doc._setSelectionAttributes.called ).to.be.true;
+			expect( doc._updateSelectionAttributes.called ).to.be.true;
 		} );
 		} );
 
 
 		it( 'if selection is a range, should find first character in it and copy it\'s attributes', () => {
 		it( 'if selection is a range, should find first character in it and copy it\'s attributes', () => {