From 4c2251a4606f0b60ab02cf14139af74267ade191 Mon Sep 17 00:00:00 2001 From: Matthias Portzel Date: Mon, 28 Mar 2022 23:45:18 -0400 Subject: [PATCH] Save and restore scroll position * This is a big deal when typing thoughts that are over a page long, it will jump you to the bottom of the input box every time and it's a little jarring. --- main/templates/whispermaphone/post.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main/templates/whispermaphone/post.html b/main/templates/whispermaphone/post.html index 7581daf..951336f 100644 --- a/main/templates/whispermaphone/post.html +++ b/main/templates/whispermaphone/post.html @@ -40,11 +40,15 @@ const textExtEl = document.getElementById("id_extended_text"); function updateBoxHeight(box) { + // Save scroll position + const scrollY = window.scrollY; //style.height doesn't include padding, .scrollHeight does box.style.height = "auto"; // Set overflow hidden to ensure scrollbars aren't shown, since they change the width and thus the height box.style.overflow = "hidden"; box.style.height = box.scrollHeight + "px"; + //Restore scroll position + window.scrollTo(0, scrollY); } // If we're handling maxlength in JS, then having the maxlength attribute is annoying