robherley/snips.sh

Scroll to line on webpage if out of view

Closed this issue · 1 comments

What is the feature or enhancement?

If you have a really long snippet and line(s) are selected, the page should jump to those lines.

Could use getSelectedLines somewhere after the other methods get called when the DOM loads:

window.addEventListener("DOMContentLoaded", async () => {
initHeaderObserver();
watchForShiftClick();
highlightLines();
mermaid.initialize({ startOnLoad: false, theme: "dark" });
await mermaid.run({
querySelector: "code.language-mermaid",
});
});

Something like this should work with better checks:

document.getElementById(`#L${theFirstSelectedLineHere}`).scrollIntoView();

Or if the menu/etc get in the way window.scroll to the element's bounding +/- some px should also work