fix(keys): the first row scrolls to the page top whenever it fits the first screen

This commit is contained in:
hh committed 2026-10-16 15:54:41 +00:00
1 parent 722fdc2a20
commit 3c1d8a4867
1 file changed
+3 -6
+3 -6
View File
@@ -1,7 +1,5 @@
import { type Binding, useKeys } from "#lib/keys.svelte.js";
const TOP_REACH = 0.6;
interface Options<T> {
edit?: (item: T) => void;
extra?: () => Binding[];
@@ -66,10 +64,9 @@ export class ListNav<T> {
if (!row) {
return;
}
const nearTop =
row.getBoundingClientRect().top + window.scrollY <
window.innerHeight * TOP_REACH;
if (this.cursor === 0 && block === "nearest" && nearTop) {
const fitsFirstScreen =
row.getBoundingClientRect().bottom + window.scrollY <= window.innerHeight;
if (this.cursor === 0 && block === "nearest" && fitsFirstScreen) {
window.scrollTo({ top: 0 });
return;
}