Add vim-style keyboard shortcuts to reader
j/k scroll down/up (small step, ~8% viewport) d/u scroll half page down/up f/b scroll full page down/up g/G jump to top/bottom n/p next/prev page (PDF scroll mode) Keys are ignored when an input or textarea is focused. Existing arrow key navigation in paginated PDF mode unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
bbb982d0b1
commit
d607388bad
1 changed files with 22 additions and 0 deletions
|
|
@ -2111,6 +2111,28 @@ document.addEventListener('keydown', e => {
|
||||||
if (e.key === 'ArrowRight') { e.preventDefault(); pdfGoToPage(pdfCurrentPage + 1); }
|
if (e.key === 'ArrowRight') { e.preventDefault(); pdfGoToPage(pdfCurrentPage + 1); }
|
||||||
if (e.key === 'ArrowLeft') { e.preventDefault(); pdfGoToPage(pdfCurrentPage - 1); }
|
if (e.key === 'ArrowLeft') { e.preventDefault(); pdfGoToPage(pdfCurrentPage - 1); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vim-style scroll — ignore when typing in an input
|
||||||
|
const tag = document.activeElement?.tagName;
|
||||||
|
if (tag !== 'INPUT' && tag !== 'TEXTAREA') {
|
||||||
|
const contentEl = $('reader-content');
|
||||||
|
if (contentEl) {
|
||||||
|
const small = Math.round(contentEl.clientHeight * 0.08);
|
||||||
|
const large = Math.round(contentEl.clientHeight * 0.85);
|
||||||
|
if (e.key === 'j') { e.preventDefault(); contentEl.scrollBy({top: small, behavior: 'smooth'}); }
|
||||||
|
if (e.key === 'k') { e.preventDefault(); contentEl.scrollBy({top: -small, behavior: 'smooth'}); }
|
||||||
|
if (e.key === 'd') { e.preventDefault(); contentEl.scrollBy({top: large / 2, behavior: 'smooth'}); }
|
||||||
|
if (e.key === 'u') { e.preventDefault(); contentEl.scrollBy({top: -large / 2, behavior: 'smooth'}); }
|
||||||
|
if (e.key === 'f') { e.preventDefault(); contentEl.scrollBy({top: large, behavior: 'smooth'}); }
|
||||||
|
if (e.key === 'b') { e.preventDefault(); contentEl.scrollBy({top: -large, behavior: 'smooth'}); }
|
||||||
|
if (e.key === 'g') { e.preventDefault(); contentEl.scrollTop = 0; }
|
||||||
|
if (e.key === 'G') { e.preventDefault(); contentEl.scrollTop = contentEl.scrollHeight; }
|
||||||
|
if (currentPdfDoc && !readerSettings.pdfPaginated) {
|
||||||
|
if (e.key === 'n') { e.preventDefault(); pdfGoToPage(pdfCurrentPage + 1); }
|
||||||
|
if (e.key === 'p') { e.preventDefault(); pdfGoToPage(pdfCurrentPage - 1); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue