Parcourir la source

Changed: Changes after model events refactor in ckeditor5-engine.

Szymon Cofalik il y a 8 ans
Parent
commit
f57ff157a5

+ 15 - 13
packages/ckeditor5-typing/src/changebuffer.js

@@ -21,7 +21,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 );
@@ -35,14 +35,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},
@@ -69,7 +69,10 @@ export default class ChangeBuffer {
 		 */
 		this.isLocked = false;
 
-		this._changeCallback = ( evt, type, changes, batch ) => {
+		this._changeCallback = ( evt, args ) => {
+			const operation = args[ 0 ];
+			const batch = operation.delta.batch;
+
 			this._onBatch( batch );
 		};
 
@@ -77,11 +80,10 @@ export default class ChangeBuffer {
 			this._reset();
 		};
 
-		doc.on( 'change', this._changeCallback );
-
-		doc.selection.on( 'change:range', this._selectionChangeCallback );
+		this.model.on( 'applyOperation', this._changeCallback );
 
-		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.
@@ -151,9 +153,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 );
+		this.model.off( 'applyOperation', this._changeCallback );
+		this.model.document.selection.off( 'change:range', this._selectionChangeCallback );
+		this.model.document.selection.off( 'change:attribute', this._selectionChangeCallback );
 	}
 
 	/**

+ 1 - 1
packages/ckeditor5-typing/src/deletecommand.js

@@ -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' ) );
 	}
 
 	/**

+ 1 - 1
packages/ckeditor5-typing/src/inputcommand.js

@@ -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 );
 	}
 
 	/**

+ 6 - 6
packages/ckeditor5-typing/tests/bogusbr-integration.js

@@ -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' } );
@@ -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' } );
@@ -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' } );
@@ -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' } );
@@ -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' } );
@@ -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' } );

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

@@ -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 );
 		} );

+ 1 - 1
packages/ckeditor5-typing/tests/manual/nbsp.js

@@ -31,7 +31,7 @@ ClassicEditor
 			} );
 		} );
 
-		editor.model.document.on( 'changesDone', () => {
+		editor.model.document.once( 'change', () => {
 			console.clear();
 
 			const modelData = getModelData( editor.model.document, { withoutSelection: true } );

+ 2 - 2
packages/ckeditor5-typing/tests/spellchecking.js

@@ -43,7 +43,7 @@ describe( 'Typing – spellchecking integration', () => {
 
 	beforeEach( () => {
 		if ( onChangesDone ) {
-			editor.model.document.off( 'changesDone', onChangesDone );
+			editor.model.document.off( 'change', onChangesDone );
 			onChangesDone = null;
 		}
 
@@ -261,7 +261,7 @@ function emulateSpellcheckerInsertText( editor, nodeIndex, rangeStart, rangeEnd,
 		] );
 	} );
 
-	editor.model.document.once( 'changesDone', onChangesDoneCallback, { priority: 'low' } );
+	model.document.once( 'change', onChangesDoneCallback, { priority: 'low' } );
 
 	window.document.execCommand( 'insertText', false, text );
 }