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

Commit

Permalink
Fix: Removing highlight on text crashed when marker range was empty-ish.
Browse files Browse the repository at this point in the history
  • Loading branch information
scofalik committed Mar 12, 2018
1 parent 5d02afa commit 1a6d529
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/conversion/downcast-converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,11 @@ export function removeHighlight( highlightDescriptor ) {

// Get all elements bound with given marker name.
const elements = conversionApi.mapper.markerNameToElements( data.markerName );

if ( !elements ) {
return;
}

conversionApi.mapper.unbindElementsFromMarkerName( data.markerName );

for ( const element of elements ) {
Expand Down
22 changes: 22 additions & 0 deletions tests/conversion/downcast-converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,28 @@ describe( 'downcast-converters', () => {

expect( viewToString( viewRoot ) ).to.equal( '<div><p>foo</p><p>bar</p></div>' );
} );

it( 'should do nothing if marker is applied and removed on empty-ish range', () => {
dispatcher.on( 'addMarker:marker', highlightText( highlightDescriptor ) );
dispatcher.on( 'removeMarker:marker', removeHighlight( highlightDescriptor ) );

const p1 = modelRoot.getChild( 0 );
const p2 = modelRoot.getChild( 1 );

const markerRange = ModelRange.createFromParentsAndOffsets( p1, 3, p2, 0 );

model.change( writer => {
writer.setMarker( 'marker', markerRange );
} );

expect( viewToString( viewRoot ) ).to.equal( '<div><p>foo</p><p>bar</p></div>' );

model.change( writer => {
writer.removeMarker( 'marker', markerRange );
} );

expect( viewToString( viewRoot ) ).to.equal( '<div><p>foo</p><p>bar</p></div>' );
} );
} );

describe( 'on element', () => {
Expand Down

0 comments on commit 1a6d529

Please sign in to comment.