summaryrefslogtreecommitdiff
path: root/public/scrollbar.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/scrollbar.js')
-rw-r--r--public/scrollbar.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/public/scrollbar.js b/public/scrollbar.js
index da6aded..2218b55 100644
--- a/public/scrollbar.js
+++ b/public/scrollbar.js
@@ -50,3 +50,27 @@ function initScrollbox(box) {
}
document.querySelectorAll("[data-scrollbox]").forEach(initScrollbox);
+
+// Vim style j/k scrolling
+document.addEventListener("keydown", (e) => {
+ // Don't scroll in input elements
+ const tag = document.activeElement.tagName;
+ if (
+ ["INPUT", "TEXTAREA", "SELECT"].includes(tag) ||
+ document.activeElement.isContentEditable
+ ) {
+ return;
+ }
+
+ // Only work for "j" and "k", no ctrl/alt/shift
+ if (e.ctrlKey || e.altKey || e.metaKey) return;
+
+ const dir = key === "j" ? step : -step;
+ const scrollTarget = document.scrollingElement || document.documentElement;
+ const scrollAmount = 100; // in pixels
+ if (scrollTarget && scrollTarget.scrollHeight > scrollTarget.clientHeight) {
+ scrollTarget.scrollBy({ top: dir, behavior: "auto" });
+ } else {
+ window.scrollBy({ top: dir, behavior: "auto" });
+ }
+});