ソースを参照

Changed Text back to a simple class.

Szymon Cofalik 10 年 前
コミット
de412697dc

+ 1 - 29
packages/ckeditor5-engine/src/treemodel/text.js

@@ -6,11 +6,9 @@
 'use strict';
 
 import AttributeList from './attributelist.js';
-import TextNode from './textnode.js';
-import langUtils from '../lib/lodash/lang.js';
 
 /**
- * Data structure for text with attributes. Note that the `Text` is not a {@link treeModel.Node}. This class is used
+ * Data structure for text with attributes. Note that `Text` is not a {@link treeModel.Node}. This class is used
  * as an aggregator for multiple characters that have same attributes. Example usage:
  *
  *		let attrFoo = new Attribute( 'foo', true );
@@ -43,30 +41,4 @@ export default class Text {
 		 */
 		this.attrs = new AttributeList( attrs );
 	}
-
-	/**
-	 * Creates and returns a text node that represents whole text contained in this text object.
-	 *
-	 * @returns {TextNode}
-	 */
-	getTextNode( start, length ) {
-		start = start && start >= 0 ? start : 0;
-		length = length && length >= 0 ? length : this.text.length;
-
-		return new TextNode( this, start, length );
-	}
-
-	/**
-	 * Custom toJSON method to solve child-parent circular dependencies.
-	 *
-	 * @returns {Object} Clone of this object with the parent property replaced with its name.
-	 */
-	toJSON() {
-		const json = langUtils.clone( this );
-
-		// Due to circular references we need to remove parent reference.
-		json.parent = this.parent ? this.parent.name : null;
-
-		return json;
-	}
 }

+ 0 - 45
packages/ckeditor5-engine/tests/treemodel/text.js

@@ -8,7 +8,6 @@
 'use strict';
 
 import Text from '/ckeditor5/core/treemodel/text.js';
-import TextNode from '/ckeditor5/core/treemodel/textnode.js';
 import Attribute from '/ckeditor5/core/treemodel/attribute.js';
 import AttributeList from '/ckeditor5/core/treemodel/attributelist.js';
 
@@ -31,48 +30,4 @@ describe( 'Text', () => {
 			expect( empty2.text ).to.equal( '' );
 		} );
 	} );
-
-	describe( 'getTextNode', () => {
-		let attrs, text;
-
-		beforeEach( () => {
-			attrs = [ new Attribute( 'bold', true ) ];
-			text = new Text( 'bar', attrs );
-		} );
-
-		it( 'should return text node containing whole text object if no parameters are passed', () => {
-			let textNode = text.getTextNode();
-
-			expect( textNode ).to.be.instanceof( TextNode );
-			expect( textNode.text ).to.equal( 'bar' );
-			expect( textNode._start ).to.equal( 0 );
-			expect( textNode._textItem ).to.equal( text );
-		} );
-
-		it( 'should return text node containing characters from start index to the end of text object if one parameter is passed', () => {
-			let textNode = text.getTextNode( 1 );
-
-			expect( textNode ).to.be.instanceof( TextNode );
-			expect( textNode.text ).to.equal( 'ar' );
-			expect( textNode._start ).to.equal( 1 );
-			expect( textNode._textItem ).to.equal( text );
-		} );
-
-		it( 'should return text node containing given number of characters, starting from given index if two parameters are passed', () => {
-			let textNode = text.getTextNode( 1, 1 );
-
-			expect( textNode ).to.be.instanceof( TextNode );
-			expect( textNode.text ).to.equal( 'a' );
-			expect( textNode._start ).to.equal( 1 );
-			expect( textNode._textItem ).to.equal( text );
-		} );
-	} );
-
-	it( 'should create proper JSON string using toJSON method', () => {
-		let text = new Text( 'bar' );
-		let parsed = JSON.parse( JSON.stringify( text ) );
-
-		expect( parsed.text ).to.equal( 'bar' );
-		expect( parsed.parent ).to.equal( null );
-	} );
 } );