From 802e7bffc3d81b868ede46fa0cb91e68009f6c96 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 2 Sep 2023 16:44:47 -0700 Subject: [PATCH] Make the arrow keys honor RTL. At least to my understanding, the pages will flip in the opposite direction. --- src/theme/book.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/theme/book.js b/src/theme/book.js index fb913165..aa12e7ec 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -557,20 +557,35 @@ function playground_text(playground, hidden = true) { document.addEventListener('keydown', function (e) { if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; } if (window.search && window.search.hasFocus()) { return; } + var html = document.querySelector('html'); + function next() { + var nextButton = document.querySelector('.nav-chapters.next'); + if (nextButton) { + window.location.href = nextButton.href; + } + } + function prev() { + var previousButton = document.querySelector('.nav-chapters.previous'); + if (previousButton) { + window.location.href = previousButton.href; + } + } switch (e.key) { case 'ArrowRight': e.preventDefault(); - var nextButton = document.querySelector('.nav-chapters.next'); - if (nextButton) { - window.location.href = nextButton.href; + if (html.dir == 'rtl') { + prev(); + } else { + next(); } break; case 'ArrowLeft': e.preventDefault(); - var previousButton = document.querySelector('.nav-chapters.previous'); - if (previousButton) { - window.location.href = previousButton.href; + if (html.dir == 'rtl') { + next(); + } else { + prev(); } break; }