Skip to content

Commit 802e7bf

Browse files
committed
Make the arrow keys honor RTL.
At least to my understanding, the pages will flip in the opposite direction.
1 parent fb272d1 commit 802e7bf

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/theme/book.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -557,20 +557,35 @@ function playground_text(playground, hidden = true) {
557557
document.addEventListener('keydown', function (e) {
558558
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
559559
if (window.search && window.search.hasFocus()) { return; }
560+
var html = document.querySelector('html');
560561

562+
function next() {
563+
var nextButton = document.querySelector('.nav-chapters.next');
564+
if (nextButton) {
565+
window.location.href = nextButton.href;
566+
}
567+
}
568+
function prev() {
569+
var previousButton = document.querySelector('.nav-chapters.previous');
570+
if (previousButton) {
571+
window.location.href = previousButton.href;
572+
}
573+
}
561574
switch (e.key) {
562575
case 'ArrowRight':
563576
e.preventDefault();
564-
var nextButton = document.querySelector('.nav-chapters.next');
565-
if (nextButton) {
566-
window.location.href = nextButton.href;
577+
if (html.dir == 'rtl') {
578+
prev();
579+
} else {
580+
next();
567581
}
568582
break;
569583
case 'ArrowLeft':
570584
e.preventDefault();
571-
var previousButton = document.querySelector('.nav-chapters.previous');
572-
if (previousButton) {
573-
window.location.href = previousButton.href;
585+
if (html.dir == 'rtl') {
586+
next();
587+
} else {
588+
prev();
574589
}
575590
break;
576591
}

0 commit comments

Comments
 (0)