Browse Source

Fix: Don't try to scroll to the selection which has no ranges.

Aleksander Nowodzinski 8 years ago
parent
commit
f4c21e6b25

+ 6 - 4
packages/ckeditor5-engine/src/view/document.js

@@ -307,10 +307,12 @@ export default class Document {
 	scrollToTheSelection() {
 		const range = this.selection.getFirstRange();
 
-		scrollUtils.scrollViewportToShowTarget( {
-			target: this.domConverter.viewRangeToDom( range ),
-			viewportOffset: 20
-		} );
+		if ( range ) {
+			scrollUtils.scrollViewportToShowTarget( {
+				target: this.domConverter.viewRangeToDom( range ),
+				viewportOffset: 20
+			} );
+		}
 	}
 
 	/**

+ 7 - 0
packages/ckeditor5-engine/tests/view/document/document.js

@@ -325,6 +325,13 @@ describe( 'Document', () => {
 	} );
 
 	describe( 'scrollToTheSelection()', () => {
+		it( 'does nothing when there are no ranges in the selection', () => {
+			const stub = testUtils.sinon.stub( scrollUtils, 'scrollViewportToShowTarget', () => {} );
+
+			viewDocument.scrollToTheSelection();
+			sinon.assert.notCalled( stub );
+		} );
+
 		it( 'scrolls to the first range in selection with an offset', () => {
 			const stub = testUtils.sinon.stub( scrollUtils, 'scrollViewportToShowTarget', () => {} );
 			const root = viewDocument.createRoot( document.createElement( 'div' ) );