Skip to content

Commit f9467ae

Browse files
committed
Use async await to fix empty quote reply at first time (go-gitea#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](go-gitea#23168 (comment)) Use await instead Close go-gitea#22075. Close go-gitea#23247.
1 parent 0c212b3 commit f9467ae

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

web_src/js/features/repo-issue.js

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

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

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

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

web_src/js/features/repo-legacy.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
initRepoIssueReferenceIssue, initRepoIssueStatusButton,
1010
initRepoIssueTitleEdit,
1111
initRepoIssueWipToggle, initRepoPullRequestUpdate,
12-
updateIssuesMeta,
12+
updateIssuesMeta, handleReply
1313
} from './repo-issue.js';
1414
import {initUnicodeEscapeButton} from './repo-unicode-escape.js';
1515
import {svg} from '../svg.js';
@@ -567,16 +567,15 @@ function initRepoIssueCommentEdit() {
567567
$(document).on('click', '.edit-content', onEditContent);
568568

569569
// Quote reply
570-
$(document).on('click', '.quote-reply', function (event) {
571-
$(this).closest('.dropdown').find('.menu').toggle('visible');
570+
$(document).on('click', '.quote-reply', async function (event) {
571+
event.preventDefault();
572572
const target = $(this).data('target');
573573
const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> ');
574574
const content = `> ${quote}\n\n`;
575575
let easyMDE;
576576
if ($(this).hasClass('quote-reply-diff')) {
577-
const $parent = $(this).closest('.comment-code-cloud');
578-
$parent.find('button.comment-form-reply').trigger('click');
579-
easyMDE = getAttachedEasyMDE($parent.find('[name="content"]'));
577+
const $replyBtn = $(this).closest('.comment-code-cloud').find('button.comment-form-reply');
578+
easyMDE = await handleReply($replyBtn);
580579
} else {
581580
// for normal issue/comment page
582581
easyMDE = getAttachedEasyMDE($('#comment-form .edit_area'));
@@ -592,6 +591,5 @@ function initRepoIssueCommentEdit() {
592591
easyMDE.codemirror.setCursor(easyMDE.codemirror.lineCount(), 0);
593592
});
594593
}
595-
event.preventDefault();
596594
});
597595
}

0 commit comments

Comments
 (0)