From 6ffafa5bc7124dd58a292720fea49465297f452c Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 17 Dec 2018 03:32:21 +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. Built from https://develop.svn.wordpress.org/trunk@44257 git-svn-id: http://core.svn.wordpress.org/trunk@44087 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-editor.php | 1 + .../js/tinymce/plugins/wordpress/plugin.js | 21 +++++++++++++++--- .../tinymce/plugins/wordpress/plugin.min.js | 2 +- wp-includes/js/tinymce/wp-tinymce.js.gz | Bin 208261 -> 208317 bytes wp-includes/version.php | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/wp-includes/class-wp-editor.php b/wp-includes/class-wp-editor.php index a9e5e04f2e..7de08a7327 100644 --- a/wp-includes/class-wp-editor.php +++ b/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:' ), diff --git a/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/wp-includes/js/tinymce/plugins/wordpress/plugin.js index 62872d2d2a..252d4d642e 100644 --- a/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/wp-includes/js/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/wp-includes/js/tinymce/plugins/wordpress/plugin.min.js b/wp-includes/js/tinymce/plugins/wordpress/plugin.min.js index 03c1a4c62d..d2b86d314a 100644 --- a/wp-includes/js/tinymce/plugins/wordpress/plugin.min.js +++ b/wp-includes/js/tinymce/plugins/wordpress/plugin.min.js @@ -1 +1 @@ -!function(a){(!a.ui.FloatPanel.zIndex||a.ui.FloatPanel.zIndex<100100)&&(a.ui.FloatPanel.zIndex=100100),a.PluginManager.add("wordpress",function(b){function c(c){var d,f,i=0,j=a.$(".block-library-classic__toolbar");"hide"===c?d=!0:j.length&&!j.hasClass("has-advanced-toolbar")&&(j.addClass("has-advanced-toolbar"),c="show"),b.theme.panel&&(f=b.theme.panel.find(".toolbar:not(.menubar)")),f&&f.length>1&&(!c&&f[1].visible()&&(c="hide"),h(f,function(a,b){b>0&&("hide"===c?(a.hide(),i+=30):(a.show(),i-=30))})),i&&!a.Env.iOS&&b.iframeElement&&g.setStyle(b.iframeElement,"height",b.iframeElement.clientHeight+i),d||("hide"===c?(setUserSetting("hidetb","0"),e&&e.active(!1)):(setUserSetting("hidetb","1"),e&&e.active(!0))),b.fire("wp-toolbar-toggle")}function d(){}var e,f,g=a.DOM,h=a.each,i=b.editorManager.i18n.translate,j=window.jQuery,k=window.wp,l=k&&k.editor&&k.editor.autop&&b.getParam("wpautop",!0);return j&&j(document).triggerHandler("tinymce-editor-setup",[b]),b.addButton("wp_adv",{tooltip:"Toolbar Toggle",cmd:"WP_Adv",onPostRender:function(){e=this,e.active("1"===getUserSetting("hidetb"))}}),b.on("PostRender",function(){b.getParam("wordpress_adv_hidden",!0)&&"0"===getUserSetting("hidetb","0")?c("hide"):a.$(".block-library-classic__toolbar").addClass("has-advanced-toolbar")}),b.addCommand("WP_Adv",function(){c()}),b.on("focus",function(){window.wpActiveEditor=b.id}),b.on("BeforeSetContent",function(b){var c;b.content&&(b.content.indexOf("/g,function(b,d){return''})),b.content.indexOf("")!==-1&&(c=i("Page break"),b.content=b.content.replace(//g,'')),b.load&&"raw"!==b.format&&(l?b.content=k.editor.autop(b.content):b.content=b.content.replace(/-->\s+"):a.indexOf('data-wp-more="nextpage"')!==-1?c="":a.indexOf("data-wp-preserve")!==-1&&(b=a.match(/ data-wp-preserve="([^"]+)"/))&&(c=decodeURIComponent(b[1])),c||a}))}),b.on("ResolveName",function(a){var c;"IMG"===a.target.nodeName&&(c=b.dom.getAttrib(a.target,"data-wp-more"))&&(a.name=c)}),b.addCommand("WP_More",function(c){var d,e,f,g="wp-more-tag",h=b.dom,j=b.selection.getNode(),k=b.getBody();return c=c||"more",g+=" mce-wp-"+c,f="more"===c?"Read more...":"Next page",f=i(f),e='',j===k||"P"===j.nodeName&&j.parentNode===k?void b.insertContent(e):(d=h.getParent(j,function(a){return!(!a.parentNode||a.parentNode!==k)},b.getBody()),void(d&&("P"===d.nodeName?d.appendChild(h.create("p",null,e).firstChild):h.insertAfter(h.create("p",null,e),d),b.nodeChanged())))}),b.addCommand("WP_Code",function(){b.formatter.toggle("code")}),b.addCommand("WP_Page",function(){b.execCommand("WP_More","nextpage")}),b.addCommand("WP_Help",function(){function c(a,b){var c="",d=0;for(b=b||1,h(a,function(a,b){c+=""+b+""+i(a)+"",d++});d",d++;return c+""}var d,e,f,g,j=i(a.Env.mac?"Ctrl + Alt + letter:":"Shift + Alt + letter:"),k=i(a.Env.mac?"Cmd + letter:":"Ctrl + letter:"),l=[],m=[],n={},o={},p=0,q=0,r=b.settings.wp_shortcut_labels;r&&(h(r,function(a,b){var d;a.indexOf("meta")!==-1?(p++,d=a.replace("meta","").toLowerCase(),d&&(n[d]=b,p%2===0&&(l.push(c(n,2)),n={}))):a.indexOf("access")!==-1&&(q++,d=a.replace("access","").toLowerCase(),d&&(o[d]=b,q%2===0&&(m.push(c(o,2)),o={})))}),p%2>0&&l.push(c(n,2)),q%2>0&&m.push(c(o,2)),d=[i("Letter"),i("Action"),i("Letter"),i("Action")],d=""+d.join("")+"",e='
',e=e+"

