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:
2025-11-30 09:06:26 -05:00
parent 0a2931030a
commit 1d7bd64600
+18 -4
View File
@@ -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();
}
}
}