Navigation Menu

Skip to content

Commit

Permalink
Fixed a case where updating link from a collapsed selection, would no…
Browse files Browse the repository at this point in the history
…t end up with selection whole anchor.
  • Loading branch information
mlewand committed Aug 25, 2016
1 parent 65dab53 commit dbcce1f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions plugins/link/dialogs/link.js
Expand Up @@ -875,21 +875,25 @@
// We're only editing an existing link, so just overwrite the attributes.
var element = this._.selectedElement,
href = element.data( 'cke-saved-href' ),
textView = element.getHtml();
textView = element.getHtml(),
newText;

element.setAttributes( attributes.set );
element.removeAttributes( attributes.removed );

// Update text view when user changes protocol (#4612).
if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 ) {
// Short mailto link text view (#5736).
element.setHtml( data.type == 'email' ?
data.email.address : attributes.set[ 'data-cke-saved-href' ] );
newText = data.type == 'email' ? data.email.address : attributes.set[ 'data-cke-saved-href' ];
} else if ( data.linkText && initialLinkText != data.linkText ) {
// Display text has been changed.
newText = data.linkText;
}

if ( newText ) {
element.setHtml( newText );
// We changed the content, so need to select it again.
selection.selectElement( element );
} else if ( data.linkText && initialLinkText != data.linkText ) {
element.setHtml( data.linkText );
}

delete this._.selectedElement;
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/link/link.js
Expand Up @@ -171,7 +171,7 @@
assert.areSame( dialog.getValueOf( 'info', 'linkDisplayText' ), 'http://ckeditor.com' );
dialog.setValueOf( 'info', 'linkDisplayText', 'testing 1, 2, 3' );
dialog.getButton( 'ok' ).click();
assert.areSame( '<a href="http://ckeditor.com">testing 1, 2, 3</a>', bot.getData( true ) );
assert.areSame( '[<a href="http://ckeditor.com">testing 1, 2, 3</a>]', bender.tools.getHtmlWithSelection( bot.editor ) );
} );
},

Expand Down
1 change: 1 addition & 0 deletions tests/plugins/link/manual/editlinkdisplaytext.md
Expand Up @@ -10,6 +10,7 @@
* The Display Text input is not disabled.
1. Change Display Text input to "baz".
1. Click OK.
* The link should get selected, like so `foo [baz].`
1. Click Source button.

**Expected:**
Expand Down

0 comments on commit dbcce1f

Please sign in to comment.