Skip to content
Permalink
Browse files

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.



git-svn-id: https://develop.svn.wordpress.org/trunk@45790 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
adamsilverstein committed Aug 13, 2019
1 parent 9a20a07 commit 98255d47207c4c37b7aecabb42360056029ac037
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/js/_enqueues/lib/comment-reply.js
@@ -95,6 +95,18 @@ window.addComment = ( function( window ) {
cancelElement.addEventListener( 'touchstart', cancelEvent );
cancelElement.addEventListener( 'click', cancelEvent );

// Submit the comment form when the user types CTRL or CMD + 'Enter'.
var submitFormHandler = function( e ) {
if ( ( e.metaKey || e.ctrlKey ) && e.keyCode === 13 ) {
commentFormElement.removeEventListener( 'keydown', submitFormHandler );
e.preventDefault();
// The submit button ID is 'submit' so we can't call commentFormElement.submit(). Click it instead.
commentFormElement.submit.click();
return false;
}
}
commentFormElement.addEventListener( 'keydown', submitFormHandler );

var links = replyLinks( context );
var element;

0 comments on commit 98255d4

Please sign in to comment.
You can’t perform that action at this time.