Skip to content

Commit b03c9f5

Browse files
committed
Comments: Avoid reverting comment reply when context menu is open.
Fix a bug where a comment reply would be discarded if `esc` was pressed to dismiss the context menu in Safari or Firefox. Checks whether the contextmenu is open and ignores the `esc` key if it is. Props yellowafterlife, yogeshbhutkar, joedolson. Fixes #62346. git-svn-id: https://develop.svn.wordpress.org/trunk@59514 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1cc1af2 commit b03c9f5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/js/_enqueues/admin/edit-comments.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,8 @@ window.commentReply = {
10201020

10211021
setTimeout(function() {
10221022
var rtop, rbottom, scrollTop, vp, scrollBottom,
1023-
isComposing = false;
1023+
isComposing = false,
1024+
isContextMenuOpen = false;
10241025

10251026
rtop = $('#replyrow').offset().top;
10261027
rbottom = rtop + $('#replyrow').height();
@@ -1035,9 +1036,20 @@ window.commentReply = {
10351036

10361037
$( '#replycontent' )
10371038
.trigger( 'focus' )
1039+
.on( 'contextmenu keydown', function ( e ) {
1040+
// Check if the context menu is open and set state.
1041+
if ( e.type === 'contextmenu' ) {
1042+
isContextMenuOpen = true;
1043+
}
1044+
1045+
// Update the context menu state if the Escape key is pressed.
1046+
if ( e.type === 'keydown' && e.which === 27 && isContextMenuOpen ) {
1047+
isContextMenuOpen = false;
1048+
}
1049+
} )
10381050
.on( 'keyup', function( e ) {
1039-
// Close on Escape except when Input Method Editors (IMEs) are in use.
1040-
if ( e.which === 27 && ! isComposing ) {
1051+
// Close on Escape unless Input Method Editors (IMEs) are in use or the context menu is open.
1052+
if ( e.which === 27 && ! isComposing && ! isContextMenuOpen ) {
10411053
commentReply.revert();
10421054
}
10431055
} )

0 commit comments

Comments
 (0)