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.
Built from https://develop.svn.wordpress.org/trunk@59514


git-svn-id: http://core.svn.wordpress.org/trunk@58900 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2024-12-14 01:32:18 +00:00
parent 880bce2ad5
commit cc3c3bf4e6
3 changed files with 17 additions and 5 deletions

View File

@ -1020,7 +1020,8 @@ window.commentReply = {
setTimeout(function() { setTimeout(function() {
var rtop, rbottom, scrollTop, vp, scrollBottom, var rtop, rbottom, scrollTop, vp, scrollBottom,
isComposing = false; isComposing = false,
isContextMenuOpen = false;
rtop = $('#replyrow').offset().top; rtop = $('#replyrow').offset().top;
rbottom = rtop + $('#replyrow').height(); rbottom = rtop + $('#replyrow').height();
@ -1035,9 +1036,20 @@ window.commentReply = {
$( '#replycontent' ) $( '#replycontent' )
.trigger( 'focus' ) .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 ) { .on( 'keyup', function( e ) {
// Close on Escape except when Input Method Editors (IMEs) are in use. // Close on Escape unless Input Method Editors (IMEs) are in use or the context menu is open.
if ( e.which === 27 && ! isComposing ) { if ( e.which === 27 && ! isComposing && ! isContextMenuOpen ) {
commentReply.revert(); commentReply.revert();
} }
} ) } )

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.8-alpha-59513'; $wp_version = '6.8-alpha-59514';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.