diff --git a/src/wp-includes/js/wplink.js b/src/wp-includes/js/wplink.js index 14361a26db..31489f8357 100644 --- a/src/wp-includes/js/wplink.js +++ b/src/wp-includes/js/wplink.js @@ -142,6 +142,8 @@ var wpLink; }, refresh: function() { + var text = ''; + // Refresh rivers (clear links, check visibility) rivers.search.refresh(); rivers.recent.refresh(); @@ -149,8 +151,21 @@ var wpLink; if ( wpLink.isMCE() ) { wpLink.mceRefresh(); } else { - inputs.wrap.removeClass( 'has-text-field' ); - inputs.text.val( '' ); + // For the Text editor the "Link text" field is always shown + if ( ! inputs.wrap.hasClass( 'has-text-field' ) ) { + inputs.wrap.addClass( 'has-text-field' ); + } + + if ( document.selection ) { + // Old IE + text = document.selection.createRange().text || ''; + } else if ( typeof this.textarea.selectionStart !== 'undefined' && + ( this.textarea.selectionStart !== this.textarea.selectionEnd ) ) { + // W3C + text = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ) || ''; + } + + inputs.text.val( text ); wpLink.setDefaultValues(); }