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
This commit is contained in:
David Baumwald
2022-03-18 18:12:47 +00:00
parent c7edd7fff9
commit 26b266ad44
+13 -5
View File
@@ -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;