Use registerShortcut within WithShortcut
This commit is contained in:
parent
b57810556d
commit
dc5b13eeab
1
ts/editor-toolbar/WithShortcut.d.ts
vendored
1
ts/editor-toolbar/WithShortcut.d.ts
vendored
@ -4,4 +4,5 @@ import type { ToolbarItem } from "./types";
|
||||
|
||||
export interface WithShortcutProps {
|
||||
button: ToolbarItem;
|
||||
shortcut: string;
|
||||
}
|
||||
|
@ -6,29 +6,26 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
|
||||
import type { ToolbarItem } from "./types";
|
||||
|
||||
export let button: ToolbarItem;
|
||||
/* export let event: string; */
|
||||
import { onDestroy } from "svelte";
|
||||
import { registerShortcut } from "anki/shortcuts";
|
||||
|
||||
function extend({
|
||||
className,
|
||||
...rest
|
||||
}: DynamicSvelteComponent): DynamicSvelteComponent {
|
||||
export let button: ToolbarItem;
|
||||
export let shortcut: string;
|
||||
|
||||
function extend({ ...rest }: DynamicSvelteComponent): DynamicSvelteComponent {
|
||||
return {
|
||||
...rest,
|
||||
};
|
||||
}
|
||||
|
||||
let deregister;
|
||||
|
||||
function createShortcut({ detail }: CustomEvent): void {
|
||||
const button: HTMLButtonElement = detail.button;
|
||||
|
||||
document.addEventListener("click", () => {
|
||||
const event = new MouseEvent("click");
|
||||
|
||||
if (code === "KeyP") {
|
||||
button.dispatchEvent(event);
|
||||
}
|
||||
});
|
||||
deregister = registerShortcut(() => button.click(), shortcut);
|
||||
}
|
||||
|
||||
onDestroy(() => deregister());
|
||||
</script>
|
||||
|
||||
<svelte:component
|
||||
|
@ -58,7 +58,7 @@ function innerShortcut(
|
||||
}
|
||||
}
|
||||
|
||||
export function shortcut(
|
||||
export function registerShortcut(
|
||||
callback: (event: KeyboardEvent) => void,
|
||||
shortcutString: string
|
||||
): () => void {
|
||||
|
Loading…
Reference in New Issue
Block a user