From a90e8c6ff2027d75cfff6df0f0f5bc8bd4590e07 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 16 Jul 2014 02:18:18 +0000 Subject: [PATCH] TinyMCE wpView: handle execCommand when the "fake caret" P is selected, props avryl, see #28595 git-svn-id: https://develop.svn.wordpress.org/trunk@29184 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/mce-view.js | 2 +- .../js/tinymce/plugins/wpview/plugin.js | 34 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index 96fc01974e..4e2f7bd214 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -1,4 +1,4 @@ -/* global tinymce, MediaElementPlayer, WPPlaylistView */ +/* global tinymce */ /** * Note: this API is "experimental" meaning that it will probably change * in the next few releases based on feedback from 3.9.0. diff --git a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index b74debcddd..603fd867f8 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -10,7 +10,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { TreeWalker = tinymce.dom.TreeWalker, toRemove = false, firstFocus = true, - cursorInterval, lastKeyDownNode, setViewCursorTries, focus; + cursorInterval, lastKeyDownNode, setViewCursorTries, focus, execCommandView; function getView( node ) { return getParent( node, 'wpview-wrap' ); @@ -581,7 +581,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { if ( focus ) { if ( view ) { - if ( className === 'wpview-selection-before' || className === 'wpview-selection-after' && editor.selection.isCollapsed() ) { + if ( ( className === 'wpview-selection-before' || className === 'wpview-selection-after' ) && editor.selection.isCollapsed() ) { setViewCursorTries = 0; deselect(); @@ -618,16 +618,34 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { } }); - editor.on( 'BeforeExecCommand', function( event ) { - var cmd = event.command, + editor.on( 'BeforeExecCommand', function() { + var node = editor.selection.getNode(), view; - if ( cmd === 'undo' || cmd === 'redo' || cmd === 'RemoveFormat' || cmd === 'mceToggleFormat' ) { - return; + if ( node && ( node.className === 'wpview-selection-before' || node.className === 'wpview-selection-after' ) && ( view = getView( node ) ) ) { + handleEnter( view ); + execCommandView = view; + } + }); + + editor.on( 'ExecCommand', function() { + var toSelect, node; + + if ( selected ) { + toSelect = selected; + deselect(); + select( toSelect ); } - if ( view = getView( editor.selection.getNode() ) ) { - handleEnter( view ); + if ( execCommandView ) { + node = execCommandView.nextSibling; + + if ( node && node.nodeName === 'P' && editor.dom.isEmpty( node ) ) { + editor.dom.remove( node ); + setViewCursor( false, execCommandView ); + } + + execCommandView = false; } });