"+i("Default shortcuts,")+" "+k+'

'+d+l.join("")+"

"+i("Additional shortcuts,")+" "+j+'

'+d+m.join("")+"
",b.plugins.wptextpattern&&(!a.Env.ie||a.Env.ie>8)&&(e=e+"

"+i("When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.")+'

'+c({"*":"Bullet list","1.":"Numbered list"})+c({"-":"Bullet list","1)":"Numbered list"})+"
",e=e+"

"+i("The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.")+'

'+c({">":"Blockquote"})+c({"##":"Heading 2"})+c({"###":"Heading 3"})+c({"####":"Heading 4"})+c({"#####":"Heading 5"})+c({"######":"Heading 6"})+c({"---":"Horizontal line"})+"
"),e=e+"

"+i("Focus shortcuts:")+'

'+c({"Alt + F8":"Inline toolbar (when an image, link or preview is selected)"})+c({"Alt + F9":"Editor menu (when enabled)"})+c({"Alt + F10":"Editor toolbar"})+c({"Alt + F11":"Elements path"})+"

"+i("To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.")+"

",e+="
",f=b.windowManager.open({title:"Keyboard Shortcuts",items:{type:"container",classes:"wp-help",html:e},buttons:{text:"Close",onclick:"close"}}),f.$el&&(f.$el.find('div[role="application"]').attr("role","document"),g=f.$el.find(".mce-wp-help"),g[0]&&(g.attr("tabindex","0"),g[0].focus(),g.on("keydown",function(a){a.keyCode>=33&&a.keyCode<=40&&a.stopPropagation()}))))}),b.addCommand("WP_Medialib",function(){k&&k.media&&k.media.editor&&k.media.editor.open(b.id)}),b.addButton("wp_more",{tooltip:"Insert Read More tag",onclick:function(){b.execCommand("WP_More","more")}}),b.addButton("wp_page",{tooltip:"Page break",onclick:function(){b.execCommand("WP_More","nextpage")}}),b.addButton("wp_help",{tooltip:"Keyboard Shortcuts",cmd:"WP_Help"}),b.addButton("wp_code",{tooltip:"Code",cmd:"WP_Code",stateSelector:"code"}),k&&k.media&&k.media.editor&&(b.addButton("wp_add_media",{tooltip:"Add Media",icon:"dashicon dashicons-admin-media",cmd:"WP_Medialib"}),b.addMenuItem("add_media",{text:"Add Media",icon:"wp-media-library",context:"insert",cmd:"WP_Medialib"})),b.addMenuItem("wp_more",{text:"Insert Read More tag",icon:"wp_more",context:"insert",onclick:function(){b.execCommand("WP_More","more")}}),b.addMenuItem("wp_page",{text:"Page break",icon:"wp_page",context:"insert",onclick:function(){b.execCommand("WP_More","nextpage")}}),b.on("BeforeExecCommand",function(c){!a.Env.webkit||"InsertUnorderedList"!==c.command&&"InsertOrderedList"!==c.command||(f||(f=b.dom.create("style",{type:"text/css"},"#tinymce,#tinymce span,#tinymce li,#tinymce li>span,#tinymce p,#tinymce p>span{font:medium sans-serif;color:#000;line-height:normal;}")),b.getDoc().head.appendChild(f))}),b.on("ExecCommand",function(c){a.Env.webkit&&f&&("InsertUnorderedList"===c.command||"InsertOrderedList"===c.command)&&b.dom.remove(f)}),b.on("init",function(){var c=a.Env,d=["mceContentBody"],e=b.getDoc(),f=b.dom;if(c.iOS&&f.addClass(e.documentElement,"ios"),"rtl"===b.getParam("directionality")&&(d.push("rtl"),f.setAttrib(e.documentElement,"dir","rtl")),f.setAttrib(e.documentElement,"lang",b.getParam("wp_lang_attr")),c.ie?9===parseInt(c.ie,10)?d.push("ie9"):8===parseInt(c.ie,10)?d.push("ie8"):c.ie<8&&d.push("ie7"):c.webkit&&d.push("webkit"),d.push("wp-editor"),h(d,function(a){a&&f.addClass(e.body,a)}),b.on("BeforeSetContent",function(a){a.content&&(a.content=a.content.replace(/

