From 5ff0ea1fcf17410e5ee1dc5cebaaaf6d81fc4c82 Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Tue, 21 Apr 2015 13:58:09 +0000 Subject: [PATCH] wpLink: Make the text editor experience the same as in the visual editor. props azaozz. fixes #31890. git-svn-id: https://develop.svn.wordpress.org/trunk@32242 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/wplink.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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(); }