From 26ac862befb195a9e03e0d554dbe1480d2e55775 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Fri, 9 Oct 2026 17:42:43 +0300 Subject: Foobar --- public/scrollbar.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'public/scrollbar.js') 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" }); + } +}); -- cgit v1.3.1