Skip to content

Conversation

@johndoknjas
Copy link
Contributor

@johndoknjas johndoknjas commented Oct 27, 2025

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).

Copy link
Collaborator

@ornicar ornicar left a 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;
Copy link
Collaborator

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;
Copy link
Collaborator

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

Copy link
Contributor Author

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.

@ornicar
Copy link
Collaborator

ornicar commented Oct 27, 2025

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.

@johndoknjas johndoknjas marked this pull request as draft October 28, 2025 05:27
@johndoknjas johndoknjas force-pushed the scroll-to-selected-chapter branch from 595328b to f08d656 Compare October 28, 2025 06:08
@johndoknjas johndoknjas marked this pull request as ready for review October 28, 2025 06:12
@johndoknjas johndoknjas marked this pull request as draft October 28, 2025 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants