From 6be6a82dc7bd73929f661e11ef2f2710dd740ad4 Mon Sep 17 00:00:00 2001 From: inokawa <48897392+inokawa@users.noreply.github.com> Date: Sun, 10 Mar 2024 20:12:27 +0900 Subject: [PATCH] Refactor --- src/core/store.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/core/store.ts b/src/core/store.ts index f521f35b..01103a18 100644 --- a/src/core/store.ts +++ b/src/core/store.ts @@ -350,19 +350,13 @@ export const createVirtualStore = ( break; } - let shouldKeepStart = false; let shouldStickToEnd = false; - if (_scrollMode === SCROLL_BY_SHIFT) { - if (scrollOffset > getMaxScrollOffset() - SUBPIXEL_THRESHOLD) { - // Keep end to stick to the end - shouldStickToEnd = true; - } else { - // Keep distance from end immediately after prepending - // We can assume jumps occurred on the upper outside - } - } else { - // Keep start at mid - shouldKeepStart = true; + if ( + _scrollMode === SCROLL_BY_SHIFT && + scrollOffset > getMaxScrollOffset() - SUBPIXEL_THRESHOLD + ) { + // Keep end to stick to the end immediately after prepending + shouldStickToEnd = true; } // Calculate jump @@ -370,7 +364,7 @@ export const createVirtualStore = ( applyJump( updated.reduce((acc, [index, size]) => { if ( - !shouldKeepStart || + shouldStickToEnd || (_frozenRange ? // https://github.com/inokawa/virtua/issues/380 index < _frozenRange[0]