From f04589defd6a06a17ebaeb6072d493c5b6210304 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sat, 17 Feb 2024 12:52:11 +0100 Subject: [PATCH] [BUG] Fix Ctrl+Enter on submitting review comment - When a event is caused by `Ctrl+Enter` jQuery might not wrap the event and in that case `originalEvent` is not defined. Check for this case. - Log the error along with showing an toast. - Resolves #2363 --- web_src/js/features/repo-diff.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/repo-diff.js b/web_src/js/features/repo-diff.js index eeb80e91b2..04dd153df2 100644 --- a/web_src/js/features/repo-diff.js +++ b/web_src/js/features/repo-diff.js @@ -57,8 +57,10 @@ function initRepoDiffConversationForm() { $form.addClass('is-loading'); const formData = new FormData($form[0]); - // if the form is submitted by a button, append the button's name and value to the form data - const submitter = submitEventSubmitter(e.originalEvent); + // If the form is submitted by a button, append the button's name and value to the form data. + // originalEvent can be undefined, such as an event that's caused by Ctrl+Enter, in that case + // sent the event itself. + const submitter = submitEventSubmitter(e.originalEvent ?? e); const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit'); if (isSubmittedByButton && submitter.name) { formData.append(submitter.name, submitter.value); @@ -76,6 +78,7 @@ function initRepoDiffConversationForm() { $newConversationHolder.find('.dropdown').dropdown(); initCompReactionSelector($newConversationHolder); } catch { // here the caught error might be a jQuery AJAX error (thrown by await $.post), which is not good to use for error message handling + console.error('error when submitting conversation', e); showErrorToast(i18n.network_error); } finally { $form.removeClass('is-loading');