Skip to content

Commit d89022c

Browse files
jolheiserzeripath
authored andcommitted
Fix SimpleMDE quote reply (#9757)
Signed-off-by: jolheiser <[email protected]> Co-authored-by: zeripath <[email protected]>
1 parent f00961a commit d89022c

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

web_src/js/index.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,14 @@ function initSimpleMDEImagePaste(simplemde, files) {
323323
});
324324
}
325325

326+
let autoSimpleMDE;
327+
326328
function initCommentForm() {
327329
if ($('.comment.form').length === 0) {
328330
return;
329331
}
330332

331-
setCommentSimpleMDE($('.comment.form textarea:not(.review-textarea)'));
333+
autoSimpleMDE = setCommentSimpleMDE($('.comment.form textarea:not(.review-textarea)'));
332334
initBranchSelector();
333335
initCommentPreviewTab($('.comment.form'));
334336
initImagePaste($('.comment.form textarea'));
@@ -826,25 +828,27 @@ function initRepository() {
826828
$('.quote-reply').click(function (event) {
827829
$(this).closest('.dropdown').find('.menu').toggle('visible');
828830
const target = $(this).data('target');
831+
const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> ');
832+
const content = `> ${quote}\n\n`;
829833

830834
let $content;
831835
if ($(this).hasClass('quote-reply-diff')) {
832836
const $parent = $(this).closest('.comment-code-cloud');
833837
$parent.find('button.comment-form-reply').click();
834838
$content = $parent.find('[name="content"]');
835-
} else {
836-
$content = $('#content');
837-
}
838-
839-
const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> ');
840-
const content = `> ${quote}\n\n`;
841-
842-
if ($content.val() !== '') {
843-
$content.val(`${$content.val()}\n\n${content}`);
844-
} else {
845-
$content.val(`${content}`);
839+
if ($content.val() !== '') {
840+
$content.val(`${$content.val()}\n\n${content}`);
841+
} else {
842+
$content.val(`${content}`);
843+
}
844+
$content.focus();
845+
} else if (autoSimpleMDE !== null) {
846+
if (autoSimpleMDE.value() !== '') {
847+
autoSimpleMDE.value(`${autoSimpleMDE.value()}\n\n${content}`);
848+
} else {
849+
autoSimpleMDE.value(`${content}`);
850+
}
846851
}
847-
$content.focus();
848852
event.preventDefault();
849853
});
850854

0 commit comments

Comments
 (0)