Skip to content

Commit 31f0efb

Browse files
authored
fix use_virtual_list written by copilot (#53)
1 parent 98dca02 commit 31f0efb

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

crates/yew-hooks/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yew-hooks"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
edition = "2021"
55
authors = ["Jet Li <jing.i.qin@icloud.com>"]
66
categories = ["gui", "wasm", "web-programming"]

crates/yew-hooks/src/hooks/use_virtual_list.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@ where
164164
end_index += 1;
165165
}
166166
end_index = end_index.min(items.len());
167-
let start_index = start_index.saturating_sub(*overscan);
168-
let end_index = (end_index + *overscan).min(items.len());
169-
let visible_items = (start_index..end_index)
167+
let visible_start = start_index;
168+
let visible_end = end_index;
169+
let render_start = visible_start.saturating_sub(*overscan);
170+
let render_end = (visible_end + *overscan).min(items.len());
171+
let visible_items = (render_start..render_end)
170172
.map(|index| {
171173
let top = heights[0..index].iter().sum::<f64>();
172174
VirtualListItem {
@@ -196,8 +198,8 @@ where
196198
let new_handle = UseVirtualListHandle {
197199
visible_items,
198200
total_height,
199-
start_index,
200-
end_index,
201+
start_index: visible_start,
202+
end_index: visible_end.saturating_sub(1),
201203
scroll_to,
202204
};
203205
handle_clone.set(new_handle.clone());

0 commit comments

Comments
 (0)