From b6a378d34543790db529f7735b38855e6fc36640 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 17 Dec 2018 01:48:05 +0000 Subject: [PATCH] TinyMCE: Fix the keyboard shortcut (Alt+Shift+H) to not open the default Block Editor help modal and change the title of the help modal to "Classic Block Keyboard Shortcuts" in the Classic BLock. Also remove Alt+Shift+Z in the Classic Block as it conflicts with the Block Editor. Props azaozz. Merges [43915] to trunk. Fixes #45365. git-svn-id: https://develop.svn.wordpress.org/trunk@44257 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tinymce/plugins/wordpress/plugin.js | 21 ++++++++++++++++--- src/wp-includes/class-wp-editor.php | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js index 62872d2d2a..252d4d642e 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js @@ -370,7 +370,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { html += ''; dialog = editor.windowManager.open( { - title: 'Keyboard Shortcuts', + title: editor.settings.classic_block_editor ? 'Classic Block Keyboard Shortcuts' : 'Keyboard Shortcuts', items: { type: 'container', classes: 'wp-help', @@ -652,10 +652,8 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { u: 'InsertUnorderedList', o: 'InsertOrderedList', m: 'WP_Medialib', - z: 'WP_Adv', t: 'WP_More', d: 'Strikethrough', - h: 'WP_Help', p: 'WP_Page', x: 'WP_Code' }, function( command, key ) { @@ -668,6 +666,23 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } } ); + // Alt+Shift+Z removes a block in the Block Editor, don't add it to the Classic Block. + if ( ! editor.settings.classic_block_editor ) { + editor.addShortcut( 'access+z', '', 'WP_Adv' ); + } + + // Workaround for not triggering the global help modal in the Block Editor by the Classic Block shortcut. + editor.on( 'keydown', function( event ) { + if ( event.shiftKey && event.altKey && event.code === 'KeyH' ) { + editor.execCommand( 'WP_Help' ); + event.stopPropagation(); + event.stopImmediatePropagation(); + return false; + } + + return true; + }); + if ( window.getUserSetting( 'editor_plain_text_paste_warning' ) > 1 ) { editor.settings.paste_plaintext_inform = false; } diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php index a9e5e04f2e..7de08a7327 100644 --- a/src/wp-includes/class-wp-editor.php +++ b/src/wp-includes/class-wp-editor.php @@ -1287,6 +1287,7 @@ final class _WP_Editors { // Shortcuts help modal 'Keyboard Shortcuts' => array( __( 'Keyboard Shortcuts' ), 'accessH' ), + 'Classic Block Keyboard Shortcuts' => __( 'Classic Block Keyboard Shortcuts' ), 'Default shortcuts,' => __( 'Default shortcuts,' ), 'Additional shortcuts,' => __( 'Additional shortcuts,' ), 'Focus shortcuts:' => __( 'Focus shortcuts:' ),