TinyMCE: fix adding of too many undo levels for wpviews. The HTML changes several times when a wpview is added. We only want one undo level. Also fixes cases when the cursor is next to an embeddable URL in the Text tab and the user switches to the Visual tab.
See #45307. git-svn-id: https://develop.svn.wordpress.org/trunk@45631 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
1f8d74409b
commit
a7041b951b
@ -25,7 +25,7 @@
|
||||
return '<p>' + window.decodeURIComponent( $1 ) + '</p>';
|
||||
}
|
||||
|
||||
if ( ! content ) {
|
||||
if ( ! content || content.indexOf( ' data-wpview-' ) === -1 ) {
|
||||
return content;
|
||||
}
|
||||
|
||||
@ -111,10 +111,30 @@
|
||||
event.content = resetViews( event.content );
|
||||
} );
|
||||
|
||||
// Replace views with their text inside undo levels.
|
||||
// This also prevents that new levels are added when there are changes inside the views.
|
||||
// Prevent adding of undo levels when replacing wpview markers
|
||||
// or when there are changes only in the (non-editable) previews.
|
||||
editor.on( 'beforeaddundo', function( event ) {
|
||||
event.level.content = resetViews( event.level.content );
|
||||
var lastContent;
|
||||
var newContent = event.level.content || ( event.level.fragments && event.level.fragments.join( '' ) );
|
||||
|
||||
if ( ! event.lastLevel ) {
|
||||
lastContent = editor.startContent;
|
||||
} else {
|
||||
lastContent = event.lastLevel.content || ( event.lastLevel.fragments && event.lastLevel.fragments.join( '' ) );
|
||||
}
|
||||
|
||||
if (
|
||||
! newContent ||
|
||||
! lastContent ||
|
||||
newContent.indexOf( ' data-wpview-' ) === -1 ||
|
||||
lastContent.indexOf( ' data-wpview-' ) === -1
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( resetViews( lastContent ) === resetViews( newContent ) ) {
|
||||
event.preventDefault();
|
||||
}
|
||||
} );
|
||||
|
||||
// Make sure views are copied as their text.
|
||||
|
@ -444,13 +444,17 @@
|
||||
'<div class="wpview wpview-wrap" data-wpview-text="' + this.encodedText + '" data-wpview-type="' + this.type + '" contenteditable="false"></div>'
|
||||
);
|
||||
|
||||
editor.undoManager.ignore( function() {
|
||||
editor.$( node ).replaceWith( $viewNode );
|
||||
} );
|
||||
|
||||
if ( selected ) {
|
||||
setTimeout( function() {
|
||||
editor.undoManager.ignore( function() {
|
||||
editor.selection.select( $viewNode[0] );
|
||||
editor.selection.collapse();
|
||||
} );
|
||||
} );
|
||||
}
|
||||
} );
|
||||
},
|
||||
@ -961,8 +965,9 @@
|
||||
|
||||
views.register( 'embedURL', _.extend( {}, embed, {
|
||||
match: function( content ) {
|
||||
var re = /(^|<p>)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi,
|
||||
match = re.exec( content );
|
||||
// There may be a "bookmark" node next to the URL...
|
||||
var re = /(^|<p>(?:<span data-mce-type="bookmark"[^>]+>\s*<\/span>)?)(https?:\/\/[^\s"]+?)((?:<span data-mce-type="bookmark"[^>]+>\s*<\/span>)?<\/p>\s*|$)/gi;
|
||||
var match = re.exec( content );
|
||||
|
||||
if ( match ) {
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user