Make WordPress Core

Changeset 59514


Ignore:
Timestamp:
12/14/2024 01:30:07 AM (21 months ago)
Author:
joedolson
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/edit-comments.js

    r58931 r59514  
    10211021                setTimeout(function() {
    10221022                        var rtop, rbottom, scrollTop, vp, scrollBottom,
    1023                                 isComposing = false;
     1023                                isComposing = false,
     1024                                isContextMenuOpen = false;
    10241025
    10251026                        rtop = $('#replyrow').offset().top;
     
    10361037                        $( '#replycontent' )
    10371038                                .trigger( 'focus' )
     1039                                .on( 'contextmenu keydown', function ( e ) {
     1040                                        // Check if the context menu is open and set state.
     1041                                        if ( e.type === 'contextmenu' ) {
     1042                                                isContextMenuOpen = true;
     1043                                        }
     1044
     1045                                        // Update the context menu state if the Escape key is pressed.
     1046                                        if ( e.type === 'keydown' && e.which === 27 && isContextMenuOpen ) {
     1047                                                isContextMenuOpen = false;
     1048                                        }
     1049                                } )
    10381050                                .on( 'keyup', function( e ) {
    1039                                         // Close on Escape except when Input Method Editors (IMEs) are in use.
    1040                                         if ( e.which === 27 && ! isComposing ) {
     1051                                        // Close on Escape unless Input Method Editors (IMEs) are in use or the context menu is open.
     1052                                        if ( e.which === 27 && ! isComposing && ! isContextMenuOpen ) {
    10411053                                                commentReply.revert();
    10421054                                        }
Note: See TracChangeset for help on using the changeset viewer.