From c1c7feb539485a2a884b548654b4b63637961b6b Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Wed, 21 Feb 2018 18:31:12 +0100 Subject: [PATCH] Fixed: Link feature was creating empty text nodes with `linkHref` attribute. --- src/linkcommand.js | 4 +++- tests/linkcommand.js | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/linkcommand.js b/src/linkcommand.js index ee8ecee..1b64d54 100644 --- a/src/linkcommand.js +++ b/src/linkcommand.js @@ -73,7 +73,9 @@ export default class LinkCommand extends Command { writer.setSelection( linkRange ); } // If not then insert text node with `linkHref` attribute in place of caret. - else { + // However, since selection in collapsed, attribute value will be used as data for text node. + // So, if `href` is empty, do not create text node. + else if ( href !== '' ) { const attributes = toMap( selection.getAttributes() ); attributes.set( 'linkHref', href ); diff --git a/tests/linkcommand.js b/tests/linkcommand.js index 73cee73..8cb8458 100644 --- a/tests/linkcommand.js +++ b/tests/linkcommand.js @@ -249,6 +249,14 @@ describe( 'LinkCommand', () => { expect( getData( model ) ).to.equal( '

foo[]bar

' ); } ); + + it( 'should not insert text node if link is empty', () => { + setData( model, '

foo[]bar

' ); + + command.execute( '' ); + + expect( getData( model ) ).to.equal( '

foo[]bar

' ); + } ); } ); } ); } );