Skip to content
1 change: 1 addition & 0 deletions ui/analyse/css/study/_list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
min-height: 16em;
max-height: 16em;
}
position: relative;
display: flex;
flex-direction: column;
overflow: hidden;
Expand Down
10 changes: 6 additions & 4 deletions ui/analyse/src/study/studyChapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,19 @@ export function view(ctrl: StudyCtrl): VNode {
const canContribute = ctrl.members.canContribute(),
current = ctrl.currentChapter();
function update(vnode: VNode) {
const isChapterObscured = (study_list: HTMLElement, chapter: HTMLElement): boolean => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming conventions studyList

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also it's a list of chapters

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer isChapterVisible - a positive and clearer name.

const c = chapter.getBoundingClientRect(),
l = study_list.getBoundingClientRect();
return c.top < l.top || c.bottom > l.bottom;
};
const newCount = ctrl.chapters.list.size(),
vData = vnode.data!.li!,
el = vnode.elm as HTMLElement;
if (vData.count !== newCount) {
if (current.id !== ctrl.chapters.list.first().id) scrollToInnerSelector(el, '.active');
} else if (vData.currentId !== ctrl.data.chapter.id) {
vData.currentId = ctrl.data.chapter.id;
scrollToInnerSelector(el, '.active');
if (isChapterObscured(el, el.querySelector('.active')!)) scrollToInnerSelector(el, '.active');
}
vData.count = newCount;
if (canContribute && newCount > 1 && !vData.sortable) {
Expand Down Expand Up @@ -207,11 +212,8 @@ export function view(ctrl: StudyCtrl): VNode {
update(vnode);
},
postpatch(old, vnode) {
const scrollTop = (old.elm as HTMLElement).scrollTop;
vnode.data!.li = old.data!.li;
update(vnode);
if (old.children?.length === vnode.children?.length)
(vnode.elm as HTMLElement).scrollTop = scrollTop;
},
destroy: vnode => {
const sortable: Sortable = vnode.data!.li!.sortable;
Expand Down
Loading