[Github-comments] [geany/geany-plugins] Markdown Plugin (Feature Request): Keep scroll position on reload (#1055)

Matthew Brush notifications at xxxxx
Wed Feb 10 09:12:53 UTC 2021


After a little more research I think it might be possible to do it fully within JS by loading the scroll position from the browser's localStorage (or maybe just sessionStorage) when the DOM is finished loading and saving it before the page is unloaded. If I can get that working, it should do the trick for both Webkit1 and Webkit2 and allow to remove some code from the plugin.

Basic theoretical untested code:

```js
document.addEventListener('DOMContentLoaded', () => { 
  const pos = localStorage.getItem('mdScrollPos');
  if (pos) window.scrollTo(pos.x, pos.y);
});
window.onbeforeunload = () => {
  localStorage.setItem('mdScrollPos', {
    x: window.scrollX,
    y: window.scrollY,
  });
};
```

To make it have different scroll positions saved per file rather than one global scroll position for all files will require to pass the filename through the template to JS so it can keep track of which scroll position to load/save. It might also require a bit of JS code to prune/vacuum the localStorage to get rid of scroll positions older than a certain date and/or above a certain number, but that might be overkill.

Next time I'm working on the plugin I'll try and see if it works.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/issues/1055#issuecomment-776559476
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20210210/7a3cd2f4/attachment.htm>


More information about the Github-comments mailing list