rintoj / ngx-virtual-scroller

Virtual Scroll displays a virtual, "infinite" list.
https://rintoj.github.io/ngx-virtual-scroller
MIT License
979 stars 295 forks source link

Current slice of visible items change on prepending items off-screen #507

Open soletan opened 3 years ago

soletan commented 3 years ago

According to README the scroller keeps current slice of items visible in case of prepending items. However, this didn't work for me due to increasing bufferAmount attribute.

See this project for illustration: https://stackblitz.com/edit/angular-ivy-nblxir

If you populate the list, scroll down a bit and click on item visible at the very top while holding Ctrl- and Alt-key, the actually clicked item gets pushed down for scrolling offset isn't adjusted after having prepended items.

After digging into the code I found that the related code is focusing on first item currently in DOM to stay first item in DOM, which is different from first visible item staying first visible item. Thus, this issue isn't reproducible unless increasing bufferAmount attribute's value from 2 to e.g. 10.

Following this observation I tried fixing the issue. See the related PR (which is affecting some issues I was having on setting up my IDE and getting rid of linter issues).