From 41992cd2d5f3b033e31459d61fdcd9d4ee2942ca Mon Sep 17 00:00:00 2001 From: Botato300 Date: Wed, 27 May 2026 22:46:07 -0300 Subject: [PATCH 1/4] fix: scroll the sidebar to the active item when using keyboard shortcuts --- js/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/common.js b/js/common.js index fc17595636..3e43313c0a 100644 --- a/js/common.js +++ b/js/common.js @@ -104,7 +104,7 @@ Mousetrap.bind("b o r k", function () { function cycle(to, from) { from.removeClass("current"); to.addClass("current"); - $.scrollTo(to.offset().top); + to[0].scrollIntoView({ block: "center" }); } function getNextOrPreviousSibling(node, forward) { From 3cc7c73368935878537e559c76919e73d773187e Mon Sep 17 00:00:00 2001 From: Botato300 Date: Thu, 28 May 2026 00:25:32 -0300 Subject: [PATCH 2/4] feat: automatically scroll the sidebar menu to the active item --- js/common.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/common.js b/js/common.js index 3e43313c0a..4ad500fb02 100644 --- a/js/common.js +++ b/js/common.js @@ -688,6 +688,11 @@ $(document).ready(function () { flashMessage($(this)); }); /* }}} */ + + const activeItem = document.querySelector(".layout-menu .current"); + if (activeItem) { + activeItem.scrollIntoView({ block: "center" }); + } }); /* {{{ add-user.php animations */ From 1403dab5c1a86f2643ea185a0f0e05e1a483b8d5 Mon Sep 17 00:00:00 2001 From: Botato300 Date: Fri, 29 May 2026 01:33:35 -0300 Subject: [PATCH 3/4] fix: modify the scroll implementation to prevent it from affecting the window scroll --- js/common.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/js/common.js b/js/common.js index 4ad500fb02..30ad955a95 100644 --- a/js/common.js +++ b/js/common.js @@ -104,7 +104,7 @@ Mousetrap.bind("b o r k", function () { function cycle(to, from) { from.removeClass("current"); to.addClass("current"); - to[0].scrollIntoView({ block: "center" }); + scrollToActiveItem(); } function getNextOrPreviousSibling(node, forward) { @@ -142,6 +142,18 @@ function cycleHeaders(matches, forward) { cycle($(matches[forward ? 0 : matches.length - 1]), $(matches[forward ? matches.length - 1 : 0])); } } + +function scrollToActiveItem() { + const sidebar = document.querySelector(".layout-menu"); + const activeItem = sidebar.querySelector(".current"); + + if (sidebar && activeItem) { + sidebar.scrollTo({ + top: activeItem.offsetTop - sidebar.offsetTop - (sidebar.clientHeight / 2) + (activeItem.clientHeight / 2) + }); + } +} + Mousetrap.bind("j", function () { /* Doc page */ var node = $(".layout-menu .current"); @@ -689,10 +701,7 @@ $(document).ready(function () { }); /* }}} */ - const activeItem = document.querySelector(".layout-menu .current"); - if (activeItem) { - activeItem.scrollIntoView({ block: "center" }); - } + scrollToActiveItem(); }); /* {{{ add-user.php animations */ From 962f2580b100615392a35238f6483f02b71018bb Mon Sep 17 00:00:00 2001 From: Botato300 Date: Fri, 29 May 2026 01:37:51 -0300 Subject: [PATCH 4/4] fix: add the '?.' operator to prevent error --- js/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/common.js b/js/common.js index 30ad955a95..86b4862fd5 100644 --- a/js/common.js +++ b/js/common.js @@ -145,7 +145,7 @@ function cycleHeaders(matches, forward) { function scrollToActiveItem() { const sidebar = document.querySelector(".layout-menu"); - const activeItem = sidebar.querySelector(".current"); + const activeItem = sidebar?.querySelector(".current"); if (sidebar && activeItem) { sidebar.scrollTo({