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

Commit

Permalink
Other: Detach LiveRange used to apply inline auto format.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Oct 17, 2017
1 parent f402607 commit bd68e72
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/inlineautoformatengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ export default class InlineAutoformatEngine {
// Apply format.
formatCallback( fixBatch, validRanges );

// Detach ranges used to apply Autoformat. Prevents memory leaks. #39
rangesToFormat.forEach( range => range.detach() );

// Remove delimiters.
for ( const range of rangesToRemove ) {
fixBatch.remove( range );
Expand Down
7 changes: 5 additions & 2 deletions tests/inlineautoformatengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ describe( 'InlineAutoformatEngine', () => {
it( 'should detach removed ranges', () => {
const detachSpies = [];
const callback = fixBatch => testUtils.sinon.stub( fixBatch, 'remove' ).callsFake( saveDetachSpy );
testUtils.sinon.stub( editor.document.schema, 'getValidRanges' )
.callThrough()
.callsFake( ranges => ranges.map( saveDetachSpy ) );

new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, callback ); // eslint-disable-line no-new

Expand All @@ -150,8 +153,8 @@ describe( 'InlineAutoformatEngine', () => {
doc.batch().insert( doc.selection.getFirstPosition(), '*' );
} );

// There should be two ranges removed.
expect( detachSpies ).to.have.length( 2 );
// There should be two removed ranges and one range used to apply autoformat.
expect( detachSpies ).to.have.length( 3 );

for ( const spy of detachSpies ) {
testUtils.sinon.assert.calledOnce( spy );
Expand Down

0 comments on commit bd68e72

Please sign in to comment.