Przeglądaj źródła

Additional test and docs.

Piotrek Koszuliński 8 lat temu
rodzic
commit
542dd51026

+ 4 - 1
packages/ckeditor5-engine/src/model/documentselection.js

@@ -693,7 +693,10 @@ function getAttrsIfCharacter( node ) {
 
 
 // Removes selection attributes from element which is not anymore empty.
 // Removes selection attributes from element which is not anymore empty.
 function clearAttributesStoredInElement( changes, batch ) {
 function clearAttributesStoredInElement( changes, batch ) {
-	if ( batch.type == 'transparent' ) {
+	// Batch may not be passed to the document#change event in some tests.
+	// See https://github.com/ckeditor/ckeditor5-engine/issues/1001#issuecomment-314202352
+	// Ignore also transparent batches because they are... transparent.
+	if ( !batch || batch.type == 'transparent' ) {
 		return;
 		return;
 	}
 	}
 
 

+ 11 - 0
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -1048,6 +1048,17 @@ describe( 'DocumentSelection', () => {
 
 
 				expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
 				expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
 			} );
 			} );
+
+			// Rename and some other deltas don't specify range in doc#change event.
+			// So let's see if there's no crash or something.
+			it( 'are not removed on rename', () => {
+				selection.setRanges( [ rangeInEmptyP ] );
+				selection.setAttribute( 'foo', 'bar' );
+
+				doc.batch().rename( emptyP, 'pnew' );
+
+				expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
+			} );
 		} );
 		} );
 	} );
 	} );
 } );
 } );