TinyMCE: when pasting an URL over a selection, insert a link with the URL instead of replacing the selection with it. Props iseulde. Fixes #31571.

git-svn-id: https://develop.svn.wordpress.org/trunk@31691 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2015-03-09 19:59:14 +00:00
parent 69c449963e
commit 7baa0da965
2 changed files with 24 additions and 1 deletions

View File

@ -1220,6 +1220,12 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
}
});
editor.on( 'beforeexeccommand', function( event ) {
if ( isPlaceholder( editor.selection.getNode() ) ) {
event.preventDefault();
}
} );
return {
_do_shcode: parseShortcode,
_get_shcode: getShortcode

View File

@ -1,7 +1,7 @@
/* global tinymce */
tinymce.PluginManager.add( 'wplink', function( editor ) {
var linkButton;
// Register a command so that it can be invoked by using tinyMCE.activeEditor.execCommand( 'WP_Link' );
editor.addCommand( 'WP_Link', function() {
if ( ( ! linkButton || ! linkButton.disabled() ) && typeof window.wpLink !== 'undefined' ) {
@ -60,4 +60,21 @@ tinymce.PluginManager.add( 'wplink', function( editor ) {
context: 'insert',
prependToContext: true
});
editor.on( 'pastepreprocess', function( event ) {
var pastedStr = event.content;
if ( ! editor.selection.isCollapsed() ) {
pastedStr = pastedStr.replace( /<[^>]+>/g, '' );
pastedStr = tinymce.trim( pastedStr );
if ( /^(?:https?:)?\/\/\S+$/i.test( pastedStr ) ) {
editor.execCommand( 'mceInsertLink', false, {
href: editor.dom.decode( pastedStr )
} );
event.preventDefault();
}
}
} );
});