···11# Changelog
2233## Next
44-- Fix deselection not happening when videos update
44+- Fix selection staying in the same position when videos update
55+- Keep video selected if it moves position
5667## 1.6.2 - 2024 Jan 15
78- Fix channel page filtering
+20-4
src/routes/+page.svelte
···1616 loading++
17171818 const selectedId = videos[selectedIndex]?.id
1919+ const oldselectedIndex = selectedIndex
19202021 const newVideos = await commands.getVideos(options, null)
2122 allLoaded = newVideos.length < $viewOptions.limit
2223 videos = newVideos
2323- // Remove selection if the video changes position
2424- if (!selectedId || selectedId !== videos[selectedIndex]?.id) {
2424+2525+ // Update the selection index if the video moves
2626+ const newSelectedIndex = videos.findIndex((v) => v.id === selectedId)
2727+ if (newSelectedIndex >= 0) {
2828+ selectedIndex = newSelectedIndex
2929+ selectionVisible = true
3030+ } else {
3131+ // Or clear selection if the video disappeared from view
2532 selectedIndex = 0
2633 selectionVisible = false
2734 }
3535+ const selectionMoved = selectionVisible && selectedIndex !== oldselectedIndex
28362929- await tick()
3737+ if (selectionMoved) {
3838+ allowScrollToBox = false
3939+ await tick()
4040+ allowScrollToBox = true
4141+ scrollToBox(selectedIndex)
4242+ } else {
4343+ await tick()
4444+ }
3045 await autoloadHandler()
3146 loading--
3247 }
···263278264279 let boxes: HTMLDivElement[] = []
265280 $: scrollToBox(selectedIndex)
281281+ let allowScrollToBox = true
266282 function scrollToBox(index: number) {
267267- if (scrollDiv && boxes[index]) {
283283+ if (scrollDiv && boxes[index] && allowScrollToBox) {
268284 const el = boxes[index].getBoundingClientRect()
269285 const parent = scrollDiv.getBoundingClientRect()
270286 const topOffset = el.top - parent.top