Browse Source

Changed: rename model.DocumentSelection to model.LiveSelection.

Szymon Cofalik 9 years ago
parent
commit
a296b700f2

+ 4 - 4
packages/ckeditor5-engine/src/model/document.js

@@ -12,7 +12,7 @@ import transformations from './delta/basic-transformations.js'; // jshint ignore
 import RootElement from './rootelement.js';
 import Batch from './batch.js';
 import History from './history.js';
-import DocumentSelection from './documentselection.js';
+import LiveSelection from './liveselection.js';
 import EmitterMixin from '../../utils/emittermixin.js';
 import CKEditorError from '../../utils/ckeditorerror.js';
 import mix from '../../utils/mix.js';
@@ -55,9 +55,9 @@ export default class Document {
 		 * Selection done on this document.
 		 *
 		 * @readonly
-		 * @member {engine.model.DocumentSelection} engine.model.Document#selection
+		 * @member {engine.model.LiveSelection} engine.model.Document#selection
 		 */
-		this.selection = new DocumentSelection( this );
+		this.selection = new LiveSelection( this );
 
 		/**
 		 * Schema for this document.
@@ -287,7 +287,7 @@ export default class Document {
 		const json = clone( this );
 
 		// Due to circular references we need to remove parent reference.
-		json.selection = '[engine.model.DocumentSelection]';
+		json.selection = '[engine.model.LiveSelection]';
 
 		return json;
 	}

+ 19 - 19
packages/ckeditor5-engine/src/model/documentselection.js

@@ -16,19 +16,19 @@ import Selection from './selection.js';
 const storePrefix = 'selection:';
 
 /**
- * Represents a main {@link engine.model.Selection selection} of a {@link engine.model.Document}. This is the selection
- * that user interacts with. `DocumentSelection` instance is created by {@link engine.model.Document}. You should not
- * create an instance of `DocumentSelection`.
+ * `LiveSelection` is a special type of {@link engine.model.Selection selection} that listens to changes on a
+ * {@link engine.model.Document document} and has it ranges updated accordingly. Internal implementation of this
+ * mechanism bases on {@link engine.model.LiveRange live ranges}.
  *
- * Differences between {@link engine.model.Selection} and `DocumentSelection` are three:
- * * there is always a range in `DocumentSelection`, even if no ranges were added - in this case, there is a
+ * Differences between {@link engine.model.Selection} and `LiveSelection` are three:
+ * * there is always a range in `LiveSelection`, even if no ranges were added - in this case, there is a
  * "default range" in selection which is a collapsed range set at the beginning of the {@link engine.model.Document document},
  * * ranges added to this selection updates automatically when the document changes,
- * * document selection may have attributes.
+ * * live selection may have attributes.
  *
  * @memberOf engine.model
  */
-export default class DocumentSelection extends Selection {
+export default class LiveSelection extends Selection {
 	/**
 	 * Creates an empty document selection for given {@link engine.model.Document}.
 	 *
@@ -49,7 +49,7 @@ export default class DocumentSelection extends Selection {
 		 * List of attributes set on current selection.
 		 *
 		 * @protected
-		 * @member {Map} engine.model.DocumentSelection#_attrs
+		 * @member {Map} engine.model.LiveSelection#_attrs
 		 */
 		this._attrs = new Map();
 	}
@@ -129,7 +129,7 @@ export default class DocumentSelection extends Selection {
 
 	/**
 	 * Creates an instance of {@link engine.model.Selection} that has same ranges and direction as this selection. Since
-	 * this will be instance of `Selection` instead of `DocumentSelection`, it will not be automatically updated or rendered,
+	 * this will be instance of `Selection` instead of `LiveSelection`, it will not be automatically updated or rendered,
 	 * so it can be used in algorithms using and modifying selection.
 	 *
 	 * @returns {engine.model.Selection} Selection instance which ranges and direction is equal to this selection.
@@ -144,7 +144,7 @@ export default class DocumentSelection extends Selection {
 	/**
 	 * Removes all attributes from the selection.
 	 *
-	 * @fires engine.model.DocumentSelection#change:attribute
+	 * @fires engine.model.LiveSelection#change:attribute
 	 */
 	clearAttributes() {
 		this._attrs.clear();
@@ -185,7 +185,7 @@ export default class DocumentSelection extends Selection {
 	/**
 	 * Removes an attribute with given key from the selection.
 	 *
-	 * @fires engine.model.DocumentSelection#change:attribute
+	 * @fires engine.model.LiveSelection#change:attribute
 	 * @param {String} key Key of attribute to remove.
 	 */
 	removeAttribute( key ) {
@@ -198,7 +198,7 @@ export default class DocumentSelection extends Selection {
 	/**
 	 * Sets attribute on the selection. If attribute with the same key already is set, it overwrites its values.
 	 *
-	 * @fires engine.model.DocumentSelection#change:attribute
+	 * @fires engine.model.LiveSelection#change:attribute
 	 * @param {String} key Key of attribute to set.
 	 * @param {*} value Attribute value.
 	 */
@@ -212,7 +212,7 @@ export default class DocumentSelection extends Selection {
 	/**
 	 * Removes all attributes from the selection and sets given attributes.
 	 *
-	 * @fires engine.model.DocumentSelection#change:attribute
+	 * @fires engine.model.LiveSelection#change:attribute
 	 * @param {Iterable|Object} attrs Iterable object containing attributes to be set.
 	 */
 	setAttributesTo( attrs ) {
@@ -290,7 +290,7 @@ export default class DocumentSelection extends Selection {
 		const selectionParent = this.getFirstPosition().parent;
 
 		if ( this.isCollapsed && selectionParent.getChildCount() === 0 ) {
-			const storeKey = DocumentSelection._getStoreAttributeKey( key );
+			const storeKey = LiveSelection._getStoreAttributeKey( key );
 
 			this._document.enqueueChanges( () => {
 				this._document.batch().removeAttr( storeKey, selectionParent );
@@ -310,7 +310,7 @@ export default class DocumentSelection extends Selection {
 		const selectionParent = this.getFirstPosition().parent;
 
 		if ( this.isCollapsed && selectionParent.getChildCount() === 0 ) {
-			const storeKey = DocumentSelection._getStoreAttributeKey( key );
+			const storeKey = LiveSelection._getStoreAttributeKey( key );
 
 			this._document.enqueueChanges( () => {
 				this._document.batch().setAttr( storeKey, value, selectionParent );
@@ -332,13 +332,13 @@ export default class DocumentSelection extends Selection {
 				const batch = this._document.batch();
 
 				for ( let attr of this._getStoredAttributes() ) {
-					const storeKey = DocumentSelection._getStoreAttributeKey( attr[ 0 ] );
+					const storeKey = LiveSelection._getStoreAttributeKey( attr[ 0 ] );
 
 					batch.removeAttr( storeKey, selectionParent );
 				}
 
 				for ( let attr of attrs ) {
-					const storeKey = DocumentSelection._getStoreAttributeKey( attr[ 0 ] );
+					const storeKey = LiveSelection._getStoreAttributeKey( attr[ 0 ] );
 
 					batch.setAttr( storeKey, attr[ 1 ], selectionParent );
 				}
@@ -349,7 +349,7 @@ export default class DocumentSelection extends Selection {
 	/**
 	 * Updates this selection attributes according to it's ranges and the document.
 	 *
-	 * @fires engine.model.DocumentSelection#change:attribute
+	 * @fires engine.model.LiveSelection#change:attribute
 	 * @protected
 	 */
 	_updateAttributes() {
@@ -441,5 +441,5 @@ export default class DocumentSelection extends Selection {
 /**
  * Fired whenever selection attributes are changed.
  *
- * @event engine.model.DocumentSelection#change:attribute
+ * @event engine.model.LiveSelection#change:attribute
  */

+ 1 - 1
packages/ckeditor5-engine/tests/model/document/document.js

@@ -256,6 +256,6 @@ describe( 'Document', () => {
 	} );
 
 	it( 'should be correctly converted to json', () => {
-		expect( jsonParseStringify( doc ).selection ).to.equal( '[engine.model.DocumentSelection]' );
+		expect( jsonParseStringify( doc ).selection ).to.equal( '[engine.model.LiveSelection]' );
 	} );
 } );

+ 15 - 15
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -13,14 +13,14 @@ import Text from '/ckeditor5/engine/model/text.js';
 import Range from '/ckeditor5/engine/model/range.js';
 import Position from '/ckeditor5/engine/model/position.js';
 import LiveRange from '/ckeditor5/engine/model/liverange.js';
-import DocumentSelection from '/ckeditor5/engine/model/documentselection.js';
+import LiveSelection from '/ckeditor5/engine/model/liveselection.js';
 import InsertOperation from '/ckeditor5/engine/model/operation/insertoperation.js';
 import MoveOperation from '/ckeditor5/engine/model/operation/moveoperation.js';
 import testUtils from '/tests/ckeditor5/_utils/utils.js';
 
 testUtils.createSinonSandbox();
 
-describe( 'DocumentSelection', () => {
+describe( 'LiveSelection', () => {
 	let attrFooBar;
 
 	before( () => {
@@ -307,7 +307,7 @@ describe( 'DocumentSelection', () => {
 		} );
 	} );
 
-	// DocumentSelection uses LiveRanges so here are only simple test to see if integration is
+	// LiveSelection uses LiveRanges so here are only simple test to see if integration is
 	// working well, without getting into complicated corner cases.
 	describe( 'after applying an operation should get updated and not fire update event', () => {
 		let spy;
@@ -473,7 +473,7 @@ describe( 'DocumentSelection', () => {
 				selection.setAttribute( 'foo', 'bar' );
 
 				expect( selection.getAttribute( 'foo' ) ).to.equal( 'bar' );
-				expect( fullP.hasAttribute( DocumentSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
+				expect( fullP.hasAttribute( LiveSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
 			} );
 
 			it( 'should store attribute if the selection is in empty node', () => {
@@ -482,7 +482,7 @@ describe( 'DocumentSelection', () => {
 
 				expect( selection.getAttribute( 'foo' ) ).to.equal( 'bar' );
 
-				expect( emptyP.getAttribute( DocumentSelection._getStoreAttributeKey( 'foo' ) ) ).to.equal( 'bar' );
+				expect( emptyP.getAttribute( LiveSelection._getStoreAttributeKey( 'foo' ) ) ).to.equal( 'bar' );
 			} );
 
 			it( 'should fire change:attribute event', () => {
@@ -535,8 +535,8 @@ describe( 'DocumentSelection', () => {
 				expect( selection.getAttribute( 'foo' ) ).to.equal( 'bar' );
 				expect( selection.getAttribute( 'abc' ) ).to.be.undefined;
 
-				expect( fullP.hasAttribute( DocumentSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
-				expect( fullP.hasAttribute( DocumentSelection._getStoreAttributeKey( 'abc' ) ) ).to.be.false;
+				expect( fullP.hasAttribute( LiveSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
+				expect( fullP.hasAttribute( LiveSelection._getStoreAttributeKey( 'abc' ) ) ).to.be.false;
 			} );
 
 			it( 'should remove all stored attributes and store the given ones if the selection is in empty node', () => {
@@ -547,8 +547,8 @@ describe( 'DocumentSelection', () => {
 				expect( selection.getAttribute( 'foo' ) ).to.equal( 'bar' );
 				expect( selection.getAttribute( 'abc' ) ).to.be.undefined;
 
-				expect( emptyP.getAttribute( DocumentSelection._getStoreAttributeKey( 'foo' ) ) ).to.equal( 'bar' );
-				expect( emptyP.hasAttribute( DocumentSelection._getStoreAttributeKey( 'abc' ) ) ).to.be.false;
+				expect( emptyP.getAttribute( LiveSelection._getStoreAttributeKey( 'foo' ) ) ).to.equal( 'bar' );
+				expect( emptyP.hasAttribute( LiveSelection._getStoreAttributeKey( 'abc' ) ) ).to.be.false;
 			} );
 
 			it( 'should fire change:attribute event', () => {
@@ -569,7 +569,7 @@ describe( 'DocumentSelection', () => {
 
 				expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
 
-				expect( fullP.hasAttribute( DocumentSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
+				expect( fullP.hasAttribute( LiveSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
 			} );
 
 			it( 'should remove stored attribute if the selection is in empty node', () => {
@@ -579,7 +579,7 @@ describe( 'DocumentSelection', () => {
 
 				expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
 
-				expect( emptyP.hasAttribute( DocumentSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
+				expect( emptyP.hasAttribute( LiveSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
 			} );
 
 			it( 'should fire change:attribute event', () => {
@@ -603,8 +603,8 @@ describe( 'DocumentSelection', () => {
 				expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
 				expect( selection.getAttribute( 'abc' ) ).to.be.undefined;
 
-				expect( fullP.hasAttribute( DocumentSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
-				expect( fullP.hasAttribute( DocumentSelection._getStoreAttributeKey( 'abc' ) ) ).to.be.false;
+				expect( fullP.hasAttribute( LiveSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
+				expect( fullP.hasAttribute( LiveSelection._getStoreAttributeKey( 'abc' ) ) ).to.be.false;
 			} );
 
 			it( 'should remove all stored attributes if the selection is in empty node', () => {
@@ -617,8 +617,8 @@ describe( 'DocumentSelection', () => {
 				expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
 				expect( selection.getAttribute( 'abc' ) ).to.be.undefined;
 
-				expect( emptyP.hasAttribute( DocumentSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
-				expect( emptyP.hasAttribute( DocumentSelection._getStoreAttributeKey( 'abc' ) ) ).to.be.false;
+				expect( emptyP.hasAttribute( LiveSelection._getStoreAttributeKey( 'foo' ) ) ).to.be.false;
+				expect( emptyP.hasAttribute( LiveSelection._getStoreAttributeKey( 'abc' ) ) ).to.be.false;
 			} );
 
 			it( 'should fire change:attribute event', () => {