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

Commit

Permalink
Merge pull request #1715 from ckeditor/t/1714
Browse files Browse the repository at this point in the history
Fix: Prevent from throwing while updating empty fake selection container. Closes #1714.
  • Loading branch information
Piotr Jasiun committed Apr 1, 2019
2 parents 21ecb7e + 49c7123 commit c48f5a4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/view/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,15 +706,15 @@ export default class Renderer {
} );

// Fill it with a text node so we can update it later.
container.appendChild( domDocument.createTextNode( '\u00A0' ) );
container.textContent = '\u00A0';
}

if ( !container.parentElement || container.parentElement != domRoot ) {
domRoot.appendChild( container );
}

// Update contents.
container.firstChild.data = this.selection.fakeSelectionLabel || '\u00A0';
container.textContent = this.selection.fakeSelectionLabel || '\u00A0';

// Update selection.
const domSelection = domDocument.getSelection();
Expand Down
25 changes: 25 additions & 0 deletions tests/view/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,31 @@ describe( 'Renderer', () => {
expect( bindSelection.isEqual( selection ) ).to.be.true;
} );

// https://github.com/ckeditor/ckeditor5-engine/issues/1714.
it( 'should handle situation when label got removed from the fake selection container', () => {
const label = 'fake selection label';
selection._setTo( selection.getRanges(), { fake: true, label } );
renderer.render();

expect( domRoot.childNodes.length ).to.equal( 2 );

const container = domRoot.childNodes[ 1 ];
expect( domConverter.mapDomToView( container ) ).to.be.undefined;
expect( container.childNodes.length ).to.equal( 1 );

const textNode = container.childNodes[ 0 ];
expect( textNode.textContent ).to.equal( label );

// Remove a text node (label) from the fake selection container.
// It can be done by pressing backspace while the delete command is disabled and selection is on the widget.
textNode.remove();

renderer.render();

const domSelection = domRoot.ownerDocument.getSelection();
assertDomSelectionContents( domSelection, container, /^fake selection label$/ );
} );

// Use a forgiving way of checking what the selection contains
// because Safari normalizes the selection ranges so precise checking is troublesome.
// Also, Edge returns a normal space instead of nbsp so we need to use even more alternatives.
Expand Down

0 comments on commit c48f5a4

Please sign in to comment.