diff --git a/README.md b/README.md index 5002fe6..71dc773 100644 --- a/README.md +++ b/README.md @@ -104,12 +104,17 @@ plugin, not just this one. - **Typing** — shows just the character: `g`, `G`, `!`, `5`. - **Modifier combos** — shows every modifier plus the key: `Super Shift G`, `Ctrl C`, `Super Enter`. +- **Combos are a unit** — a combination stays intact no matter the order you + release it: press `Ctrl Shift N`, let go of `Ctrl` first, then `Shift`, + then `N`, and the display keeps showing `Ctrl Shift N` the whole time + (keyviz shrinks key-by-key; this plugin treats the chord as one unit). - **Non-printing keys** — labeled: `Esc`, `Tab`, `F1`, arrows, `Space`. - Modifiers that produce the shifted character (`Shift` with a letter) are folded into the character itself: `Shift + 1` shows `!`. - Key repeat is ignored; a held key shows once. - After the last key is released the combo lingers briefly (1s by default, - keyviz-style "Duration") and then vanishes in one frame — no fade. + keyviz-style "Duration") and then vanishes in one frame — no fade. The + lingering combo is always the last full one, never a partial release state. - In `mode: "bindings"` only combos with a modifier are shown; plain typing stays off screen. diff --git a/key-visualizer.lua b/key-visualizer.lua index b445e5a..4c707de 100644 --- a/key-visualizer.lua +++ b/key-visualizer.lua @@ -145,6 +145,13 @@ local function emit() end end +-- Combos: a combination of keys is treated as a unit. The display only +-- updates on key-down (the combo grows as you press) and when the last key +-- is released (the empty payload starts the panel's linger with the last +-- full combo). Intermediate releases never shrink the display, so the order +-- in which you let go of a shortcut doesn't matter: Ctrl+Shift+N stays +-- Ctrl+Shift+N whether you release Ctrl, Shift, or N first. +-- -- state: 0 = released, 1 = pressed, 2 = repeat (ignored). hl.on("input.keyboard.key", function(keycode, timeMs, state) if state == 2 then return end @@ -158,6 +165,7 @@ hl.on("input.keyboard.key", function(keycode, timeMs, state) end if not found then combo[#combo + 1] = keycode end end + emit() else pressed[keycode] = false if not MODS[keycode] then @@ -168,7 +176,12 @@ hl.on("input.keyboard.key", function(keycode, timeMs, state) end end end + -- Only emit when the last key goes up: intermediate releases keep the + -- full combo on screen (the panel lingers it after the empty payload). + local any_down = false + for _, down in pairs(pressed) do + if down then any_down = true break end + end + if not any_down then emit() end end - - emit() end) diff --git a/manifest.json b/manifest.json index 7e20900..46614c3 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "id": "felixzsh.key-visualizer", "name": "Key Visualizer", - "version": "1.3.3", + "version": "1.4.0", "description": "Shows the keys you press on screen. Great for keybinding tutorials, demos, and screencasts.", "kinds": [ "panel",