fix(keys): the first row scrolls to the page top whenever it fits the first screen
This commit is contained in:
1 parent
722fdc2a20
commit
3c1d8a4867
1 file changed
+3
-6
@@ -1,7 +1,5 @@
|
|||||||
import { type Binding, useKeys } from "#lib/keys.svelte.js";
|
import { type Binding, useKeys } from "#lib/keys.svelte.js";
|
||||||
|
|
||||||
const TOP_REACH = 0.6;
|
|
||||||
|
|
||||||
interface Options<T> {
|
interface Options<T> {
|
||||||
edit?: (item: T) => void;
|
edit?: (item: T) => void;
|
||||||
extra?: () => Binding[];
|
extra?: () => Binding[];
|
||||||
@@ -66,10 +64,9 @@ export class ListNav<T> {
|
|||||||
if (!row) {
|
if (!row) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const nearTop =
|
const fitsFirstScreen =
|
||||||
row.getBoundingClientRect().top + window.scrollY <
|
row.getBoundingClientRect().bottom + window.scrollY <= window.innerHeight;
|
||||||
window.innerHeight * TOP_REACH;
|
if (this.cursor === 0 && block === "nearest" && fitsFirstScreen) {
|
||||||
if (this.cursor === 0 && block === "nearest" && nearTop) {
|
|
||||||
window.scrollTo({ top: 0 });
|
window.scrollTo({ top: 0 });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user