Skip to content

Commit

Permalink
Fix Quote Reply button on review diff (#13830)
Browse files Browse the repository at this point in the history
* Fix Quote Reply #13762

* requestAnimationFrame() instead of setTimeout()

Co-authored-by: 6543 <6543@obermui.de>
  • Loading branch information
jpraet and 6543 authored Dec 8, 2020
1 parent 6bdcacd commit 4d66ee1
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,25 +901,23 @@ async function initRepository() {
const target = $(this).data('target');
const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> ');
const content = `> ${quote}\n\n`;

let $content;
let $simplemde = autoSimpleMDE;
if ($(this).hasClass('quote-reply-diff')) {
const $parent = $(this).closest('.comment-code-cloud');
$parent.find('button.comment-form-reply').trigger('click');
$content = $parent.find('[name="content"]');
if ($content.val() !== '') {
$content.val(`${$content.val()}\n\n${content}`);
} else {
$content.val(`${content}`);
}
$content.focus();
} else if (autoSimpleMDE !== null) {
if (autoSimpleMDE.value() !== '') {
autoSimpleMDE.value(`${autoSimpleMDE.value()}\n\n${content}`);
$simplemde = $parent.find('[name="content"]').data('simplemde');
}
if ($simplemde !== null) {
if ($simplemde.value() !== '') {
$simplemde.value(`${$simplemde.value()}\n\n${content}`);
} else {
autoSimpleMDE.value(`${content}`);
$simplemde.value(`${content}`);
}
}
requestAnimationFrame(() => {
$simplemde.codemirror.focus();
$simplemde.codemirror.setCursor($simplemde.codemirror.lineCount(), 0);
});
event.preventDefault();
});

Expand Down Expand Up @@ -1082,8 +1080,10 @@ async function initRepository() {
$textarea.val($rawContent.text());
$simplemde.value($rawContent.text());
}
$textarea.focus();
$simplemde.codemirror.focus();
requestAnimationFrame(() => {
$textarea.focus();
$simplemde.codemirror.focus();
});
event.preventDefault();
});

Expand Down

0 comments on commit 4d66ee1

Please sign in to comment.