From 1a10ec0c3c6d2991d11fa474c00e902790fb85ba Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Wed, 13 Nov 2024 14:12:02 +0530 Subject: [PATCH 1/2] Comments: Prevent comment revert when context menu is open --- src/js/_enqueues/admin/edit-comments.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/js/_enqueues/admin/edit-comments.js b/src/js/_enqueues/admin/edit-comments.js index e007edf465c6f..b596f6f3023df 100644 --- a/src/js/_enqueues/admin/edit-comments.js +++ b/src/js/_enqueues/admin/edit-comments.js @@ -1021,6 +1021,7 @@ window.commentReply = { setTimeout(function() { var rtop, rbottom, scrollTop, vp, scrollBottom, isComposing = false; + var isContextMenuOpen = false; rtop = $('#replyrow').offset().top; rbottom = rtop + $('#replyrow').height(); @@ -1035,9 +1036,20 @@ window.commentReply = { $( '#replycontent' ) .trigger( 'focus' ) + .on( 'contextmenu keydown', function ( e ) { + // Don't revert the comment if the context menu is open and the Escape key is pressed. + if ( e.type === 'contextmenu' ) { + isContextMenuOpen = true; + } + + // Update the context menu state when 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 except when Input Method Editors (IMEs) are in use or the context menu is open. + if ( e.which === 27 && ! isComposing && ! isContextMenuOpen ) { commentReply.revert(); } } ) From eb19e788a41b66667d1cccc546930d19afb250ca Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Fri, 13 Dec 2024 18:55:38 -0600 Subject: [PATCH 2/2] Move isContextMenuOpen var declaration into list declaration, update comments. --- src/js/_enqueues/admin/edit-comments.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/js/_enqueues/admin/edit-comments.js b/src/js/_enqueues/admin/edit-comments.js index b596f6f3023df..9a3d81a751bd8 100644 --- a/src/js/_enqueues/admin/edit-comments.js +++ b/src/js/_enqueues/admin/edit-comments.js @@ -1020,8 +1020,8 @@ window.commentReply = { setTimeout(function() { var rtop, rbottom, scrollTop, vp, scrollBottom, - isComposing = false; - var isContextMenuOpen = false; + isComposing = false, + isContextMenuOpen = false; rtop = $('#replyrow').offset().top; rbottom = rtop + $('#replyrow').height(); @@ -1037,18 +1037,18 @@ window.commentReply = { $( '#replycontent' ) .trigger( 'focus' ) .on( 'contextmenu keydown', function ( e ) { - // Don't revert the comment if the context menu is open and the Escape key is pressed. + // Check if the context menu is open and set state. if ( e.type === 'contextmenu' ) { isContextMenuOpen = true; } - // Update the context menu state when the Escape key is pressed. + // 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 or the context menu is open. + // 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(); }