From 26b266ad4450a20a36a81e1575f2fd26fe852ba5 Mon Sep 17 00:00:00 2001 From: David Baumwald Date: Fri, 18 Mar 2022 18:12:47 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@52951 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/admin/edit-comments.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/js/_enqueues/admin/edit-comments.js b/src/js/_enqueues/admin/edit-comments.js index 96ca1f9f48..1d56e7c843 100644 --- a/src/js/_enqueues/admin/edit-comments.js +++ b/src/js/_enqueues/admin/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;