3a18dce03f
It works better with alternative Latin-based keyboard layouts
27 lines
801 B
Svelte
27 lines
801 B
Svelte
<!--
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
-->
|
|
<script lang="typescript">
|
|
import { onDestroy } from "svelte";
|
|
import { registerShortcut, getPlatformString } from "lib/shortcuts";
|
|
|
|
export let shortcut: string;
|
|
|
|
const shortcutLabel = getPlatformString(shortcut);
|
|
|
|
let deregister: () => void;
|
|
|
|
function createShortcut({ detail }: CustomEvent): void {
|
|
const mounted: HTMLButtonElement = detail.button;
|
|
deregister = registerShortcut((event: KeyboardEvent) => {
|
|
mounted.dispatchEvent(new MouseEvent("click", event));
|
|
event.preventDefault();
|
|
}, shortcut);
|
|
}
|
|
|
|
onDestroy(() => deregister());
|
|
</script>
|
|
|
|
<slot {createShortcut} {shortcutLabel} />
|