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 {
|
export interface WithShortcutProps {
|
||||||
button: ToolbarItem;
|
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 { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
|
||||||
import type { ToolbarItem } from "./types";
|
import type { ToolbarItem } from "./types";
|
||||||
|
|
||||||
export let button: ToolbarItem;
|
import { onDestroy } from "svelte";
|
||||||
/* export let event: string; */
|
import { registerShortcut } from "anki/shortcuts";
|
||||||
|
|
||||||
function extend({
|
export let button: ToolbarItem;
|
||||||
className,
|
export let shortcut: string;
|
||||||
...rest
|
|
||||||
}: DynamicSvelteComponent): DynamicSvelteComponent {
|
function extend({ ...rest }: DynamicSvelteComponent): DynamicSvelteComponent {
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let deregister;
|
||||||
|
|
||||||
function createShortcut({ detail }: CustomEvent): void {
|
function createShortcut({ detail }: CustomEvent): void {
|
||||||
const button: HTMLButtonElement = detail.button;
|
const button: HTMLButtonElement = detail.button;
|
||||||
|
deregister = registerShortcut(() => button.click(), shortcut);
|
||||||
document.addEventListener("click", () => {
|
|
||||||
const event = new MouseEvent("click");
|
|
||||||
|
|
||||||
if (code === "KeyP") {
|
|
||||||
button.dispatchEvent(event);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDestroy(() => deregister());
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:component
|
<svelte:component
|
||||||
|
@ -58,7 +58,7 @@ function innerShortcut(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shortcut(
|
export function registerShortcut(
|
||||||
callback: (event: KeyboardEvent) => void,
|
callback: (event: KeyboardEvent) => void,
|
||||||
shortcutString: string
|
shortcutString: string
|
||||||
): () => void {
|
): () => void {
|
||||||
|
Loading…
Reference in New Issue
Block a user