WordPress.org

Make WordPress Core

Changeset 45790


Ignore:
Timestamp:
08/13/2019 09:25:57 PM (4 months ago)
Author:
adamsilverstein
Message:

Comments: enable typing cmd/ctrl-enter to submit comment forms.

Add a key handler on the comment form that detects the cmd/ctrl-enter key press and submits the comment form.

Props xyfi, Lindstromer, helen, splitti.
Fixes #41545.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/comment-reply.js

    r45641 r45790  
    9696        cancelElement.addEventListener( 'click',      cancelEvent );
    9797
     98        // Submit the comment form when the user types CTRL or CMD + 'Enter'.
     99        var submitFormHandler = function( e ) {
     100            if ( ( e.metaKey || e.ctrlKey ) && e.keyCode === 13 ) {
     101                commentFormElement.removeEventListener( 'keydown', submitFormHandler );
     102                e.preventDefault();
     103                // The submit button ID is 'submit' so we can't call commentFormElement.submit(). Click it instead.
     104                commentFormElement.submit.click();
     105                return false;
     106            }
     107        }
     108        commentFormElement.addEventListener( 'keydown', submitFormHandler );
     109
    98110        var links = replyLinks( context );
    99111        var element;
Note: See TracChangeset for help on using the changeset viewer.