浏览代码

Rename engine.treeModel.TextFragment to engine.treeModel.TextProxy.

Szymon Cofalik 9 年之前
父节点
当前提交
45f6ff43c1

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/item.jsdoc

@@ -4,7 +4,7 @@
  */
 
 /**
- * Item is a {@link engine.treeModel.Node Node} or {engine.treeModel.TextFragment TextFragment}.
+ * Item is a {@link engine.treeModel.Node Node} or {engine.treeModel.TextProxy TextProxy}.
  *
- * @typedef {engine.treeModel.Node|engine.treeModel.TextFragment} engine.treeModel.Item
+ * @typedef {engine.treeModel.Node|engine.treeModel.TextProxy} engine.treeModel.Item
  */

+ 0 - 1
packages/ckeditor5-engine/src/treemodel/operation/attributeoperation.js

@@ -8,7 +8,6 @@
 import Operation from './operation.js';
 import Range from '../range.js';
 import CKEditorError from '../../../utils/ckeditorerror.js';
-import TextFragment from '../textfragment.js';
 
 /**
  * Operation to change nodes' attribute. Using this class you can add, remove or change value of the attribute.

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/range.js

@@ -256,7 +256,7 @@ export default class Range {
 	/**
 	 * Returns an iterator that iterates over all {@link engine.treeModel.Item items} that are in this range and returns
 	 * them together with additional information like length or {@link engine.treeModel.Position positions},
-	 * grouped as {@link engine.treeModel.TreeWalkerValue}. It iterates over all {@link engine.treeModel.TextFragment texts}
+	 * grouped as {@link engine.treeModel.TreeWalkerValue}. It iterates over all {@link engine.treeModel.TextProxy texts}
 	 * that are inside the range and all the {@link engine.treeModel.Element}s we enter into when iterating over this
 	 * range.
 	 *
@@ -294,7 +294,7 @@ export default class Range {
 	/**
 	 * Returns an iterator that iterates over all {@link engine.treeModel.Item items} that are in this range and returns
 	 * them. It iterates over all {@link engine.treeModel.CharacterProxy characters} or
-	 * {@link engine.treeModel.TextFragment texts} that are inside the range and all the {@link engine.treeModel.Element}s
+	 * {@link engine.treeModel.TextProxy texts} that are inside the range and all the {@link engine.treeModel.Element}s
 	 * we enter into when iterating over this range. Note that it use {@link engine.treeModel.TreeWalker} with the
 	 * {@link engine.treeModel.TreeWalker#ignoreElementEnd ignoreElementEnd} option set to true.
 	 *

+ 24 - 24
packages/ckeditor5-engine/src/treemodel/textfragment.js → packages/ckeditor5-engine/src/treemodel/textproxy.js

@@ -9,59 +9,59 @@ import CharacterProxy from './characterproxy.js';
 import utils from '../../utils/utils.js';
 
 /**
- * TextFragment is an aggregator for multiple CharacterProxy instances that are placed next to each other in
+ * TextProxy is an aggregator for multiple CharacterProxy instances that are placed next to each other in
  * tree model, in the same parent, and all have same attributes set. Instances of this class are created and returned
  * in various algorithms that "merge characters" (see {@link engine.treeModel.TreeWalker}, {@link engine.treeModel.Range}).
  *
- * **Note:** TextFragment instances are created on the fly basing on the current state of tree model and attributes
- * set on characters. Because of this it is highly unrecommended to store references to TextFragment instances
+ * **Note:** TextProxy instances are created on the fly basing on the current state of tree model and attributes
+ * set on characters. Because of this it is highly unrecommended to store references to TextProxy instances
  * because they might get invalidated due to operations on Document. This is especially true when you change
- * attributes of TextFragment.
+ * attributes of TextProxy.
  *
- * Difference between {@link engine.treeModel.TextFragment} and {@link engine.treeModel.Text} is that the former is a set of
+ * Difference between {@link engine.treeModel.TextProxy} and {@link engine.treeModel.Text} is that the former is a set of
  * nodes taken from tree model, while {@link engine.treeModel.Text} is simply a string with attributes set.
  *
  * You should never create an instance of this class by your own. Instead, use string literals or {@link engine.treeModel.Text}.
  *
  * @memberOf engine.treeModel
  */
