8
0
Piotrek Koszuliński 9 лет назад
Родитель
Сommit
16810673ae

+ 9 - 0
packages/ckeditor5-engine/src/treemodel/selection.js

@@ -106,6 +106,15 @@ export default class Selection {
 		return true;
 		return true;
 	}
 	}
 
 
+	/**
+	 * Specifies whether the last added range was added as a backward or forward range.
+	 *
+	 * @type {Boolean}
+	 */
+	get isBackward() {
+		return this._lastRangeBackward;
+	}
+
 	/**
 	/**
 	 * Adds a range to the selection. Added range is copied and converted to {@link engine.treeModel.LiveRange}. This means
 	 * Adds a range to the selection. Added range is copied and converted to {@link engine.treeModel.LiveRange}. This means
 	 * that passed range is not saved in the Selection instance and you can safely operate on it.
 	 * that passed range is not saved in the Selection instance and you can safely operate on it.

+ 9 - 0
packages/ckeditor5-engine/tests/treemodel/selection.js

@@ -59,6 +59,7 @@ describe( 'Selection', () => {
 		expect( ranges.length ).to.equal( 1 );
 		expect( ranges.length ).to.equal( 1 );
 		expect( selection.anchor.isEqual( new Position( root, [ 0 ] ) ) ).to.be.true;
 		expect( selection.anchor.isEqual( new Position( root, [ 0 ] ) ) ).to.be.true;
 		expect( selection.focus.isEqual( new Position( root, [ 0 ] ) ) ).to.be.true;
 		expect( selection.focus.isEqual( new Position( root, [ 0 ] ) ) ).to.be.true;
+		expect( selection ).to.have.property( 'isBackward', false );
 		expect( selection._attrs ).to.be.instanceof( Map );
 		expect( selection._attrs ).to.be.instanceof( Map );
 		expect( selection._attrs.size ).to.equal( 0 );
 		expect( selection._attrs.size ).to.equal( 0 );
 	} );
 	} );
@@ -119,6 +120,14 @@ describe( 'Selection', () => {
 			expect( selection.focus.path ).to.deep.equal( [ 2 ] );
 			expect( selection.focus.path ).to.deep.equal( [ 2 ] );
 		} );
 		} );
 
 
+		it( 'should set isBackward', () => {
+			selection.addRange( range, true );
+			expect( selection ).to.have.property( 'isBackward', true );
+
+			selection.addRange( liveRange );
+			expect( selection ).to.have.property( 'isBackward', false );
+		} );
+
 		it( 'should return a copy of (not a reference to) array of stored ranges', () => {
 		it( 'should return a copy of (not a reference to) array of stored ranges', () => {
 			selection.addRange( liveRange );
 			selection.addRange( liveRange );