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.

git-svn-id: https://develop.svn.wordpress.org/trunk@36982 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2016-03-13 22:43:10 +00:00
parent 98c197f09f
commit 4fcb429575
1 changed files with 25 additions and 2 deletions

View File

@ -90,6 +90,8 @@
var previewInstance; var previewInstance;
var inputInstance; var inputInstance;
var linkNode; var linkNode;
var doingUndoRedo;
var doingUndoRedoTimer;
var $ = window.jQuery; var $ = window.jQuery;
function getSelectedLink() { function getSelectedLink() {
@ -166,9 +168,11 @@
element.value = window.wpLink.getUrlFromSelection( selection ); element.value = window.wpLink.getUrlFromSelection( selection );
} }
if ( ! doingUndoRedo ) {
element.focus(); element.focus();
element.select(); element.select();
} }
}
} ); } );
} }
} ); } );
@ -301,6 +305,25 @@
} }
}); });
// When doing undo and redo with keyboard shortcuts (Ctrl|Cmd+Z, Ctrl|Cmd+Shift+Z, Ctrl|Cmd+Y),
// set a flag to not focus the inline dialog. The editor has to remain focused so the users can do consecutive undo/redo.
editor.on( 'keydown', function( event ) {
if ( event.altKey || ( tinymce.Env.mac && ( ! event.metaKey || event.ctrlKey ) ) ||
( ! tinymce.Env.mac && ! event.ctrlKey ) ) {
return;
}
if ( event.keyCode === 89 || event.keyCode === 90 ) { // Y or Z
doingUndoRedo = true;
window.clearTimeout( doingUndoRedoTimer );
doingUndoRedoTimer = window.setTimeout( function() {
doingUndoRedo = false;
}, 500 );
}
} );
editor.addButton( 'wp_link_preview', { editor.addButton( 'wp_link_preview', {
type: 'WPLinkPreview', type: 'WPLinkPreview',
onPostRender: function() { onPostRender: function() {