Skip to content

Commit

Permalink
Fix virtual list indexes not updating
Browse files Browse the repository at this point in the history
  • Loading branch information
probablykasper committed Sep 26, 2024
1 parent b6d64df commit 6ba21f6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/VirtualListBlock.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
let start_index = 0
let visible_count = 0
// Workaround for svelte not updating the indexes when the keys change
$: visible_count_obj = { length: visible_count }
$: {
items, item_height, buffer
if (scroll_container && main_element) refresh()
Expand Down Expand Up @@ -71,6 +74,7 @@
start_index = Math.floor(start_pixel / item_height)
visible_count = Math.ceil(end_pixel / item_height) - start_index
visible_count_obj = { length: visible_count }
}
$: apply_scroll_event_handler(scroll_container)
Expand Down Expand Up @@ -103,7 +107,7 @@
style:padding-top={start_index * item_height + 'px'}
style:height={items.length * item_height + 'px'}
>
{#each { length: visible_count } as _, i (get_key(items[i + start_index], i + start_index))}
{#each visible_count_obj as _, i (get_key(items[i + start_index], i + start_index))}
<slot item={items[i + start_index]} i={i + start_index} />
{/each}
</div>

0 comments on commit 6ba21f6

Please sign in to comment.