From b03c9f531d017aa5e15eceeb2534097851e30707 Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Sat, 14 Dec 2024 01:30:07 +0000 Subject: [PATCH] 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 --- src/js/_enqueues/admin/edit-comments.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/js/_enqueues/admin/edit-comments.js b/src/js/_enqueues/admin/edit-comments.js index e007edf465c6f..9a3d81a751bd8 100644 --- a/src/js/_enqueues/admin/edit-comments.js +++ b/src/js/_enqueues/admin/edit-comments.js @@ -1020,7 +1020,8 @@ window.commentReply = { setTimeout(function() { var rtop, rbottom, scrollTop, vp, scrollBottom, - isComposing = false; + isComposing = false, + isContextMenuOpen = false; rtop = $('#replyrow').offset().top; rbottom = rtop + $('#replyrow').height(); @@ -1035,9 +1036,20 @@ window.commentReply = { $( '#replycontent' ) .trigger( 'focus' ) + .on( 'contextmenu keydown', function ( e ) { + // Check if the context menu is open and set state. + if ( e.type === 'contextmenu' ) { + isContextMenuOpen = true; + } + + // Update the context menu state if the Escape key is pressed. + if ( e.type === 'keydown' && e.which === 27 && isContextMenuOpen ) { + isContextMenuOpen = false; + } + } ) .on( 'keyup', function( e ) { - // Close on Escape except when Input Method Editors (IMEs) are in use. - if ( e.which === 27 && ! isComposing ) { + // Close on Escape unless Input Method Editors (IMEs) are in use or the context menu is open. + if ( e.which === 27 && ! isComposing && ! isContextMenuOpen ) { commentReply.revert(); } } )