Make WordPress Core

Changeset 36982


Ignore:
Timestamp:
03/13/2016 10:43:10 PM (10 years ago)
Author:
azaozz
Message:

TinyMCE, inline link: when doing undo/redo with keyboard shortcut, do not focus the inline dialog. Cannot do consecutive undo/redo if the focus is moved away from the editor.

See #33301.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/tinymce/plugins/wplink/plugin.js

    r36974 r36982  
    9191                var inputInstance;
    9292                var linkNode;
     93                var doingUndoRedo;
     94                var doingUndoRedoTimer;
    9395                var $ = window.jQuery;
    9496
     
    167169                                                                }
    168170
    169                                                                 element.focus();
    170                                                                 element.select();
     171                                                                if ( ! doingUndoRedo ) {
     172                                                                        element.focus();
     173                                                                        element.select();
     174                                                                }
    171175                                                        }
    172176                                                } );
     
    301305                        }
    302306                });
     307
     308                // When doing undo and redo with keyboard shortcuts (Ctrl|Cmd+Z, Ctrl|Cmd+Shift+Z, Ctrl|Cmd+Y),
     309                // set a flag to not focus the inline dialog. The editor has to remain focused so the users can do consecutive undo/redo.
     310                editor.on( 'keydown', function( event ) {
     311                        if ( event.altKey || ( tinymce.Env.mac && ( ! event.metaKey || event.ctrlKey ) ) ||
     312                                ( ! tinymce.Env.mac && ! event.ctrlKey ) ) {
     313
     314                                return;
     315                        }
     316
     317                        if ( event.keyCode === 89 || event.keyCode === 90 ) { // Y or Z
     318                                doingUndoRedo = true;
     319
     320                                window.clearTimeout( doingUndoRedoTimer );
     321                                doingUndoRedoTimer = window.setTimeout( function() {
     322                                        doingUndoRedo = false;
     323                                }, 500 );
     324                        }
     325                } );
    303326
    304327                editor.addButton( 'wp_link_preview', {
Note: See TracChangeset for help on using the changeset viewer.