Suggestion: Remember place in sutta when switching views

Context

Viewing a sutta on Sutta Central in Chrome, Edge, or Firefox on Windows 11 PC.

Current Behavior

When using the “V” keyboard shortcut to switch views, the page inconsistently saves where you were after fully cycling through the views. You can see this if you go to a sutta, scroll down to a certain point, make note of where you are, then press the “V” key to cycle through the views. When you come back to your original view, the page will sometimes be in the place where you were but other times be in a different place. The exception is the very top of the page, where it will consistently remember your place. Firefox seems to remember more consistently than Edge or Chrome.

Desired Behavior

If it isn’t an overly-laborious fix, have the page consistently remember where you were after cycling through the views.

2 Likes

:thinking:

My guess at the “fix” here would be on layout change to identify the segment currently in view using:

segments.forEach(s => {
    const rect = s.getBoundingClientRect();
    ...

and then s.scrollTo() that segment after the layout shift is finished. @HongDa - How would one accomplish that? Surely lit redux has a cleaner way to execute a callback after a layout shift than to use setTimeout?

3 Likes

I generally take the long way around to do this.

I tap M, to turn on the main SC IDs and then tap the ID (this adds it to the URL) and then tap V to switch views.

Can we just add a segment ID lookup to the view switcher rather than having it run with the scroll function?

1 Like

I was under the impression that #id in a URL basically just calls:

document.getElementByID(id).scrollTo()

EDIT: Oh! I see what you mean. .focus() might be enough to tell the browser to keep that segment in view. :thinking: Could try it!

1 Like

Yeah sorry. I forgot my nerd-words :nerd_face:

1 Like

This needs to happen when notes are toggled too. So maybe Ven Khemarato’s solution is more elegant?

1 Like