fix: hotkeys

fixes #20
This commit is contained in:
2024-04-06 19:00:14 +02:00
parent 3af65106bf
commit 4b738bb340
8 changed files with 66 additions and 52 deletions

View File

@@ -2,7 +2,8 @@ import type { Action } from "svelte/action";
import tippy from "tippy.js";
import type { SvelteComponent } from "svelte";
import Tooltip from "$lib/components/Tooltip.svelte";
import hotkeys from "hotkeys-js";
export const hotkeys = new Map<string, HTMLElement>();
export const action: Action<Element, { title?: string; shortcut?: string }> = (
node: Element,
@@ -26,20 +27,15 @@ export const action: Action<Element, { title?: string; shortcut?: string }> = (
});
if (shortcut && node instanceof HTMLElement) {
hotkeys(shortcut, function (keyboardEvent) {
keyboardEvent.preventDefault();
node.click();
});
hotkeys.set(shortcut, node);
}
return {
update(updated) {
title = updated.title;
shortcut = updated.shortcut;
},
destroy() {
tooltip.destroy();
hotkeys.unbind(shortcut);
if (shortcut && node instanceof HTMLElement) {
hotkeys.delete(shortcut);
}
},
};
};