Bladeren bron

Added Document.selection.

Szymon Cofalik 10 jaren geleden
bovenliggende
commit
757d21e583

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

@@ -9,10 +9,11 @@ CKEDITOR.define( [
 	'treemodel/element',
 	'treemodel/rootelement',
 	'treemodel/batch',
+	'treemodel/selection',
 	'emittermixin',
 	'utils',
 	'ckeditorerror'
-], ( Element, RootElement, Batch, EmitterMixin, utils, CKEditorError ) => {
+], ( Element, RootElement, Batch, Selection, EmitterMixin, utils, CKEditorError ) => {
 	const graveyardSymbol = Symbol( 'graveyard' );
 
 	/**
@@ -63,6 +64,14 @@ CKEDITOR.define( [
 			 * @property {Array.<Function>}
 			 */
 			this._pendingChanges = [];
+
+			/**
+			 * Selection done on this document.
+			 *
+			 * @readonly
+			 * @property {treeModel.Selection}
+			 */
+			this._selection = new Selection();
 		}
 
 		/**
@@ -75,6 +84,16 @@ CKEDITOR.define( [
 			return this.getRoot( graveyardSymbol );
 		}
 
+		/**
+		 * Returns current selection done on this document.
+		 *
+		 * @readonly
+		 * @property {treeModel.Selection}
+		 */
+		get selection() {
+			return this._selection;
+		}
+
 		/**
 		 * This is the entry point for all document changes. All changes on the document are done using
 		 * {@link treeModel.operation.Operation operations}. To create operations in the simple way use the

+ 2 - 1
packages/ckeditor5-engine/tests/treemodel/document/document.js

@@ -31,11 +31,12 @@ describe( 'Document', () => {
 	} );
 
 	describe( 'constructor', () => {
-		it( 'should create Document with no data and empty graveyard', () => {
+		it( 'should create Document with no data, empty graveyard and empty selection', () => {
 			expect( doc ).to.have.property( 'roots' ).that.is.instanceof( Map );
 			expect( doc.roots.size ).to.equal( 1 );
 			expect( doc.graveyard ).to.be.instanceof( RootElement );
 			expect( doc.graveyard.getChildCount() ).to.equal( 0 );
+			expect( doc.selection.getRanges().length ).to.equal( 0 );
 		} );
 	} );