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
This commit is contained in:
Andrew Ozz 2014-07-16 02:18:18 +00:00
parent 76c3055aec
commit a90e8c6ff2
2 changed files with 27 additions and 9 deletions

View File

@ -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.

View File

@ -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;
}
});