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

Commit

Permalink
Merge branch 'master' into t/ckeditor5/753
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Jan 16, 2018
2 parents 12a44e6 + e3c2d2e commit 4874278
Show file tree
Hide file tree
Showing 36 changed files with 79 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Software License Agreement
==========================

**CKEditor 5 Typing Feature**https://github.com/ckeditor/ckeditor5-typing <br>
Copyright (c) 2003-2017, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.
Copyright (c) 2003-2018, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.

Licensed under the terms of any of the following licenses at your choice:

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"@ckeditor/ckeditor5-link": "^1.0.0-alpha.2",
"@ckeditor/ckeditor5-paragraph": "^1.0.0-alpha.2",
"@ckeditor/ckeditor5-undo": "^1.0.0-alpha.2",
"eslint": "^4.8.0",
"eslint": "^4.15.0",
"eslint-config-ckeditor5": "^1.0.7",
"husky": "^0.14.3",
"lint-staged": "^4.2.3"
"lint-staged": "^6.0.0"
},
"engines": {
"node": ">=6.0.0",
Expand Down
56 changes: 22 additions & 34 deletions src/changebuffer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

/**
* @module typing/changebuffer
*/

import count from '@ckeditor/ckeditor5-utils/src/count';
import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';

/**
Expand All @@ -21,7 +20,7 @@ import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
*
* To use the change buffer you need to let it know about the number of changes that were added to the batch:
*
* const buffer = new ChangeBuffer( document, LIMIT );
* const buffer = new ChangeBuffer( model, LIMIT );
*
* // Later on in your feature:
* buffer.batch.insert( pos, insertedCharacters );
Expand All @@ -35,14 +34,14 @@ export default class ChangeBuffer {
* @param {module:engine/model/document~Document} doc
* @param {Number} [limit=20] The maximum number of atomic changes which can be contained in one batch.
*/
constructor( doc, limit = 20 ) {
constructor( model, limit = 20 ) {
/**
* The document instance.
* The model instance.
*
* @readonly
* @member {module:engine/model/document~Document} #document
* @member {module:engine/model/model~Model} #model
*/
this.document = doc;
this.model = model;

/**
* The number of atomic changes in the buffer. Once it exceeds the {@link #limit},
Expand All @@ -69,19 +68,26 @@ export default class ChangeBuffer {
*/
this.isLocked = false;

this._changeCallback = ( evt, type, changes, batch ) => {
this._onBatch( batch );
// The function to be called in order to notify the buffer about batches which appeared in the document.
// The callback will check whether it is a new batch and in that case the buffer will be flushed.
//
// The reason why the buffer needs to be flushed whenever a new batch appears is that the changes added afterwards
// should be added to a new batch. For instance, when the user types, then inserts an image, and then types again,
// the characters typed after inserting the image should be added to a different batch than the characters typed before.
this._changeCallback = ( evt, batch ) => {
if ( batch.type != 'transparent' && batch !== this._batch ) {
this._reset( true );
}
};

this._selectionChangeCallback = () => {
this._reset();
};

doc.on( 'change', this._changeCallback );
this.model.document.on( 'change', this._changeCallback );

doc.selection.on( 'change:range', this._selectionChangeCallback );

doc.selection.on( 'change:attribute', this._selectionChangeCallback );
this.model.document.selection.on( 'change:range', this._selectionChangeCallback );
this.model.document.selection.on( 'change:attribute', this._selectionChangeCallback );

/**
* The current batch instance.
Expand Down Expand Up @@ -151,27 +157,9 @@ export default class ChangeBuffer {
* Destroys the buffer.
*/
destroy() {
this.document.off( 'change', this._changeCallback );
this.document.selection.off( 'change:range', this._selectionChangeCallback );
this.document.selection.off( 'change:attribute', this._selectionChangeCallback );
}

/**
* The method to be called in order to notify the buffer about batches which appeared in the document.
* The method will check whether it is a new batch and in that case the buffer will be flushed.
*
* The reason why the buffer needs to be flushed whenever a new batch appears is that the changes added afterwards
* should be added to a new batch. For instance, when the user types, then inserts an image, and then types again,
* the characters typed after inserting the image should be added to a different batch than the characters typed before.
*
* @private
* @param {module:engine/model/batch~Batch} batch The batch which appears in the document.
*/
_onBatch( batch ) {
// One operation means a newly created batch.
if ( batch.type != 'transparent' && batch !== this._batch && count( batch.getOperations() ) <= 1 ) {
this._reset( true );
}
this.model.document.off( 'change', this._changeCallback );
this.model.document.selection.off( 'change:range', this._selectionChangeCallback );
this.model.document.selection.off( 'change:attribute', this._selectionChangeCallback );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/delete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
4 changes: 2 additions & 2 deletions src/deletecommand.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down Expand Up @@ -47,7 +47,7 @@ export default class DeleteCommand extends Command {
* @private
* @member {typing.ChangeBuffer} #buffer
*/
this._buffer = new ChangeBuffer( editor.model.document, editor.config.get( 'typing.undoStep' ) );
this._buffer = new ChangeBuffer( editor.model, editor.config.get( 'typing.undoStep' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/deleteobserver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/input.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
4 changes: 2 additions & 2 deletions src/inputcommand.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down Expand Up @@ -33,7 +33,7 @@ export default class InputCommand extends Command {
* @private
* @member {module:typing/changebuffer~ChangeBuffer} #_buffer
*/
this._buffer = new ChangeBuffer( editor.model.document, undoStepSize );
this._buffer = new ChangeBuffer( editor.model, undoStepSize );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/typing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
14 changes: 7 additions & 7 deletions tests/bogusbr-integration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down Expand Up @@ -49,7 +49,7 @@ describe( 'Typing – bogus BR integration', () => {
setData( editor.model, '<paragraph>Foo[]</paragraph>' );
} );

editor.model.document.once( 'changesDone', () => {
editor.model.document.once( 'change', () => {
expect( editor.getData() ).to.equal( '<p>Foo&nbsp;</p>' );
done();
}, { priority: 'low' } );
Expand All @@ -63,7 +63,7 @@ describe( 'Typing – bogus BR integration', () => {
setData( editor.model, '<paragraph>[]</paragraph>' );
} );

editor.model.document.once( 'changesDone', () => {
editor.model.document.once( 'change', () => {
expect( editor.getData() ).to.equal( '<p>&nbsp;</p>' );
done();
}, { priority: 'low' } );
Expand All @@ -77,7 +77,7 @@ describe( 'Typing – bogus BR integration', () => {
setData( editor.model, '<paragraph><$text bold="true">Foo[]</$text></paragraph>' );
} );

editor.model.document.once( 'changesDone', () => {
editor.model.document.once( 'change', () => {
expect( editor.getData() ).to.equal( '<p><strong>Foo&nbsp;</strong></p>' );
done();
}, { priority: 'low' } );
Expand All @@ -95,7 +95,7 @@ describe( 'Typing – bogus BR integration', () => {
setData( editor.model, '<paragraph>Foo[]</paragraph>' );
} );

editor.model.document.once( 'changesDone', () => {
editor.model.document.once( 'change', () => {
expect( editor.getData() ).to.equal( '<p>Foo&nbsp;</p>' );
done();
}, { priority: 'low' } );
Expand All @@ -121,7 +121,7 @@ describe( 'Typing – bogus BR integration', () => {
setData( editor.model, '<paragraph>Foo[]</paragraph>' );
} );

editor.model.document.once( 'changesDone', () => {
editor.model.document.once( 'change', () => {
expect( editor.getData() ).to.equal( '<p>Foo&nbsp;</p>' );
done();
}, { priority: 'low' } );
Expand Down Expand Up @@ -150,7 +150,7 @@ describe( 'Typing – bogus BR integration', () => {
setData( editor.model, '<paragraph>Foo hous[]</paragraph>' );
} );

editor.model.document.once( 'changesDone', () => {
editor.model.document.once( 'change', () => {
expect( editor.getData() ).to.equal( '<p>Foo house</p>' );
done();
}, { priority: 'low' } );
Expand Down
8 changes: 4 additions & 4 deletions tests/changebuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand All @@ -15,19 +15,19 @@ describe( 'ChangeBuffer', () => {
model = new Model();
doc = model.document;
root = doc.createRoot();
buffer = new ChangeBuffer( doc, CHANGE_LIMIT );
buffer = new ChangeBuffer( model, CHANGE_LIMIT );
} );

describe( 'constructor()', () => {
it( 'sets all properties', () => {
expect( buffer ).to.have.property( 'document', doc );
expect( buffer ).to.have.property( 'model', model );
expect( buffer ).to.have.property( 'limit', CHANGE_LIMIT );
expect( buffer ).to.have.property( 'size', 0 );
expect( buffer ).to.have.property( 'isLocked', false );
} );

it( 'sets limit property according to default value', () => {
buffer = new ChangeBuffer( doc );
buffer = new ChangeBuffer( model );

expect( buffer ).to.have.property( 'limit', 20 );
} );
Expand Down
2 changes: 1 addition & 1 deletion tests/delete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/deletecommand-integration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/deletecommand.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
6 changes: 4 additions & 2 deletions tests/deleteobserver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand All @@ -8,6 +8,7 @@
import DeleteObserver from '../src/deleteobserver';
import ViewDocument from '@ckeditor/ckeditor5-engine/src/view/document';
import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventdata';
import createViewRoot from '@ckeditor/ckeditor5-engine/tests/view/_utils/createroot';
import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';

describe( 'DeleteObserver', () => {
Expand All @@ -21,7 +22,8 @@ describe( 'DeleteObserver', () => {
// See ckeditor/ckeditor5-enter#10.
it( 'can be initialized', () => {
expect( () => {
viewDocument.createRoot( document.createElement( 'div' ) );
createViewRoot( viewDocument );
viewDocument.attachDomRoot( document.createElement( 'div' ) );
} ).to.not.throw();
} );

Expand Down
2 changes: 1 addition & 1 deletion tests/input.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/inputcommand-integration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/inputcommand.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/manual/20/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/manual/21/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/manual/40/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/manual/52/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/manual/59/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
2 changes: 1 addition & 1 deletion tests/manual/82/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
Loading

0 comments on commit 4874278

Please sign in to comment.