From 92a1067f1defbfdf15262d00a269ffecf41d5879 Mon Sep 17 00:00:00 2001 From: davidbaumwald Date: Fri, 18 Mar 2022 18:14:02 +0000 Subject: [PATCH] Comments: Disable "close on escape" for inline replies when using an IME. When using an Input Method Editor(IME), pressing escape to perform actions in the IME is common. However, if this was done while replying to a comment, the "close on escape" feature was also triggered which cleared the current textarea and closed it. This change checks if an IME is in use by binding the `compositionstart` event to the reply text box and setting a flag if it's triggered. The "close on escape" feature will now only be triggered if this new flag is not set after typing a reply. Props BettyJJ, sabernhardt, alexstine, konradyoast, audrasjb, rafiahmedd, afercia. Fixes #54548. Built from https://develop.svn.wordpress.org/trunk@52951 git-svn-id: http://core.svn.wordpress.org/trunk@52540 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/edit-comments.js | 18 +++++++++++++----- wp-admin/js/edit-comments.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/wp-admin/js/edit-comments.js b/wp-admin/js/edit-comments.js index 96ca1f9f48..1d56e7c843 100644 --- a/wp-admin/js/edit-comments.js +++ b/wp-admin/js/edit-comments.js @@ -1019,7 +1019,8 @@ window.commentReply = { } setTimeout(function() { - var rtop, rbottom, scrollTop, vp, scrollBottom; + var rtop, rbottom, scrollTop, vp, scrollBottom, + isComposing = false; rtop = $('#replyrow').offset().top; rbottom = rtop + $('#replyrow').height(); @@ -1032,10 +1033,17 @@ window.commentReply = { else if ( rtop - 20 < scrollTop ) window.scroll(0, rtop - 35); - $('#replycontent').trigger( 'focus' ).on( 'keyup', function(e){ - if ( e.which == 27 ) - commentReply.revert(); // Close on Escape. - }); + $( '#replycontent' ) + .trigger( 'focus' ) + .on( 'keyup', function( e ) { + // Close on Escape except when Input Method Editors (IMEs) are in use. + if ( e.which === 27 && ! isComposing ) { + commentReply.revert(); + } + } ) + .on( 'compositionstart', function() { + isComposing = true; + } ); }, 600); return false; diff --git a/wp-admin/js/edit-comments.min.js b/wp-admin/js/edit-comments.min.js index 9f2b049a9e..ca01a49e5b 100644 --- a/wp-admin/js/edit-comments.min.js +++ b/wp-admin/js/edit-comments.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -!function(w){var o,s,i=document.title,C=w("#dashboard_right_now").length,c=wp.i18n.__,x=function(t){t=parseInt(t.html().replace(/[^0-9]+/g,""),10);return isNaN(t)?0:t},r=function(t,e){var n="";if(!isNaN(e)){if(3<(e=e<1?"0":e.toString()).length){for(;3"),e=i,1<=(t=(a=s.exec(document.title))?(a=a[0],o.html(a),x(o)+t):(o.html(0),t))?(r(o,t),(n=s.exec(document.title))&&(e=document.title.replace(n[0],c("Comments (%s)").replace("%s",o.text())+" "))):(n=s.exec(e))&&(e=e.replace(n[0],c("Comments"))),document.title=e},I=function(n,t){var e=".post-com-count-"+t,a="comment-count-no-pending",o="post-com-count-no-pending",s="comment-count-pending";C||l(n),w("span.pending-count").each(function(){var t=w(this),e=x(t)+n;e<1&&(e=0),t.closest(".awaiting-mod")[0===e?"addClass":"removeClass"]("count-0"),r(t,e)}),t&&(t=w("span."+s,e),e=w("span."+a,e),t.each(function(){var t=w(this),e=x(t)+n;0===(e=e<1?0:e)?(t.parent().addClass(o),t.removeClass(s).addClass(a)):(t.parent().removeClass(o),t.addClass(s).removeClass(a)),r(t,e)}),e.each(function(){var t=w(this);0