- text = linkNode.innerText || linkNode.textContent;
- inputs.url.val( editor.dom.getAttrib( linkNode, 'href' ) );
- inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) );
- inputs.submit.val( wpLinkL10n.update );
+ linkText = linkNode.innerText || linkNode.textContent;
+ href = editor.dom.getAttrib( linkNode, 'href' );
+
+ if ( ! $.trim( linkText ) ) {
+ linkText = text || '';
+ }
+
+ if ( searchStr && ( urlRegexp.test( searchStr ) || emailRegexp.test( searchStr ) ) ) {
+ href = searchStr;
+ }
+
+ if ( href !== '_wp_link_placeholder' ) {
+ inputs.url.val( href );
+ inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) );
+ inputs.submit.val( wpLinkL10n.update );
+ } else {
+ this.setDefaultValues( linkText );
+ }
+
+ if ( searchStr && searchStr !== href ) {
+ // The user has typed something in the inline dialog. Trigger a search with it.
+ inputs.search.val( searchStr );
+ } else {
+ inputs.search.val( '' );
+ }
+
+ // Always reset the search
+ window.setTimeout( function() {
+ wpLink.searchInternalLinks();
+ } );