8
0
Просмотр исходного кода

Change buffer should be flushed once the size reaches the limit.

Piotrek Koszuliński 9 лет назад
Родитель
Сommit
4d8667091a

+ 3 - 3
packages/ckeditor5-typing/src/changebuffer.js

@@ -79,7 +79,7 @@ export default class ChangeBuffer {
 
 	/**
 	 * Current batch to which a feature should add its deltas. Once the {@link typing.ChangeBuffer#size}
-	 * exceedes the {@link typing.ChangeBuffer#limit}, the batch is set to a new instance and size is reset.
+	 * reach or exceedes the {@link typing.ChangeBuffer#limit}, then the batch is set to a new instance and size is reset.
 	 *
 	 * @type {engine.treeModel.batch.Batch}
 	 */
@@ -93,14 +93,14 @@ export default class ChangeBuffer {
 
 	/**
 	 * Input number of changes into the buffer. Once the {@link typing.ChangeBuffer#size}
-	 * exceedes the {@link typing.ChangeBuffer#limit}, the batch is set to a new instance and size is reset.
+	 * reach or exceedes the {@link typing.ChangeBuffer#limit}, then the batch is set to a new instance and size is reset.
 	 *
 	 * @param {Number} changeCount Number of atomic changes to input.
 	 */
 	input( changeCount ) {
 		this.size += changeCount;
 
-		if ( this.size > this.limit ) {
+		if ( this.size >= this.limit ) {
 			this._batch = null;
 		}
 	}

+ 11 - 2
packages/ckeditor5-typing/tests/changebuffer.js

@@ -34,10 +34,10 @@ describe( 'ChangeBuffer', () => {
 			expect( buffer.batch ).to.be.instanceof( Batch );
 		} );
 
-		it( 'is reset once changes exceed the limit', () => {
+		it( 'is reset once changes reaches the limit', () => {
 			const batch1 = buffer.batch;
 
-			buffer.input( CHANGE_LIMIT );
+			buffer.input( CHANGE_LIMIT - 1 );
 
 			expect( buffer.batch ).to.equal( batch1 );
 
@@ -49,6 +49,15 @@ describe( 'ChangeBuffer', () => {
 			expect( batch2 ).to.not.equal( batch1 );
 		} );
 
+		it( 'is reset once changes exceedes the limit', () => {
+			const batch1 = buffer.batch;
+
+			// Exceed the limit with one big jump to ensure that >= operator was used.
+			buffer.input( CHANGE_LIMIT + 1 );
+
+			expect( buffer.batch ).to.not.equal( batch1 );
+		} );
+
 		it( 'is reset once a new batch appears in the document', () => {
 			const batch1 = buffer.batch;