\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi,"<$1$2>").replace(/<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi,""))}),j&&j(document).triggerHandler("tinymce-editor-init",[b]),window.tinyMCEPreInit&&window.tinyMCEPreInit.dragDropUpload&&f.bind(e,"dragstart dragend dragover drop",function(a){j&&j(document).trigger(new j.Event(a))}),b.getParam("wp_paste_filters",!0)&&(b.on("PastePreProcess",function(b){b.content=b.content.replace(/
/gi,""),a.Env.webkit||(b.content=b.content.replace(/(<[^>]+) style="[^"]*"([^>]*>)/gi,"$1$2"),b.content=b.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi,"$1 style=$2"))}),b.on("PastePostProcess",function(c){b.$("p",c.node).each(function(a,b){f.isEmpty(b)&&f.remove(b)}),a.isIE&&b.$("a",c.node).find("font, u").each(function(a,b){f.remove(b,!0)})})),b.settings.wp_shortcut_labels&&b.theme.panel){var g={},i="Shift+Alt+",k="Ctrl+";a.Env.mac&&(i="\u2303\u2325",k="\u2318"),h(b.settings.wp_shortcut_labels,function(a,b){g[b]=a.replace("access",i).replace("meta",k)}),h(b.theme.panel.find("button"),function(a){a&&a.settings.tooltip&&g.hasOwnProperty(a.settings.tooltip)&&(a.settings.tooltip=b.translate(a.settings.tooltip)+" ("+g[a.settings.tooltip]+")")}),h(b.theme.panel.find("listbox"),function(a){a&&"Paragraph"===a.settings.text&&h(a.settings.values,function(a){a.text&&g.hasOwnProperty(a.text)&&(a.shortcut="("+g[a.text]+")")})})}}),b.on("SaveContent",function(a){return!b.inline&&b.isHidden()?void(a.content=a.element.value):(a.content=a.content.replace(/

(?:
|\u00a0|\uFEFF| )*<\/p>/g,"

 

"),void(l?a.content=k.editor.removep(a.content):a.content=a.content.replace(/-->\s*\n\n/g,function(b,d){return''})),b.content.indexOf("")!==-1&&(c=i("Page break"),b.content=b.content.replace(//g,'')),b.load&&"raw"!==b.format&&(l?b.content=k.editor.autop(b.content):b.content=b.content.replace(/-->\s+"):a.indexOf('data-wp-more="nextpage"')!==-1?c="":a.indexOf("data-wp-preserve")!==-1&&(b=a.match(/ data-wp-preserve="([^"]+)"/))&&(c=decodeURIComponent(b[1])),c||a}))}),b.on("ResolveName",function(a){var c;"IMG"===a.target.nodeName&&(c=b.dom.getAttrib(a.target,"data-wp-more"))&&(a.name=c)}),b.addCommand("WP_More",function(c){var d,e,f,g="wp-more-tag",h=b.dom,j=b.selection.getNode(),k=b.getBody();return c=c||"more",g+=" mce-wp-"+c,f="more"===c?"Read more...":"Next page",f=i(f),e='',j===k||"P"===j.nodeName&&j.parentNode===k?void b.insertContent(e):(d=h.getParent(j,function(a){return!(!a.parentNode||a.parentNode!==k)},b.getBody()),void(d&&("P"===d.nodeName?d.appendChild(h.create("p",null,e).firstChild):h.insertAfter(h.create("p",null,e),d),b.nodeChanged())))}),b.addCommand("WP_Code",function(){b.formatter.toggle("code")}),b.addCommand("WP_Page",function(){b.execCommand("WP_More","nextpage")}),b.addCommand("WP_Help",function(){function c(a,b){var c="",d=0;for(b=b||1,h(a,function(a,b){c+=""+b+""+i(a)+"",d++});d",d++;return c+""}var d,e,f,g,j=i(a.Env.mac?"Ctrl + Alt + letter:":"Shift + Alt + letter:"),k=i(a.Env.mac?"Cmd + letter:":"Ctrl + letter:"),l=[],m=[],n={},o={},p=0,q=0,r=b.settings.wp_shortcut_labels;r&&(h(r,function(a,b){var d;a.indexOf("meta")!==-1?(p++,d=a.replace("meta","").toLowerCase(),d&&(n[d]=b,p%2===0&&(l.push(c(n,2)),n={}))):a.indexOf("access")!==-1&&(q++,d=a.replace("access","").toLowerCase(),d&&(o[d]=b,q%2===0&&(m.push(c(o,2)),o={})))}),p%2>0&&l.push(c(n,2)),q%2>0&&m.push(c(o,2)),d=[i("Letter"),i("Action"),i("Letter"),i("Action")],d=""+d.join("")+"",e='
',e=e+"

"+i("Default shortcuts,")+" "+k+'

'+d+l.join("")+"

"+i("Additional shortcuts,")+" "+j+'

'+d+m.join("")+"
",b.plugins.wptextpattern&&(!a.Env.ie||a.Env.ie>8)&&(e=e+"

"+i("When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.")+'

'+c({"*":"Bullet list","1.":"Numbered list"})+c({"-":"Bullet list","1)":"Numbered list"})+"
",e=e+"

"+i("The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.")+'

'+c({">":"Blockquote"})+c({"##":"Heading 2"})+c({"###":"Heading 3"})+c({"####":"Heading 4"})+c({"#####":"Heading 5"})+c({"######":"Heading 6"})+c({"---":"Horizontal line"})+"
"),e=e+"

"+i("Focus shortcuts:")+'

'+c({"Alt + F8":"Inline toolbar (when an image, link or preview is selected)"})+c({"Alt + F9":"Editor menu (when enabled)"})+c({"Alt + F10":"Editor toolbar"})+c({"Alt + F11":"Elements path"})+"

"+i("To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.")+"

",e+="
",f=b.windowManager.open({title:b.settings.classic_block_editor?"Classic Block Keyboard Shortcuts":"Keyboard Shortcuts",items:{type:"container",classes:"wp-help",html:e},buttons:{text:"Close",onclick:"close"}}),f.$el&&(f.$el.find('div[role="application"]').attr("role","document"),g=f.$el.find(".mce-wp-help"),g[0]&&(g.attr("tabindex","0"),g[0].focus(),g.on("keydown",function(a){a.keyCode>=33&&a.keyCode<=40&&a.stopPropagation()}))))}),b.addCommand("WP_Medialib",function(){k&&k.media&&k.media.editor&&k.media.editor.open(b.id)}),b.addButton("wp_more",{tooltip:"Insert Read More tag",onclick:function(){b.execCommand("WP_More","more")}}),b.addButton("wp_page",{tooltip:"Page break",onclick:function(){b.execCommand("WP_More","nextpage")}}),b.addButton("wp_help",{tooltip:"Keyboard Shortcuts",cmd:"WP_Help"}),b.addButton("wp_code",{tooltip:"Code",cmd:"WP_Code",stateSelector:"code"}),k&&k.media&&k.media.editor&&(b.addButton("wp_add_media",{tooltip:"Add Media",icon:"dashicon dashicons-admin-media",cmd:"WP_Medialib"}),b.addMenuItem("add_media",{text:"Add Media",icon:"wp-media-library",context:"insert",cmd:"WP_Medialib"})),b.addMenuItem("wp_more",{text:"Insert Read More tag",icon:"wp_more",context:"insert",onclick:function(){b.execCommand("WP_More","more")}}),b.addMenuItem("wp_page",{text:"Page break",icon:"wp_page",context:"insert",onclick:function(){b.execCommand("WP_More","nextpage")}}),b.on("BeforeExecCommand",function(c){!a.Env.webkit||"InsertUnorderedList"!==c.command&&"InsertOrderedList"!==c.command||(f||(f=b.dom.create("style",{type:"text/css"},"#tinymce,#tinymce span,#tinymce li,#tinymce li>span,#tinymce p,#tinymce p>span{font:medium sans-serif;color:#000;line-height:normal;}")),b.getDoc().head.appendChild(f))}),b.on("ExecCommand",function(c){a.Env.webkit&&f&&("InsertUnorderedList"===c.command||"InsertOrderedList"===c.command)&&b.dom.remove(f)}),b.on("init",function(){var c=a.Env,d=["mceContentBody"],e=b.getDoc(),f=b.dom;if(c.iOS&&f.addClass(e.documentElement,"ios"),"rtl"===b.getParam("directionality")&&(d.push("rtl"),f.setAttrib(e.documentElement,"dir","rtl")),f.setAttrib(e.documentElement,"lang",b.getParam("wp_lang_attr")),c.ie?9===parseInt(c.ie,10)?d.push("ie9"):8===parseInt(c.ie,10)?d.push("ie8"):c.ie<8&&d.push("ie7"):c.webkit&&d.push("webkit"),d.push("wp-editor"),h(d,function(a){a&&f.addClass(e.body,a)}),b.on("BeforeSetContent",function(a){a.content&&(a.content=a.content.replace(/

\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi,"<$1$2>").replace(/<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi,""))}),j&&j(document).triggerHandler("tinymce-editor-init",[b]),window.tinyMCEPreInit&&window.tinyMCEPreInit.dragDropUpload&&f.bind(e,"dragstart dragend dragover drop",function(a){j&&j(document).trigger(new j.Event(a))}),b.getParam("wp_paste_filters",!0)&&(b.on("PastePreProcess",function(b){b.content=b.content.replace(/
/gi,""),a.Env.webkit||(b.content=b.content.replace(/(<[^>]+) style="[^"]*"([^>]*>)/gi,"$1$2"),b.content=b.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi,"$1 style=$2"))}),b.on("PastePostProcess",function(c){b.$("p",c.node).each(function(a,b){f.isEmpty(b)&&f.remove(b)}),a.isIE&&b.$("a",c.node).find("font, u").each(function(a,b){f.remove(b,!0)})})),b.settings.wp_shortcut_labels&&b.theme.panel){var g={},i="Shift+Alt+",k="Ctrl+";a.Env.mac&&(i="\u2303\u2325",k="\u2318"),h(b.settings.wp_shortcut_labels,function(a,b){g[b]=a.replace("access",i).replace("meta",k)}),h(b.theme.panel.find("button"),function(a){a&&a.settings.tooltip&&g.hasOwnProperty(a.settings.tooltip)&&(a.settings.tooltip=b.translate(a.settings.tooltip)+" ("+g[a.settings.tooltip]+")")}),h(b.theme.panel.find("listbox"),function(a){a&&"Paragraph"===a.settings.text&&h(a.settings.values,function(a){a.text&&g.hasOwnProperty(a.text)&&(a.shortcut="("+g[a.text]+")")})})}}),b.on("SaveContent",function(a){return!b.inline&&b.isHidden()?void(a.content=a.element.value):(a.content=a.content.replace(/

(?:
|\u00a0|\uFEFF| )*<\/p>/g,"

 

"),void(l?a.content=k.editor.removep(a.content):a.content=a.content.replace(/-->\s*\n\n