From dd59e79f94b88181dabc9ae12da7f6f2a1eda43a Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 8 Aug 2026 23:01:23 +0200 Subject: [PATCH] catalog: scrollFocused driven by keydown arrows (Controller may not own arrows); keeps card visible --- plugin.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/plugin.js b/plugin.js index 41186c8..0ec8abe 100644 --- a/plugin.js +++ b/plugin.js @@ -83,6 +83,16 @@ var body; var grid; + // Keep the focused card visible while navigating down/up (native Lampa behaviour). + function scrollFocused() { + var cont = document.querySelector('.mymovies'); + var el = document.querySelector('.mymovies .card.selector.focus'); + if (cont && el) { + var delta = el.getBoundingClientRect().top - cont.getBoundingClientRect().top; + cont.scrollTop += delta - 100; + } + } + this.create = function (b) { body = b; comp._onKey = function (e) { @@ -90,6 +100,9 @@ e.preventDefault(); e.stopPropagation(); Lampa.Activity.backward(); + } else if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { + // After Navigator moves focus, keep the focused card visible. + setTimeout(scrollFocused, 30); } }; document.addEventListener('keydown', comp._onKey, true); @@ -147,18 +160,10 @@ }, left: function () { if (Navigator.canmove('left')) Navigator.move('left'); else Lampa.Controller.toggle('menu'); }, right: function () { Navigator.move('right'); }, - up: function () { Navigator.move('up'); setTimeout(scrollFocused, 30); }, - down: function () { Navigator.move('down'); setTimeout(scrollFocused, 30); }, + up: function () { Navigator.move('up'); }, + down: function () { Navigator.move('down'); }, back: function () { Lampa.Activity.backward(); } }); - function scrollFocused() { - var cont = document.querySelector('.mymovies'); - var el = document.querySelector('.mymovies .card.selector.focus'); - if (cont && el) { - var delta = el.getBoundingClientRect().top - cont.getBoundingClientRect().top; - cont.scrollTop += delta - 100; - } - } Lampa.Controller.toggle('content'); };