diff --git a/frontend/src/components/contextmenu.svelte b/frontend/src/components/contextmenu.svelte index ae4e266..cd7c736 100644 --- a/frontend/src/components/contextmenu.svelte +++ b/frontend/src/components/contextmenu.svelte @@ -5,6 +5,8 @@ export let position = undefined; const dispatch = createEventDispatcher(); + let selected = -1; + const buttons = []; function close() { dispatch('close'); @@ -14,23 +16,58 @@ fn?.(); close(); } + + function keydown(evt) { + if (evt.key === 'Escape') { + close(); + return; + } + else if (!items?.length) { + return; + } + + let delta = 0; + (evt.key === 'ArrowDown') && delta++; + (evt.key === 'ArrowUp') && delta--; + + selected += delta; + if (selected >= items.length) { + selected = 0; + } + else if (items[selected].separator) { + selected += delta; + } + + buttons[selected]?.focus?.(); + } + + {#if items && position}
- + {/if}