From d35e03f0b07d1af3fecd51cd4ca42a76c300db23 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 5 Aug 2026 11:58:50 +0200 Subject: format: run prettier --- src/selection.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src/selection.js') diff --git a/src/selection.js b/src/selection.js index bfaebc0..b7968af 100644 --- a/src/selection.js +++ b/src/selection.js @@ -27,7 +27,7 @@ async function initSelection(idPrefix, fetchCandidates, fmtCandidate, onSelectio let currentFocus = -1; let visibleItems = []; function setActive() { - visibleItems.forEach(item => item.classList.remove("active")); + visibleItems.forEach((item) => item.classList.remove("active")); if (currentFocus >= 0 && visibleItems[currentFocus]) { visibleItems[currentFocus].classList.add("active"); } @@ -37,11 +37,11 @@ async function initSelection(idPrefix, fetchCandidates, fmtCandidate, onSelectio const item = document.createElement("li"); item.candidate = candidate; item.innerHTML = fmtCandidate(candidate); - item.style.display = 'none'; + item.style.display = "none"; - item.addEventListener('click', function() { + item.addEventListener("click", function () { sel.value = ""; - sel.dispatchEvent(new Event('keyup')); + sel.dispatchEvent(new Event("keyup")); onSelection(candidate); }); @@ -49,9 +49,8 @@ async function initSelection(idPrefix, fetchCandidates, fmtCandidate, onSelectio items.push(item); } - sel.addEventListener('keyup', function(e) { - if ((["ArrowDown", "ArrowUp", "Enter"]).includes(e.key)) - return; + sel.addEventListener("keyup", function (e) { + if (["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return; const filter = sel.value.toLowerCase(); visibleItems = []; @@ -63,10 +62,10 @@ async function initSelection(idPrefix, fetchCandidates, fmtCandidate, onSelectio visibleItems.push(item); // Highlight matched text - const regex = new RegExp(`(${filter})`, 'gi'); + const regex = new RegExp(`(${filter})`, "gi"); item.innerHTML = item.textContent.replace( regex, - "$1" + "$1", ); } else { item.style.display = "none"; @@ -82,26 +81,23 @@ async function initSelection(idPrefix, fetchCandidates, fmtCandidate, onSelectio noResults.style.display = visibleItems.length || filter === "" ? "none" : "block"; }); - clearBtn.addEventListener('click', function() { + clearBtn.addEventListener("click", function () { sel.value = ""; - sel.dispatchEvent(new Event('keyup')); // reset list + sel.dispatchEvent(new Event("keyup")); // reset list sel.focus(); }); - sel.addEventListener('keydown', function(e) { + sel.addEventListener("keydown", function (e) { if (e.key === "ArrowDown" || e.key === "ArrowUp") { - if(e.key === "ArrowDown") - currentFocus = (currentFocus + 1) % visibleItems.length; - else - currentFocus = (currentFocus - 1 + visibleItems.length) % visibleItems.length; + if (e.key === "ArrowDown") currentFocus = (currentFocus + 1) % visibleItems.length; + else currentFocus = (currentFocus - 1 + visibleItems.length) % visibleItems.length; setActive(); e.preventDefault(); } else if (e.key === "Enter") { if (currentFocus > -1 && visibleItems[currentFocus]) { - const visibleItem = visibleItems[currentFocus]; sel.value = ""; - sel.dispatchEvent(new Event('keyup')); + sel.dispatchEvent(new Event("keyup")); onSelection(visibleItem.candidate); } e.preventDefault(); -- cgit v1.2.3