浏览代码

Docs fixes in SelectionObserver.

Szymon Kupś 8 年之前
父节点
当前提交
15b65285c6

+ 3 - 14
packages/ckeditor5-engine/src/view/observer/selectionobserver.js

@@ -148,7 +148,9 @@ export default class SelectionObserver extends Observer {
 		}
 
 		// Ensure we are not in the infinite loop (#400).
-		if ( this._isInfiniteLoop() ) {
+		// This counter is reset every 1 seconds. 200 selection changes in 1 seconds is enough high number
+		// to be very difficult (impossible) to achieve using just keyboard keys (during normal editor use).
+		if ( ++this._loopbackCounter > 200 ) {
 			/**
 			 * Selection change observer detected an infinite rendering loop.
 			 * Most probably you try to put the selection in the position which is not allowed
@@ -179,19 +181,6 @@ export default class SelectionObserver extends Observer {
 	}
 
 	/**
-	 * Checks if selection rendering entered an infinite loop.
-	 *
-	 * See https://github.com/ckeditor/ckeditor5-engine/issues/400.
-	 *
-	 * @private
-	 * @param {module:engine/view/selection~Selection} newSelection DOM selection converted to view.
-	 * @returns {Boolean} True is the same selection repeat more then 10 times.
-	 */
-	_isInfiniteLoop() {
-		return ++this._loopbackCounter > 200;
-	}
-
-	/**
 	 * Clears `SelectionObserver` internal properties connected with preventing infinite loop.
 	 *
 	 * @protected

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

@@ -181,7 +181,6 @@ describe( 'SelectionObserver', () => {
 	it( 'should not be treated as an infinite loop if changes are not often', () => {
 		const clock = testUtils.sinon.useFakeTimers( 'setInterval', 'clearInterval' );
 		const stub = testUtils.sinon.stub( log, 'warn' );
-		const changeCount = 75;
 
 		// We need to recreate SelectionObserver, so it will use mocked setInterval.
 		selectionObserver.disable();
@@ -196,7 +195,8 @@ describe( 'SelectionObserver', () => {
 				clock.restore();
 			} );
 
-		// Does changes in DOM that should not trigger infinite loop warning. Then skips clock to reset loop counter.
+		// Selectionchange event is called twice per `changeDomSelection()` execution. We call it 75 times to get
+		// 150 events. Infinite loop counter is reset, so calling this method twice should not show any warning.
 		function doChanges() {
 			return new Promise( resolve => {
 				viewDocument.once( 'selectionChangeDone', () => {
@@ -204,7 +204,7 @@ describe( 'SelectionObserver', () => {
 					resolve();
 				} );
 
-				for ( let i = 0; i < changeCount; i++ ) {
+				for ( let i = 0; i < 75; i++ ) {
 					changeDomSelection();
 				}
 			} );