From eb79e190a6dc35a553d5545e425d9cedac739372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannik=20Sch=C3=A4fer?= Date: Tue, 13 Dec 2022 21:59:11 +0100 Subject: [PATCH] Implement Vim key bindings. --- src/ui/ui.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/ui/ui.js b/src/ui/ui.js index 1830f20..91057ef 100644 --- a/src/ui/ui.js +++ b/src/ui/ui.js @@ -830,8 +830,31 @@ var UI = (() => { break; case "Home": newRow = row; + case "KeyH": + dir = "previous"; + case "KeyL": + const presets = row.querySelectorAll("input[class='preset']"); + const currentIndex = [...presets].findIndex((p) => p.checked); + const step = dir === "next" ? 1 : -1; + const len = presets.length; + + for (let i = 1; i < len; i++) { + // Limit nextIndex to [0, len). + const nextIndex = (currentIndex + len + i * step) % len; + + // Skip disabled presets. + if (!presets[nextIndex].disabled) { + const nextPreset = presets[nextIndex]; + nextPreset.focus(); + nextPreset.click(); + break; + } + } + break; + case "KeyK": case "ArrowUp": dir = "previous"; + case "KeyJ": case "ArrowDown": if (!newRow) { this.customize(null);