From 180e1ac64c5b77fcd86f7145e7170bb7b7dc7b51 Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Thu, 3 Dec 2020 22:04:49 +0100 Subject: [PATCH 1/2] Fix Quote Reply #13762 --- web_src/js/index.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index ef865529db868..59ff505915115 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -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}`); } } + setTimeout(() => { + $simplemde.codemirror.focus(); + $simplemde.codemirror.setCursor($simplemde.codemirror.lineCount(), 0); + }, 0); event.preventDefault(); }); @@ -1082,8 +1080,10 @@ async function initRepository() { $textarea.val($rawContent.text()); $simplemde.value($rawContent.text()); } - $textarea.focus(); - $simplemde.codemirror.focus(); + setTimeout(() => { + $textarea.focus(); + $simplemde.codemirror.focus(); + }, 0); event.preventDefault(); }); From f1047732907ef17492fc5a3c30f560d342cfbcdd Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Sat, 5 Dec 2020 13:35:53 +0100 Subject: [PATCH 2/2] requestAnimationFrame() instead of setTimeout() --- web_src/js/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index 59ff505915115..2cb928b203de6 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -914,10 +914,10 @@ async function initRepository() { $simplemde.value(`${content}`); } } - setTimeout(() => { + requestAnimationFrame(() => { $simplemde.codemirror.focus(); $simplemde.codemirror.setCursor($simplemde.codemirror.lineCount(), 0); - }, 0); + }); event.preventDefault(); }); @@ -1080,10 +1080,10 @@ async function initRepository() { $textarea.val($rawContent.text()); $simplemde.value($rawContent.text()); } - setTimeout(() => { + requestAnimationFrame(() => { $textarea.focus(); $simplemde.codemirror.focus(); - }, 0); + }); event.preventDefault(); });