-
-
Couldn't load subscription status.
- Fork 2.5k
Scroll to selected chapter #18497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Scroll to selected chapter #18497
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a lot of code for a fix that should only exist if it's simple.
Adding such code complexity to solve a problem is pretty much a guarantee to create more problems down the line. It's a not-so-virtuous circle.
| const activeChapter = (v: VNode) => { | ||
| const kids = (v.children as any[]) ?? []; | ||
| const activeVnode = kids.find(c => c?.data?.class?.active); | ||
| return activeVnode?.elm as HTMLElement | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the source of truth is ctrl.currentChapter(), not the DOM. The DOM is for presentation only, not storage/retrieval of information.
| const dyTop = t.top - c.top; | ||
| const dyBottom = t.bottom - c.bottom; | ||
| if (dyTop < 0) el.scrollTop += dyTop; | ||
| else if (dyBottom > 0) el.scrollTop += dyBottom; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this reinventing scrollToInnerSelector that we see in use in this same file?
https://github.com/lichess-org/lila/blob/master/ui/analyse/src/study/studyChapters.ts#L177-L177
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ornicar Yeah I was approaching this the wrong way. Updated so that any adjustments needed for scrolling take place in view where it first happens.
|
it looks like the file already contains code that tries to scroll the the selected chapter: https://github.com/lichess-org/lila/blob/master/ui/analyse/src/study/studyChapters.ts#L175-L178 Let's fix it instead of adding more code alongside it to achieve the same thing. |
595328b to
f08d656
Compare
Makes it so that a scroll is done to the active chapter, in the event of a chapter change or page load.
Recording of current behaviour:
Screen.Recording.2025-10-26.at.11.09.35.PM.mov
After this patch:
Screen.Recording.2025-10-26.at.11.11.11.PM.mov
EDIT: after recent commits, same as recording except will scroll so that a previously obscured chapter is in the middle of the viewable section (when this is possible).