summaryrefslogtreecommitdiff
path: root/public/scrollbar.js
diff options
context:
space:
mode:
authorKyren223 <contact@kyren.codes>2026-10-10 06:24:00 +0300
committerKyren223 <contact@kyren.codes>2026-10-10 06:24:00 +0300
commitd0176451865aba0a6a07c563edfdcdde6cd83c73 (patch)
tree0e2eb88a1a579138d9600d9870e49cb6ef915330 /public/scrollbar.js
parentb354565619802f0d3bc5035d89237d5c1f67434e (diff)
Fix scrollbar
Diffstat (limited to 'public/scrollbar.js')
-rw-r--r--public/scrollbar.js21
1 files changed, 14 insertions, 7 deletions
diff --git a/public/scrollbar.js b/public/scrollbar.js
index 2218b55..b297d76 100644
--- a/public/scrollbar.js
+++ b/public/scrollbar.js
@@ -1,4 +1,8 @@
function initScrollbox(box) {
+ // Guard against double-initialization
+ if (box.dataset.initialized) return;
+ box.dataset.initialized = "true";
+
const area = box.querySelector("[data-scroll-area]");
const track = box.querySelector("[data-scroll-track]");
const thumb = box.querySelector("[data-scroll-thumb]");
@@ -51,23 +55,26 @@ function initScrollbox(box) {
document.querySelectorAll("[data-scrollbox]").forEach(initScrollbox);
-// Vim style j/k scrolling
+document.addEventListener("htmx:afterSettle", () => {
+ document.querySelectorAll("[data-scrollbox]").forEach(initScrollbox);
+});
+
document.addEventListener("keydown", (e) => {
- // Don't scroll in input elements
- const tag = document.activeElement.tagName;
+ const tag = document.activeElement?.tagName;
if (
["INPUT", "TEXTAREA", "SELECT"].includes(tag) ||
- document.activeElement.isContentEditable
+ document.activeElement?.isContentEditable
) {
return;
}
- // Only work for "j" and "k", no ctrl/alt/shift
if (e.ctrlKey || e.altKey || e.metaKey) return;
+ if (e.key !== "j" && e.key !== "k") return;
- const dir = key === "j" ? step : -step;
- const scrollTarget = document.scrollingElement || document.documentElement;
const scrollAmount = 100; // in pixels
+ const dir = e.key === "j" ? scrollAmount : -scrollAmount;
+ const scrollTarget = document.scrollingElement || document.documentElement;
+
if (scrollTarget && scrollTarget.scrollHeight > scrollTarget.clientHeight) {
scrollTarget.scrollBy({ top: dir, behavior: "auto" });
} else {