summaryrefslogtreecommitdiff
path: root/public/scrollbar.js
diff options
context:
space:
mode:
authorKyren223 <contact@kyren.codes>2026-10-09 17:42:43 +0300
committerKyren223 <contact@kyren.codes>2026-10-09 17:42:43 +0300
commit26ac862befb195a9e03e0d554dbe1480d2e55775 (patch)
tree98b1d08c1718759cb6c9522b547f8dd5fc998263 /public/scrollbar.js
parenta7ecfccc8a5f1bb8d0d3ae03dc125672b428f31f (diff)
Foobar
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" });
+ }
+});