Skip to content

Commit

Permalink
Comments: Avoid reverting comment reply when context menu is open.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joedolson committed Dec 14, 2024
1 parent 1cc1af2 commit b03c9f5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/js/_enqueues/admin/edit-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
} )
Expand Down

0 comments on commit b03c9f5

Please sign in to comment.