Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Changed: ChangeBuffer recognizes 'transparent' batch type. Fixes #2. #18

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/changebuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -85,7 +82,7 @@ export default class ChangeBuffer {

/**
* Current batch to which a feature should add its deltas. Once the {@link typing.ChangeBuffer#size}
* reach or exceedes the {@link typing.ChangeBuffer#limit}, then the batch is set to a new instance and size is reset.
* reach or exceeds the {@link typing.ChangeBuffer#limit}, then the batch is set to a new instance and size is reset.
*
* @type {engine.treeModel.batch.Batch}
*/
Expand Down Expand Up @@ -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();
}
}
Expand Down
13 changes: 3 additions & 10 deletions tests/changebuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,21 +96,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;

Expand Down