-export default class TextFragment {
+export default class TextProxy {
 	/**
 	 * Creates a text fragment.
 	 *
 	 * @protected
-	 * @param {engine.treeModel.CharacterProxy} firstCharacter First character node contained in {@link engine.treeModel.TextFragment}.
-	 * @param {Number} length Whole text contained in {@link engine.treeModel.TextFragment}.
+	 * @param {engine.treeModel.CharacterProxy} firstCharacter First character node contained in {@link engine.treeModel.TextProxy}.
+	 * @param {Number} length Whole text contained in {@link engine.treeModel.TextProxy}.
 	 * @constructor
 	 */
 	constructor( firstCharacter, length ) {
 		/**
-		 * First character node contained in {@link engine.treeModel.TextFragment}.
+		 * First character node contained in {@link engine.treeModel.TextProxy}.
 		 *
 		 * @readonly
-		 * @member {engine.treeModel.CharacterProxy} engine.treeModel.TextFragment#first
+		 * @member {engine.treeModel.CharacterProxy} engine.treeModel.TextProxy#first
 		 */
 		this.first = firstCharacter;
 
 		/**
-		 * Characters contained in {@link engine.treeModel.TextFragment}.
+		 * Characters contained in {@link engine.treeModel.TextProxy}.
 		 *
 		 * @readonly
-		 * @member {String} engine.treeModel.TextFragment#text
+		 * @member {String} engine.treeModel.TextProxy#text
 		 */
 		this.text = firstCharacter._nodeListText.text.substr( this.first._index, length );
 
 		/**
-		 * Last {@link engine.treeModel.CharacterProxy character node} contained in {@link engine.treeModel.TextFragment}.
+		 * Last {@link engine.treeModel.CharacterProxy character node} contained in {@link engine.treeModel.TextProxy}.
 		 *
 		 * @readonly
-		 * @member {engine.treeModel.CharacterProxy} engine.treeModel.TextFragment#last
+		 * @member {engine.treeModel.CharacterProxy} engine.treeModel.TextProxy#last
 		 */
 		this.last = this.getCharAt( this.text.length - 1 );
 	}
 
 	/**
-	 * A common parent of all character nodes contained in {@link engine.treeModel.TextFragment}.
+	 * A common parent of all character nodes contained in {@link engine.treeModel.TextProxy}.
 	 *
 	 * @type {engine.treeModel.Element}
 	 */
@@ -115,8 +115,8 @@ export default class TextFragment {
 	/**
 	 * Sets attribute on the text fragment. If attribute with the same key already is set, it overwrites its values.
 	 *
-	 * **Note:** Changing attributes of text fragment affects document state. This TextFragment instance properties
-	 * will be refreshed, but other may get invalidated. It is highly unrecommended to store references to TextFragment instances.
+	 * **Note:** Changing attributes of text fragment affects document state. This TextProxy instance properties
+	 * will be refreshed, but other may get invalidated. It is highly unrecommended to store references to TextProxy instances.
 	 *
 	 * @param {String} key Key of attribute to set.
 	 * @param {*} value Attribute value.
@@ -133,11 +133,11 @@ export default class TextFragment {
 	/**
 	 * Removes all attributes from the text fragment and sets given attributes.
 	 *
-	 * **Note:** Changing attributes of text fragment affects document state. This TextFragment instance properties
-	 * will be refreshed, but other may get invalidated. It is highly unrecommended to store references to TextFragment instances.
+	 * **Note:** Changing attributes of text fragment affects document state. This TextProxy instance properties
+	 * will be refreshed, but other may get invalidated. It is highly unrecommended to store references to TextProxy instances.
 	 *
 	 * @param {Iterable|Object} attrs Iterable object containing attributes to be set.
-	 * See {@link engine.treeModel.TextFragment#getAttributes}.
+	 * See {@link engine.treeModel.TextProxy#getAttributes}.
 	 */
 	setAttributesTo( attrs ) {
 		let attrsMap = utils.toMap( attrs );
@@ -152,8 +152,8 @@ export default class TextFragment {
 	/**
 	 * Removes an attribute with given key from the text fragment.
 	 *
-	 * **Note:** Changing attributes of text fragment affects document state. This TextFragment instance properties
-	 * will be refreshed, but other may get invalidated. It is highly unrecommended to store references to TextFragment instances.
+	 * **Note:** Changing attributes of text fragment affects document state. This TextProxy instance properties
+	 * will be refreshed, but other may get invalidated. It is highly unrecommended to store references to TextProxy instances.
 	 *
 	 * @param {String} key Key of attribute to remove.
 	 */
@@ -164,8 +164,8 @@ export default class TextFragment {
 	/**
 	 * Removes all attributes from the text fragment.
 	 *
-	 * **Note:** Changing attributes of text fragment affects document state. This TextFragment instance properties
-	 * will be refreshed, but other may get invalidated. It is highly unrecommended to store references to TextFragment instances.
+	 * **Note:** Changing attributes of text fragment affects document state. This TextProxy instance properties
+	 * will be refreshed, but other may get invalidated. It is highly unrecommended to store references to TextProxy instances.
 	 */
 	clearAttributes() {
 		for ( let attr of this.getAttributes() ) {

+ 4 - 4
packages/ckeditor5-engine/src/treemodel/treewalker.js

@@ -6,7 +6,7 @@
 'use strict';
 
 import CharacterProxy from './characterproxy.js';
-import TextFragment from './textfragment.js';
+import TextProxy from './textproxy.js';
 import Element from './element.js';
 import Position from './position.js';
 import CKEditorError from '../../utils/ckeditorerror.js';
@@ -25,7 +25,7 @@ export default class TreeWalker {
 	 * @param {engine.treeModel.Position} [options.startPosition] Starting position.
 	 * @param {Boolean} [options.singleCharacters=false] Flag indicating whether all consecutive characters with the same attributes
 	 * should be returned one by one as multiple {@link engine.treeModel.CharacterProxy} (`true`) objects or as one
-	 * {@link engine.treeModel.TextFragment} (`false`).
+	 * {@link engine.treeModel.TextProxy} (`false`).
 	 * @param {Boolean} [options.shallow=false] Flag indicating whether iterator should enter elements or not. If the
 	 * iterator is shallow child nodes of any iterated node will not be returned along with `ELEMENT_END` tag.
 	 * @param {Boolean} [options.ignoreElementEnd=false] Flag indicating whether iterator should ignore `ELEMENT_END`
@@ -167,12 +167,12 @@ export default class TreeWalker {
 					charactersCount = offset - position.offset;
 				}
 
-				let textFragment = new TextFragment( node, charactersCount );
+				let textProxy = new TextProxy( node, charactersCount );
 
 				position.offset = offset;
 				this.position = position;
 
-				return formatReturnValue( 'TEXT', textFragment, previousPosition, position, charactersCount );
+				return formatReturnValue( 'TEXT', textProxy, previousPosition, position, charactersCount );
 			}
 		} else {
 			// `node` is not set, we reached the end of current `parent`.

+ 7 - 7
packages/ckeditor5-engine/tests/treemodel/textfragment.js → packages/ckeditor5-engine/tests/treemodel/textproxy.js

@@ -9,11 +9,11 @@
 
 import Element from '/ckeditor5/engine/treemodel/element.js';
 import Text from '/ckeditor5/engine/treemodel/text.js';
-import TextFragment from '/ckeditor5/engine/treemodel/textfragment.js';
+import TextProxy from '/ckeditor5/engine/treemodel/textproxy.js';
 import Document from '/ckeditor5/engine/treemodel/document.js';
 import CharacterProxy from '/ckeditor5/engine/treemodel/characterproxy.js';
 
-describe( 'TextFragment', () => {
+describe( 'TextProxy', () => {
 	let doc, text, element, textFragment, root;
 
 	beforeEach( () => {
@@ -24,21 +24,21 @@ describe( 'TextFragment', () => {
 
 		text = new Text( 'foobar', { foo: 'bar' } );
 		element.insertChildren( 0, text );
-		textFragment = new TextFragment( element.getChild( 2 ), 3 );
+		textFragment = new TextProxy( element.getChild( 2 ), 3 );
 	} );
 
 	afterEach( () => {
 		element.removeChildren( 0, 1 );
 	} );
 
-	it( 'should have first property pointing to the first character node contained in TextFragment', () => {
+	it( 'should have first property pointing to the first character node contained in TextProxy', () => {
 		let char = textFragment.first;
 
 		expect( char.getPath() ).to.deep.equal( [ 0, 2 ] );
 		expect( char.character ).to.equal( 'o' );
 	} );
 
-	it( 'should have last property pointing to the last character node contained in TextFragment', () => {
+	it( 'should have last property pointing to the last character node contained in TextProxy', () => {
 		let char = textFragment.last;
 
 		expect( char.getPath() ).to.deep.equal( [ 0, 4 ] );
@@ -118,8 +118,8 @@ describe( 'TextFragment', () => {
 			} );
 
 			it( 'should correctly split and merge text fragments and refresh this text fragment properties', () => {
-				let otherTextFragment = new TextFragment( element.getChild( 5 ), 1 );
-				otherTextFragment.setAttribute( 'foo', null );
+				let otherTextProxy = new TextProxy( element.getChild( 5 ), 1 );
+				otherTextProxy.setAttribute( 'foo', null );
 				textFragment.setAttribute( 'foo', null );
 
 				expect( element._children._nodes.length ).to.equal( 2 );