Fix Quote Reply button on review diff (#13830)

* Fix Quote Reply #13762

* requestAnimationFrame() instead of setTimeout()

Co-authored-by: 6543 <6543@obermui.de>
tokarchuk/v1.17
Jimmy Praet 4 years ago committed by GitHub
parent 6bdcacd73b
commit 4d66ee1f74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      web_src/js/index.js

@ -901,25 +901,23 @@ async function initRepository() {
const target = $(this).data('target'); const target = $(this).data('target');
const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> '); const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> ');
const content = `> ${quote}\n\n`; const content = `> ${quote}\n\n`;
let $simplemde = autoSimpleMDE;
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').trigger('click'); $parent.find('button.comment-form-reply').trigger('click');
$content = $parent.find('[name="content"]'); $simplemde = $parent.find('[name="content"]').data('simplemde');
if ($content.val() !== '') {
$content.val(`${$content.val()}\n\n${content}`);
} else {
$content.val(`${content}`);
} }
$content.focus(); if ($simplemde !== null) {
} else if (autoSimpleMDE !== null) { if ($simplemde.value() !== '') {
if (autoSimpleMDE.value() !== '') { $simplemde.value(`${$simplemde.value()}\n\n${content}`);
autoSimpleMDE.value(`${autoSimpleMDE.value()}\n\n${content}`);
} else { } else {
autoSimpleMDE.value(`${content}`); $simplemde.value(`${content}`);
} }
} }
requestAnimationFrame(() => {
$simplemde.codemirror.focus();
$simplemde.codemirror.setCursor($simplemde.codemirror.lineCount(), 0);
});
event.preventDefault(); event.preventDefault();
}); });
@ -1082,8 +1080,10 @@ async function initRepository() {
$textarea.val($rawContent.text()); $textarea.val($rawContent.text());
$simplemde.value($rawContent.text()); $simplemde.value($rawContent.text());
} }
requestAnimationFrame(() => {
$textarea.focus(); $textarea.focus();
$simplemde.codemirror.focus(); $simplemde.codemirror.focus();
});
event.preventDefault(); event.preventDefault();
}); });

Loading…
Cancel
Save