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
This commit is contained in:
Adam Silverstein 2019-08-13 21:25:57 +00:00
parent 9a20a07304
commit 98255d4720
1 changed files with 12 additions and 0 deletions

View File

@ -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;