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.

git-svn-id: https://develop.svn.wordpress.org/trunk@58981 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Dolson 2024-09-03 20:34:35 +00:00
parent c5a5c20445
commit 583bbce947

View File

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