Fix SimpleMDE quote reply (#9757)

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Co-authored-by: zeripath <art27@cantab.net>
pull/9770/head
John Olheiser 5 years ago committed by Antoine GIRARD
parent f00961abe7
commit d89022c202
  1. 30
      web_src/js/index.js

@ -323,12 +323,14 @@ function initSimpleMDEImagePaste(simplemde, files) {
}); });
} }
let autoSimpleMDE;
function initCommentForm() { function initCommentForm() {
if ($('.comment.form').length === 0) { if ($('.comment.form').length === 0) {
return; return;
} }
setCommentSimpleMDE($('.comment.form textarea:not(.review-textarea)')); autoSimpleMDE = setCommentSimpleMDE($('.comment.form textarea:not(.review-textarea)'));
initBranchSelector(); initBranchSelector();
initCommentPreviewTab($('.comment.form')); initCommentPreviewTab($('.comment.form'));
initImagePaste($('.comment.form textarea')); initImagePaste($('.comment.form textarea'));
@ -826,25 +828,27 @@ function initRepository() {
$('.quote-reply').click(function (event) { $('.quote-reply').click(function (event) {
$(this).closest('.dropdown').find('.menu').toggle('visible'); $(this).closest('.dropdown').find('.menu').toggle('visible');
const target = $(this).data('target'); const target = $(this).data('target');
const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> ');
const content = `> ${quote}\n\n`;
let $content; let $content;
if ($(this).hasClass('quote-reply-diff')) { if ($(this).hasClass('quote-reply-diff')) {
const $parent = $(this).closest('.comment-code-cloud'); const $parent = $(this).closest('.comment-code-cloud');
$parent.find('button.comment-form-reply').click(); $parent.find('button.comment-form-reply').click();
$content = $parent.find('[name="content"]'); $content = $parent.find('[name="content"]');
} else { if ($content.val() !== '') {
$content = $('#content'); $content.val(`${$content.val()}\n\n${content}`);
} } else {
$content.val(`${content}`);
const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> '); }
const content = `> ${quote}\n\n`; $content.focus();
} else if (autoSimpleMDE !== null) {
if ($content.val() !== '') { if (autoSimpleMDE.value() !== '') {
$content.val(`${$content.val()}\n\n${content}`); autoSimpleMDE.value(`${autoSimpleMDE.value()}\n\n${content}`);
} else { } else {
$content.val(`${content}`); autoSimpleMDE.value(`${content}`);
}
} }
$content.focus();
event.preventDefault(); event.preventDefault();
}); });

Loading…
Cancel
Save