WordPress.org

Make WordPress Core

Changeset 29184


Ignore:
Timestamp:
07/16/2014 02:18:18 AM (4 years ago)
Author:
azaozz
Message:

TinyMCE wpView: handle execCommand when the "fake caret" P is selected, props avryl, see #28595

Location:
trunk/src/wp-includes/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/mce-view.js

    r29179 r29184  
    1 /* global tinymce, MediaElementPlayer, WPPlaylistView */
     1/* global tinymce */
    22/**
    33 * Note: this API is "experimental" meaning that it will probably change
  • trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js

    r29183 r29184  
    1111        toRemove = false,
    1212        firstFocus = true,
    13         cursorInterval, lastKeyDownNode, setViewCursorTries, focus;
     13        cursorInterval, lastKeyDownNode, setViewCursorTries, focus, execCommandView;
    1414
    1515    function getView( node ) {
     
    582582        if ( focus ) {
    583583            if ( view ) {
    584                 if ( className === 'wpview-selection-before' || className === 'wpview-selection-after' && editor.selection.isCollapsed() ) {
     584                if ( ( className === 'wpview-selection-before' || className === 'wpview-selection-after' ) && editor.selection.isCollapsed() ) {
    585585                    setViewCursorTries = 0;
    586586
     
    619619    });
    620620
    621     editor.on( 'BeforeExecCommand', function( event ) {
    622         var cmd = event.command,
     621    editor.on( 'BeforeExecCommand', function() {
     622        var node = editor.selection.getNode(),
    623623            view;
    624624
    625         if ( cmd === 'undo' || cmd === 'redo' || cmd === 'RemoveFormat' || cmd === 'mceToggleFormat' ) {
    626             return;
    627         }
    628 
    629         if ( view = getView( editor.selection.getNode() ) ) {
     625        if ( node && ( node.className === 'wpview-selection-before' || node.className === 'wpview-selection-after' ) && ( view = getView( node ) ) ) {
    630626            handleEnter( view );
     627            execCommandView = view;
     628        }
     629    });
     630
     631    editor.on( 'ExecCommand', function() {
     632        var toSelect, node;
     633
     634        if ( selected ) {
     635            toSelect = selected;
     636            deselect();
     637            select( toSelect );
     638        }
     639
     640        if ( execCommandView ) {
     641            node = execCommandView.nextSibling;
     642
     643            if ( node && node.nodeName === 'P' && editor.dom.isEmpty( node ) ) {
     644                editor.dom.remove( node );
     645                setViewCursor( false, execCommandView );
     646            }
     647
     648            execCommandView = false;
    631649        }
    632650    });
Note: See TracChangeset for help on using the changeset viewer.