Browse Source

Minor improvements.

Maciej Bukowski 7 years ago
parent
commit
7759be5437

+ 1 - 1
packages/ckeditor5-engine/src/model/document.js

@@ -147,11 +147,11 @@ export default class Document {
 		// Wait for `_change` event from model, which signalizes that outermost change block has finished.
 		// When this happens, check if there were any changes done on document, and if so, call post fixers,
 		// fire `change` event for features and conversion and then reset the differ.
+		// Fire `change:data` event when at least one operation changes the data model.
 		this.listenTo( model, '_change', ( evt, writer ) => {
 			if ( !this.differ.isEmpty || hasSelectionChanged ) {
 				this._callPostFixers( writer );
 
-				// Fire `change:data` event when at least one operation changes the data model.
 				if ( !this.differ.isEmpty && isBatchAffectingData( writer.batch ) ) {
 					this.fire( 'change:data', writer.batch );
 				} else {

+ 18 - 2
packages/ckeditor5-engine/tests/model/document.js

@@ -405,7 +405,7 @@ describe( 'Document', () => {
 			sinon.assert.notCalled( spy );
 		} );
 
-		it( 'should fire if default marker operation is applied', () => {
+		it( 'should be fired if default marker operation is applied', () => {
 			const root = doc.createRoot();
 			const spy = sinon.spy();
 
@@ -421,7 +421,7 @@ describe( 'Document', () => {
 			sinon.assert.calledOnce( spy );
 		} );
 
-		it( 'should not fire if the marker operation is applied and marker does not affect data', () => {
+		it( 'should not be fired if the marker operation is applied and marker does not affect data', () => {
 			const root = doc.createRoot();
 			const spy = sinon.spy();
 
@@ -436,6 +436,22 @@ describe( 'Document', () => {
 
 			sinon.assert.notCalled( spy );
 		} );
+
+		it( 'should not be fired if writer was used on non-document tree', () => {
+			const spy = sinon.spy();
+
+			doc.on( 'change:data', ( evt, batch ) => {
+				spy();
+				expect( batch ).to.be.instanceof( Batch );
+			} );
+
+			model.change( writer => {
+				const docFrag = writer.createDocumentFragment();
+				writer.insertText( 'foo', docFrag, 0 );
+			} );
+
+			expect( spy.calledOnce ).to.be.false;
+		} );
 	} );
 
 	it( 'should be correctly converted to json', () => {