Skip to content

Commit

Permalink
tweak to scroll behavior on search, scroll to center when hit is off …
Browse files Browse the repository at this point in the history
…screen
  • Loading branch information
tconfrey committed Dec 6, 2024
1 parent 3185626 commit ecd451b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/bt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ecd451b

Please sign in to comment.