Sfoglia il codice sorgente

Merge pull request #19 from ckeditor/t/7

Changed: ChangeBuffer recognizes 'transparent' batch type. Fixes #7.
Piotr Jasiun 9 anni fa
parent
commit
e74f89f486

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

@@ -60,10 +60,7 @@ export default class ChangeBuffer {
 		this.limit = limit;
 
 		this._changeCallback = ( evt, type, changes, batch ) => {
-			// See #7.
-			if ( batch ) {
-				this._onBatch( batch );
-			}
+			this._onBatch( batch );
 		};
 
 		doc.on( 'change', this._changeCallback );
@@ -130,8 +127,8 @@ export default class ChangeBuffer {
 	 * @param {engine.treeModel.batch.Batch} batch The batch which appears in the document.
 	 */
 	_onBatch( batch ) {
-		// 1 operation means a newly created batch.
-		if ( batch !== this._batch && count( batch.getOperations() ) <= 1 ) {
+		// One operation means a newly created batch.
+		if ( batch.type != 'transparent' && batch !== this._batch && count( batch.getOperations() ) <= 1 ) {
 			this._reset();
 		}
 	}

+ 3 - 10
packages/ckeditor5-typing/tests/changebuffer.js

@@ -9,8 +9,6 @@ import ChangeBuffer from '/ckeditor5/typing/changebuffer.js';
 import Document from '/ckeditor5/engine/model/document.js';
 import Batch from '/ckeditor5/engine/model/batch.js';
 import Position from '/ckeditor5/engine/model/position.js';
-import InsertDelta from '/ckeditor5/engine/model/delta/insertdelta.js';
-import InsertOperation from '/ckeditor5/engine/model/operation/insertoperation.js';
 
 describe( 'ChangeBuffer', () => {
 	const CHANGE_LIMIT = 3;
@@ -104,21 +102,16 @@ describe( 'ChangeBuffer', () => {
 			expect( buffer.batch ).to.not.equal( bufferBatch );
 		} );
 
-		// See #7.
-		it( 'is not reset when changes are applied without a batch', () => {
+		it( 'is not reset when changes are applied in transparent batch', () => {
 			const bufferBatch = buffer.batch;
 
-			const delta = new InsertDelta();
-			const insert = new InsertOperation( Position.createAt( root, 0 ), 'a', doc.version );
-
-			delta.addOperation( insert );
-			doc.applyOperation( insert );
+			doc.batch( 'transparent' ).insert( Position.createAt( root, 0 ), 'a' );
 
 			expect( buffer.batch ).to.equal( bufferBatch );
 		} );
 	} );
 
-	describe( 'destory', () => {
+	describe( 'destroy', () => {
 		it( 'offs the buffer from the document', () => {
 			const batch1 = buffer.batch;