Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use async await to fix empty quote reply at first time #23168

Merged
merged 25 commits into from Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
aa9c759
fix firdt quote reply blank
HesterG Feb 24, 2023
923d3d7
Merge branch 'go-gitea:main' into fix-quote-reply-issue22075
HesterG Feb 24, 2023
6ab7979
remove useless logic
HesterG Feb 24, 2023
45a14cf
add check for null for the case of directly reply or comment
HesterG Feb 24, 2023
83bc150
Merge branch 'go-gitea:main' into fix-quote-reply-issue22075
HesterG Feb 24, 2023
c2e35e7
Merge branch 'go-gitea:main' into fix-quote-reply-issue22075
HesterG Feb 25, 2023
a272be2
Merge branch 'go-gitea:main' into fix-quote-reply-issue22075
HesterG Feb 25, 2023
a6f37d3
Merge branch 'go-gitea:main' into fix-quote-reply-issue22075
HesterG Feb 26, 2023
d88672a
Merge branch 'go-gitea:main' into fix-quote-reply-issue22075
HesterG Feb 27, 2023
104e4c4
fix lint
HesterG Feb 27, 2023
cae207c
use await for comment-form-reply
HesterG Feb 27, 2023
c185185
add back blank line
HesterG Feb 27, 2023
a1ce432
remove space
HesterG Feb 27, 2023
a0369f5
remove unnecessary change
HesterG Feb 27, 2023
0ae0a28
save for later tests
HesterG Feb 27, 2023
e6c95d4
change function name and clean up
HesterG Feb 27, 2023
d1a50ff
Merge branch 'main' into fix-quote-reply-issue22075
HesterG Feb 27, 2023
ca879e2
Merge branch 'main' into fix-quote-reply-issue22075
HesterG Feb 28, 2023
653eb17
rename param and move preventdefault and add empty onchange
HesterG Feb 28, 2023
eda0e2b
change onchange function to optional in easymde
HesterG Feb 28, 2023
9943dd2
Merge branch 'main' into fix-quote-reply-issue22075
HesterG Mar 1, 2023
f278f7b
Merge branch 'main' into fix-quote-reply-issue22075
HesterG Mar 1, 2023
ad5641e
Merge branch 'main' into fix-quote-reply-issue22075
HesterG Mar 2, 2023
9bb8c4a
Merge branch 'main' into fix-quote-reply-issue22075
HesterG Mar 2, 2023
9d756aa
Merge branch 'main' into fix-quote-reply-issue22075
jolheiser Mar 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion web_src/js/features/comp/EasyMDE.js
Expand Up @@ -78,7 +78,7 @@ export async function createCommentEasyMDE(textarea, easyMDEOptions = {}) {
const inputField = easyMDE.codemirror.getInputField();

easyMDE.codemirror.on('change', (...args) => {
easyMDEOptions?.onChange(...args);
easyMDEOptions?.onChange?.(...args);
});
easyMDE.codemirror.setOption('extraKeys', {
'Cmd-Enter': codeMirrorQuickSubmit,
Expand Down
30 changes: 17 additions & 13 deletions web_src/js/features/repo-issue.js
Expand Up @@ -418,6 +418,22 @@ function assignMenuAttributes(menu) {
return id;
}

export async function handleReply($el) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export async function handleReply($el) {
// Done asynchronously as a workaround to easyMDE not being loaded yet
export async function handleReply($el) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a workaround, but by design the EasyMDE is loaded asynchronously

hideElem($el);
const form = $el.closest('.comment-code-cloud').find('.comment-form');
form.removeClass('gt-hidden');
const $textarea = form.find('textarea');
let easyMDE = getAttachedEasyMDE($textarea);
if (!easyMDE) {
await attachTribute($textarea.get(), {mentions: true, emoji: true});
easyMDE = await createCommentEasyMDE($textarea);
}
$textarea.focus();
easyMDE.codemirror.focus();
assignMenuAttributes(form.find('.menu'));
return easyMDE;
}

export function initRepoPullRequestReview() {
if (window.location.hash && window.location.hash.startsWith('#issuecomment-')) {
const commentDiv = $(window.location.hash);
Expand Down Expand Up @@ -455,19 +471,7 @@ export function initRepoPullRequestReview() {

$(document).on('click', 'button.comment-form-reply', async function (e) {
e.preventDefault();

hideElem($(this));
const form = $(this).closest('.comment-code-cloud').find('.comment-form');
form.removeClass('gt-hidden');
const $textarea = form.find('textarea');
let easyMDE = getAttachedEasyMDE($textarea);
if (!easyMDE) {
await attachTribute($textarea.get(), {mentions: true, emoji: true});
easyMDE = await createCommentEasyMDE($textarea);
}
$textarea.focus();
easyMDE.codemirror.focus();
assignMenuAttributes(form.find('.menu'));
await handleReply($(this));
});

const $reviewBox = $('.review-box-panel');
Expand Down
11 changes: 5 additions & 6 deletions web_src/js/features/repo-legacy.js
Expand Up @@ -6,7 +6,7 @@ import {
initRepoIssueBranchSelect, initRepoIssueCodeCommentCancel, initRepoIssueCommentDelete,
initRepoIssueComments, initRepoIssueDependencyDelete, initRepoIssueReferenceIssue,
initRepoIssueStatusButton, initRepoIssueTitleEdit, initRepoIssueWipToggle,
initRepoPullRequestUpdate, updateIssuesMeta,
initRepoPullRequestUpdate, updateIssuesMeta, handleReply
} from './repo-issue.js';
import {initUnicodeEscapeButton} from './repo-unicode-escape.js';
import {svg} from '../svg.js';
Expand Down Expand Up @@ -613,15 +613,15 @@ function initRepoIssueCommentEdit() {
$(document).on('click', '.edit-content', onEditContent);

// Quote reply
$(document).on('click', '.quote-reply', function (event) {
$(document).on('click', '.quote-reply', async function (event) {
HesterG marked this conversation as resolved.
Show resolved Hide resolved
event.preventDefault();
silverwind marked this conversation as resolved.
Show resolved Hide resolved
const target = $(this).data('target');
const quote = $(`#${target}`).text().replace(/\n/g, '\n> ');
const content = `> ${quote}\n\n`;
let easyMDE;
if ($(this).hasClass('quote-reply-diff')) {
const $parent = $(this).closest('.comment-code-cloud');
$parent.find('button.comment-form-reply').trigger('click');
easyMDE = getAttachedEasyMDE($parent.find('[name="content"]'));
const $replyBtn = $(this).closest('.comment-code-cloud').find('button.comment-form-reply');
easyMDE = await handleReply($replyBtn);
} else {
// for normal issue/comment page
easyMDE = getAttachedEasyMDE($('#comment-form .edit_area'));
Expand All @@ -637,6 +637,5 @@ function initRepoIssueCommentEdit() {
easyMDE.codemirror.setCursor(easyMDE.codemirror.lineCount(), 0);
});
}
event.preventDefault();
});
}