Skip to content

Commit ef8209a

Browse files
GiteaBotHesterG
andauthored
Use async await to fix empty quote reply at first time (#23168) (#23256)
Backport #23168 The reason why quote reply is empty is when quote reply is clicked, it triggers the click function on `.comment-form-reply` button, and when the first time this function is triggered, easyMDE for the reply has not yet initialized, so that click handler of `.quote-reply` button in `repo-legacy.js` got an `undefined` as easyMDE, and the following lines which put quoted reply into the easyMDE is not executed. The workaround in this PR is to pass the replied content to '.comment-form-reply' button if easyMDE is not yet initialized (quote reply first clicked) and put the replied content into it the after easyMDE is created. Now quote reply on first click: https://user-images.githubusercontent.com/17645053/221452823-fc699d50-1649-4af1-952e-f04fc8d2978e.mov <br /> Update: The above change is not appropriate as stated in the [comment](#23168 (comment)) Use await instead Close #22075. Close #23247. Co-authored-by: HesterG <[email protected]>
1 parent 9309098 commit ef8209a

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

web_src/js/features/repo-issue.js

+17-13
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,22 @@ function assignMenuAttributes(menu) {
418418
return id;
419419
}
420420

421+
export async function handleReply($el) {
422+
hideElem($el);
423+
const form = $el.closest('.comment-code-cloud').find('.comment-form');
424+
form.removeClass('gt-hidden');
425+
const $textarea = form.find('textarea');
426+
let easyMDE = getAttachedEasyMDE($textarea);
427+
if (!easyMDE) {
428+
await attachTribute($textarea.get(), {mentions: true, emoji: true});
429+
easyMDE = await createCommentEasyMDE($textarea);
430+
}
431+
$textarea.focus();
432+
easyMDE.codemirror.focus();
433+
assignMenuAttributes(form.find('.menu'));
434+
return easyMDE;
435+
}
436+
421437
export function initRepoPullRequestReview() {
422438
if (window.location.hash && window.location.hash.startsWith('#issuecomment-')) {
423439
const commentDiv = $(window.location.hash);
@@ -455,19 +471,7 @@ export function initRepoPullRequestReview() {
455471

456472
$(document).on('click', 'button.comment-form-reply', async function (e) {
457473
e.preventDefault();
458-
459-
hideElem($(this));
460-
const form = $(this).closest('.comment-code-cloud').find('.comment-form');
461-
form.removeClass('gt-hidden');
462-
const $textarea = form.find('textarea');
463-
let easyMDE = getAttachedEasyMDE($textarea);
464-
if (!easyMDE) {
465-
await attachTribute($textarea.get(), {mentions: true, emoji: true});
466-
easyMDE = await createCommentEasyMDE($textarea);
467-
}
468-
$textarea.focus();
469-
easyMDE.codemirror.focus();
470-
assignMenuAttributes(form.find('.menu'));
474+
await handleReply($(this));
471475
});
472476

473477
const $reviewBox = $('.review-box-panel');

web_src/js/features/repo-legacy.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
initRepoIssueBranchSelect, initRepoIssueCodeCommentCancel, initRepoIssueCommentDelete,
77
initRepoIssueComments, initRepoIssueDependencyDelete, initRepoIssueReferenceIssue,
88
initRepoIssueStatusButton, initRepoIssueTitleEdit, initRepoIssueWipToggle,
9-
initRepoPullRequestUpdate, updateIssuesMeta,
9+
initRepoPullRequestUpdate, updateIssuesMeta, handleReply
1010
} from './repo-issue.js';
1111
import {initUnicodeEscapeButton} from './repo-unicode-escape.js';
1212
import {svg} from '../svg.js';
@@ -613,15 +613,15 @@ function initRepoIssueCommentEdit() {
613613
$(document).on('click', '.edit-content', onEditContent);
614614

615615
// Quote reply
616-
$(document).on('click', '.quote-reply', function (event) {
616+
$(document).on('click', '.quote-reply', async function (event) {
617+
event.preventDefault();
617618
const target = $(this).data('target');
618619
const quote = $(`#${target}`).text().replace(/\n/g, '\n> ');
619620
const content = `> ${quote}\n\n`;
620621
let easyMDE;
621622
if ($(this).hasClass('quote-reply-diff')) {
622-
const $parent = $(this).closest('.comment-code-cloud');
623-
$parent.find('button.comment-form-reply').trigger('click');
624-
easyMDE = getAttachedEasyMDE($parent.find('[name="content"]'));
623+
const $replyBtn = $(this).closest('.comment-code-cloud').find('button.comment-form-reply');
624+
easyMDE = await handleReply($replyBtn);
625625
} else {
626626
// for normal issue/comment page
627627
easyMDE = getAttachedEasyMDE($('#comment-form .edit_area'));
@@ -637,6 +637,5 @@ function initRepoIssueCommentEdit() {
637637
easyMDE.codemirror.setCursor(easyMDE.codemirror.lineCount(), 0);
638638
});
639639
}
640-
event.preventDefault();
641640
});
642641
}

0 commit comments

Comments
 (0)