From 02d2fa959ab289de5a50a5545fa77282b5844747 Mon Sep 17 00:00:00 2001 From: joedolson Date: Tue, 3 Sep 2024 20:36:10 +0000 Subject: [PATCH] Comments: Limit comments shortcut to not execute on links. Exclude links from activating the comment submission shortcut. [45790] introduced a shortcut to submit comment forms using `Ctrl/Cmd + Enter`. This keyboard combination is also the combination for opening a link in a new tab, which resulted in submitting the form when using the Log Out or Edit Profile links. Props greentreefrog, sabernhardt, narenin. Fixes #61919. Built from https://develop.svn.wordpress.org/trunk@58981 git-svn-id: http://core.svn.wordpress.org/trunk@58377 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/comment-reply.js | 2 +- wp-includes/js/comment-reply.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wp-includes/js/comment-reply.js b/wp-includes/js/comment-reply.js index 59cf5a1aa0..b916dc54d1 100644 --- a/wp-includes/js/comment-reply.js +++ b/wp-includes/js/comment-reply.js @@ -98,7 +98,7 @@ window.addComment = ( function( window ) { // Submit the comment form when the user types [Ctrl] or [Cmd] + [Enter]. var submitFormHandler = function( e ) { - if ( ( e.metaKey || e.ctrlKey ) && e.keyCode === 13 ) { + if ( ( e.metaKey || e.ctrlKey ) && e.keyCode === 13 && document.activeElement.tagName.toLowerCase() !== 'a' ) { commentFormElement.removeEventListener( 'keydown', submitFormHandler ); e.preventDefault(); // The submit button ID is 'submit' so we can't call commentFormElement.submit(). Click it instead. diff --git a/wp-includes/js/comment-reply.min.js b/wp-includes/js/comment-reply.min.js index ff42ec63ff..bd6017af4f 100644 --- a/wp-includes/js/comment-reply.min.js +++ b/wp-includes/js/comment-reply.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -window.addComment=function(v){var I,C,h,E=v.document,b={commentReplyClass:"comment-reply-link",commentReplyTitleId:"reply-title",cancelReplyId:"cancel-comment-reply-link",commentFormId:"commentform",temporaryFormId:"wp-temp-form-div",parentIdFieldId:"comment_parent",postIdFieldId:"comment_post_ID"},e=v.MutationObserver||v.WebKitMutationObserver||v.MozMutationObserver,r="querySelector"in E&&"addEventListener"in v,n=!!E.documentElement.dataset;function t(){d(),e&&new e(o).observe(E.body,{childList:!0,subtree:!0})}function d(e){if(r&&(I=g(b.cancelReplyId),C=g(b.commentFormId),I)){I.addEventListener("touchstart",l),I.addEventListener("click",l);function t(e){if((e.metaKey||e.ctrlKey)&&13===e.keyCode)return C.removeEventListener("keydown",t),e.preventDefault(),C.submit.click(),!1}C&&C.addEventListener("keydown",t);for(var n,d=function(e){var t=b.commentReplyClass;e&&e.childNodes||(e=E);e=E.getElementsByClassName?e.getElementsByClassName(t):e.querySelectorAll("."+t);return e}(e),o=0,i=d.length;o