mirror of
https://github.com/kennethreitz/kjvstudy.org.git
synced 2026-06-05 23:00:16 +00:00
Make keyboard navigation viewport-aware on initial keypress
When you scroll the page and then press ↑ or ↓ for the first time, the selection now intelligently starts from what's currently visible in the viewport instead of always starting at the top. **Behavior:** - If chapter section is visible → starts there - If scrolled past chapters → starts at first visible paragraph - Selection only moves when you press a key (not automatically on scroll) This makes navigation feel natural when combined with mouse/trackpad scrolling. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -515,8 +515,15 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
selectParagraph(selectedParagraphIndex - 1);
|
||||
}
|
||||
} else {
|
||||
// No selection, start at chapter section
|
||||
selectChapterSection();
|
||||
// No selection - start with first visible item
|
||||
if (chapterSection && KJVNav.isInViewport(chapterSection)) {
|
||||
selectChapterSection();
|
||||
} else if (contentParagraphs.length > 0) {
|
||||
const visibleIndex = KJVNav.findFirstVisibleIndex(Array.from(contentParagraphs));
|
||||
selectParagraph(visibleIndex);
|
||||
} else {
|
||||
selectChapterSection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -547,8 +554,15 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
selectParagraph(selectedParagraphIndex + 1);
|
||||
}
|
||||
} else {
|
||||
// No selection, start at chapter section
|
||||
selectChapterSection();
|
||||
// No selection - start with first visible item
|
||||
if (chapterSection && KJVNav.isInViewport(chapterSection)) {
|
||||
selectChapterSection();
|
||||
} else if (contentParagraphs.length > 0) {
|
||||
const visibleIndex = KJVNav.findFirstVisibleIndex(Array.from(contentParagraphs));
|
||||
selectParagraph(visibleIndex);
|
||||
} else {
|
||||
selectChapterSection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user