From 3c164a36cb8104853b7272d3de2f85057af28a49 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Wed, 19 Jun 2024 23:55:30 +0200 Subject: select sections when quickly switching to them This is for when you use Q/E on keyboard or the bumper buttons on a gamepad, this prevents your selection from being on an element that is no longer visible. --- src/app/js/launcher.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/app/js/launcher.js b/src/app/js/launcher.js index dc99792..546b647 100644 --- a/src/app/js/launcher.js +++ b/src/app/js/launcher.js @@ -203,18 +203,30 @@ launcher.relative_section = (direction) => { } } + let new_section; + // if we're going left, and a previous section was found, click it if (direction == "left" && prev_section) { - prev_section.click(); + new_section = prev_section; } else if (direction == "right") { // click the next section, if one was found, otherwise just // assume that the first section is the next section, as the // active section is likely just the last section, so we wrap // around instead if (next_section) { - next_section.click(); + new_section = next_section; } else if (sections[0]) { - sections[0].click(); + new_section = sections[0]; + } + } + + if (new_section) { + new_section.click(); + + // if there's an active selection, we select the new section, as + // that selection may be in a section that's now hidden + if (document.querySelector(".active-selection")) { + navigate.selection(new_section); } } } -- cgit v1.2.3