Bläddra i källkod

Fix: LiveRanges removed by InlineAutoFormatEngine are not detached after removing.

Maciej Gołaszewski 8 år sedan
förälder
incheckning
e463f2eafc

+ 1 - 0
packages/ckeditor5-autoformat/src/inlineautoformatengine.js

@@ -198,6 +198,7 @@ export default class InlineAutoformatEngine {
 				// Remove delimiters.
 				for ( const range of rangesToRemove ) {
 					fixBatch.remove( range );
+					range.detach(); // Prevents memory leaks. #39
 				}
 			} );
 		} );

+ 24 - 0
packages/ckeditor5-autoformat/tests/inlineautoformatengine.js

@@ -137,5 +137,29 @@ describe( 'InlineAutoformatEngine', () => {
 
 			sinon.assert.notCalled( formatSpy );
 		} );
+
+		it( 'should detach removed ranges', () => {
+			const detachSpies = [];
+			const callback = fixBatch => testUtils.sinon.stub( fixBatch, 'remove' ).callsFake( saveDetachSpy );
+
+			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, callback ); // eslint-disable-line no-new
+
+			setData( doc, '<paragraph>*foobar[]</paragraph>' );
+
+			doc.enqueueChanges( () => {
+				doc.batch().insert( doc.selection.getFirstPosition(), '*' );
+			} );
+
+			// There should be two ranges removed
+			expect( detachSpies ).to.have.length( 2 );
+
+			for ( const spy of detachSpies ) {
+				testUtils.sinon.assert.calledOnce( spy );
+			}
+
+			function saveDetachSpy( range ) {
+				detachSpies.push( testUtils.sinon.spy( range, 'detach' ) );
+			}
+		} );
 	} );
 } );