From 871d28f8647fd2d0d0ae350526dc1a022402a4e4 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Wed, 28 Sep 2022 20:09:40 +0200 Subject: [PATCH] Fix live preview reset scrolling --- src/articles/static/live-preview.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/articles/static/live-preview.js b/src/articles/static/live-preview.js index f58721b..f45e8ee 100644 --- a/src/articles/static/live-preview.js +++ b/src/articles/static/live-preview.js @@ -34,6 +34,8 @@ function openPreviewPopup(event) { function loadPreview() { const id = Number(window.location.pathname.match(/\d+/)[0]); const body = prepareBody(); + const scrollX = preview.scrollX || 0; + const scrollY = preview.scrollY || 0; fetch(`/api/render/${id}/`, { method: "POST", body: body }) .then((response) => { return response.text(); @@ -42,6 +44,7 @@ function loadPreview() { preview.document.open("text/html", "replace"); preview.document.write(value); preview.document.close(); + preview.scrollTo(scrollX, scrollY); }) .catch(console.error); } @@ -88,7 +91,7 @@ function prepareBody() { } function setupLivePreview() { - const debouncedLoadPreview = debounce(loadPreview, 500); + const debouncedLoadPreview = debounce(loadPreview, 200); function listener(event) { event.preventDefault();