Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments: Prevent comment revert when context menu is open when Escape key gets pressed. #7786

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading