From 3e605d3852ce0f746bc50af12af8aaaf1e091f0a Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 13 Aug 2019 21:26:56 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@45790 git-svn-id: http://core.svn.wordpress.org/trunk@45601 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/comment-reply.js | 12 ++++++++++++ wp-includes/js/comment-reply.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/wp-includes/js/comment-reply.js b/wp-includes/js/comment-reply.js index a82fc03c87..be54c350d3 100644 --- a/wp-includes/js/comment-reply.js +++ b/wp-includes/js/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; diff --git a/wp-includes/js/comment-reply.min.js b/wp-includes/js/comment-reply.min.js index eedf334d2e..7708a7794e 100644 --- a/wp-includes/js/comment-reply.min.js +++ b/wp-includes/js/comment-reply.min.js @@ -1 +1 @@ -window.addComment=function(a){function b(){c(),g()}function c(a){if(t&&(m=j(r.cancelReplyId),n=j(r.commentFormId),m)){m.addEventListener("touchstart",e),m.addEventListener("click",e);for(var b,c=d(a),g=0,h=c.length;g