Kaynağa Gözat

Renamed `Selection#moveFocusTo` to `setFocus`.

Maciej Bukowski 8 yıl önce
ebeveyn
işleme
07db6b0092

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

@@ -258,8 +258,8 @@ export default class DocumentSelection {
 	 * @param {Number|'end'|'before'|'after'} [offset] Offset or one of the flags. Used only when
 	 * first parameter is a {@link module:engine/model/item~Item model item}.
 	 */
-	_moveFocusTo( itemOrPosition, offset ) {
-		this._selection.moveFocusTo( itemOrPosition, offset );
+	_setFocus( itemOrPosition, offset ) {
+		this._selection.setFocus( itemOrPosition, offset );
 	}
 
 	/**

+ 3 - 3
packages/ckeditor5-engine/src/model/selection.js

@@ -382,15 +382,15 @@ export default class Selection {
 	 * @param {Number|'end'|'before'|'after'} [offset=0] Offset or one of the flags. Used only when
 	 * first parameter is a {@link module:engine/model/item~Item model item}.
 	 */
-	moveFocusTo( itemOrPosition, offset ) {
+	setFocus( itemOrPosition, offset ) {
 		if ( this.anchor === null ) {
 			/**
 			 * Cannot set selection focus if there are no ranges in selection.
 			 *
-			 * @error model-selection-moveFocusTo-no-ranges
+			 * @error model-selection-setFocus-no-ranges
 			 */
 			throw new CKEditorError(
-				'model-selection-moveFocusTo-no-ranges: Cannot set selection focus if there are no ranges in selection.'
+				'model-selection-setFocus-no-ranges: Cannot set selection focus if there are no ranges in selection.'
 			);
 		}
 

+ 2 - 2
packages/ckeditor5-engine/src/model/utils/modifyselection.js

@@ -66,9 +66,9 @@ export default function modifySelection( model, selection, options = {} ) {
 
 		if ( position ) {
 			if ( selection instanceof DocumentSelection ) {
-				selection._moveFocusTo( position );
+				selection._setFocus( position );
 			} else {
-				selection.moveFocusTo( position );
+				selection.setFocus( position );
 			}
 
 			return;

+ 1 - 1
packages/ckeditor5-engine/src/model/writer.js

@@ -847,7 +847,7 @@ export default class Writer {
 	setSelectionFocus( itemOrPosition, offset ) {
 		this._assertWriterUsedCorrectly();
 
-		this.model.document.selection._moveFocusTo( itemOrPosition, offset );
+		this.model.document.selection._setFocus( itemOrPosition, offset );
 	}
 
 	/**

+ 1 - 1
packages/ckeditor5-engine/src/view/observer/mutationobserver.js

@@ -241,7 +241,7 @@ export default class MutationObserver extends Observer {
 			if ( viewSelectionAnchor && viewSelectionFocus ) {
 				viewSelection = new ViewSelection();
 				viewSelection.setTo( viewSelectionAnchor );
-				viewSelection.moveFocusTo( viewSelectionFocus );
+				viewSelection.setFocus( viewSelectionFocus );
 			}
 		}
 

+ 3 - 3
packages/ckeditor5-engine/src/view/selection.js

@@ -472,15 +472,15 @@ export default class Selection {
 	 * @param {Number|'end'|'before'|'after'} [offset=0] Offset or one of the flags. Used only when
 	 * first parameter is a {@link module:engine/view/item~Item view item}.
 	 */
-	moveFocusTo( itemOrPosition, offset ) {
+	setFocus( itemOrPosition, offset ) {
 		if ( this.anchor === null ) {
 			/**
 			 * Cannot set selection focus if there are no ranges in selection.
 			 *
-			 * @error view-selection-moveFocusTo-no-ranges
+			 * @error view-selection-setFocus-no-ranges
 			 */
 			throw new CKEditorError(
-				'view-selection-moveFocusTo-no-ranges: Cannot set selection focus if there are no ranges in selection.'
+				'view-selection-setFocus-no-ranges: Cannot set selection focus if there are no ranges in selection.'
 			);
 		}
 

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

@@ -229,12 +229,12 @@ describe( 'DocumentSelection', () => {
 		} );
 	} );
 
-	describe( 'moveFocusTo()', () => {
+	describe( 'setFocus()', () => {
 		it( 'modifies default range', () => {
 			const startPos = selection.getFirstPosition();
 			const endPos = Position.createAt( root, 'end' );
 
-			selection._moveFocusTo( endPos );
+			selection._setFocus( endPos );
 
 			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
@@ -248,7 +248,7 @@ describe( 'DocumentSelection', () => {
 
 			selection._setTo( new Range( startPos, endPos ) );
 
-			selection._moveFocusTo( newEndPos );
+			selection._setFocus( newEndPos );
 
 			expect( spy.calledOnce ).to.be.true;
 		} );

+ 14 - 14
packages/ckeditor5-engine/tests/model/selection.js

@@ -268,14 +268,14 @@ describe( 'Selection', () => {
 		} );
 	} );
 
-	describe( 'moveFocusTo()', () => {
+	describe( 'setFocus()', () => {
 		it( 'keeps all existing ranges and fires no change:range when no modifications needed', () => {
 			selection.setTo( [ range, liveRange ] );
 
 			const spy = sinon.spy();
 			selection.on( 'change:range', spy );
 
-			selection.moveFocusTo( selection.focus );
+			selection.setFocus( selection.focus );
 
 			expect( count( selection.getRanges() ) ).to.equal( 2 );
 			expect( spy.callCount ).to.equal( 0 );
@@ -287,7 +287,7 @@ describe( 'Selection', () => {
 			const spy = sinon.spy();
 			selection.on( 'change:range', spy );
 
-			selection.moveFocusTo( Position.createAt( root, 'end' ) );
+			selection.setFocus( Position.createAt( root, 'end' ) );
 
 			expect( spy.calledOnce ).to.be.true;
 		} );
@@ -296,8 +296,8 @@ describe( 'Selection', () => {
 			const endPos = Position.createAt( root, 'end' );
 
 			expect( () => {
-				selection.moveFocusTo( endPos );
-			} ).to.throw( CKEditorError, /model-selection-moveFocusTo-no-ranges/ );
+				selection.setFocus( endPos );
+			} ).to.throw( CKEditorError, /model-selection-setFocus-no-ranges/ );
 		} );
 
 		it( 'modifies existing collapsed selection', () => {
@@ -306,7 +306,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( startPos );
 
-			selection.moveFocusTo( endPos );
+			selection.setFocus( endPos );
 
 			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
@@ -318,7 +318,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( startPos );
 
-			selection.moveFocusTo( endPos );
+			selection.setFocus( endPos );
 
 			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
@@ -332,7 +332,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( new Range( startPos, endPos ) );
 
-			selection.moveFocusTo( newEndPos );
+			selection.setFocus( newEndPos );
 
 			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
@@ -345,7 +345,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( new Range( startPos, endPos ) );
 
-			selection.moveFocusTo( newEndPos );
+			selection.setFocus( newEndPos );
 
 			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
@@ -359,7 +359,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( new Range( startPos, endPos ), true );
 
-			selection.moveFocusTo( newEndPos );
+			selection.setFocus( newEndPos );
 
 			expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
@@ -373,7 +373,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( new Range( startPos, endPos ), true );
 
-			selection.moveFocusTo( newEndPos );
+			selection.setFocus( newEndPos );
 
 			expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
@@ -398,7 +398,7 @@ describe( 'Selection', () => {
 
 			selection.on( 'change:range', spy );
 
-			selection.moveFocusTo( newEndPos );
+			selection.setFocus( newEndPos );
 
 			const ranges = Array.from( selection.getRanges() );
 
@@ -419,7 +419,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( new Range( startPos, endPos ) );
 
-			selection.moveFocusTo( startPos );
+			selection.setFocus( startPos );
 
 			expect( selection.focus.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.isCollapsed ).to.be.true;
@@ -433,7 +433,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( new Range( startPos, endPos ) );
 
-			selection.moveFocusTo( root, 'end' );
+			selection.setFocus( root, 'end' );
 
 			expect( spy.calledOnce ).to.be.true;
 			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );

+ 1 - 1
packages/ckeditor5-engine/tests/view/observer/selectionobserver.js

@@ -320,7 +320,7 @@ describe( 'SelectionObserver', () => {
 			const viewFocus = viewDocument.domConverter.domPositionToView( sel.focusNode, sel.focusOffset );
 
 			viewSel.setTo( viewAnchor );
-			viewSel.moveFocusTo( viewFocus );
+			viewSel.setFocus( viewFocus );
 
 			viewDocument.render();
 		} );

+ 13 - 13
packages/ckeditor5-engine/tests/view/selection.js

@@ -105,10 +105,10 @@ describe( 'Selection', () => {
 		} );
 	} );
 
-	describe( 'moveFocusTo', () => {
+	describe( 'setFocus', () => {
 		it( 'keeps all existing ranges when no modifications needed', () => {
 			selection.setTo( range1 );
-			selection.moveFocusTo( selection.focus );
+			selection.setFocus( selection.focus );
 
 			expect( count( selection.getRanges() ) ).to.equal( 1 );
 		} );
@@ -117,8 +117,8 @@ describe( 'Selection', () => {
 			const endPos = Position.createAt( el, 'end' );
 
 			expect( () => {
-				selection.moveFocusTo( endPos );
-			} ).to.throw( CKEditorError, /view-selection-moveFocusTo-no-ranges/ );
+				selection.setFocus( endPos );
+			} ).to.throw( CKEditorError, /view-selection-setFocus-no-ranges/ );
 		} );
 
 		it( 'modifies existing collapsed selection', () => {
@@ -127,7 +127,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( startPos );
 
-			selection.moveFocusTo( endPos );
+			selection.setFocus( endPos );
 
 			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
@@ -139,7 +139,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( startPos );
 
-			selection.moveFocusTo( endPos );
+			selection.setFocus( endPos );
 
 			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
@@ -153,7 +153,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( new Range( startPos, endPos ) );
 
-			selection.moveFocusTo( newEndPos );
+			selection.setFocus( newEndPos );
 
 			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
@@ -166,7 +166,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( new Range( startPos, endPos ) );
 
-			selection.moveFocusTo( newEndPos );
+			selection.setFocus( newEndPos );
 
 			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
@@ -180,7 +180,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( new Range( startPos, endPos ), true );
 
-			selection.moveFocusTo( newEndPos );
+			selection.setFocus( newEndPos );
 
 			expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
@@ -194,7 +194,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( new Range( startPos, endPos ), true );
 
-			selection.moveFocusTo( newEndPos );
+			selection.setFocus( newEndPos );
 
 			expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
 			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
@@ -215,7 +215,7 @@ describe( 'Selection', () => {
 				new Range( startPos2, endPos2 )
 			] );
 
-			selection.moveFocusTo( newEndPos );
+			selection.setFocus( newEndPos );
 
 			const ranges = Array.from( selection.getRanges() );
 
@@ -234,7 +234,7 @@ describe( 'Selection', () => {
 
 			selection.setTo( new Range( startPos, endPos ) );
 
-			selection.moveFocusTo( startPos );
+			selection.setFocus( startPos );
 
 			expect( selection.focus.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.isCollapsed ).to.be.true;
@@ -248,7 +248,7 @@ describe( 'Selection', () => {
 			const spy = sinon.stub( Position, 'createAt' ).returns( newEndPos );
 
 			selection.setTo( new Range( startPos, endPos ) );
-			selection.moveFocusTo( el, 'end' );
+			selection.setFocus( el, 'end' );
 
 			expect( spy.calledOnce ).to.be.true;
 			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );