From ecd451b94b97f29597c8ca6321458b6ea9dcd455 Mon Sep 17 00:00:00 2001 From: tconfrey Date: Fri, 6 Dec 2024 17:22:26 -0500 Subject: [PATCH] tweak to scroll behavior on search, scroll to center when hit is off screen --- app/bt.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/bt.js b/app/bt.js index 76c1a7e..d0b669e 100644 --- a/app/bt.js +++ b/app/bt.js @@ -2160,13 +2160,16 @@ function rowsInViewport() { function scrollIntoViewIfNeeded(element) { // Helper function to make sure search or nav to item has its row visible but only scroll if needed + // NB needed the timeout for block:center to work const height = $(window).height(); const topOfRow = $(element).position().top; const displayTop = $(document).scrollTop(); - if (topOfRow < displayTop) - element.scrollIntoView(true); - if (topOfRow > (displayTop + height - 200)) - element.scrollIntoView(false); + + if (topOfRow < displayTop || topOfRow > (displayTop + height - 200)) { + setTimeout(() => { + element.scrollIntoView({ block: 'center', behavior: 'smooth' }); + }, 0); + } } function extendedSearch(sstr, currentMatch) {