flytta kortkommandon till hotkeys-js

This commit is contained in:
botvid johansson 2025-04-24 15:32:18 +02:00
parent 3b57f22e6e
commit 4e9128c840
3 changed files with 30 additions and 21 deletions

View File

@ -6,8 +6,8 @@
import { clickOutside } from 'svelte-outside'; import { clickOutside } from 'svelte-outside';
import Input from '$lib/components/ui/input/input.svelte'; import Input from '$lib/components/ui/input/input.svelte';
var show = true; var show = true;
const cancelSave = () => true; const cancelSave = () => (appState.open = '');
const handleSave = () => true; const handleSave = () => (appState.open = '');
const close = () => { const close = () => {
if (show == true) { if (show == true) {
appState.open = ''; appState.open = '';
@ -20,16 +20,18 @@
<Card.Root class="mx-auto w-[590px]"> <Card.Root class="mx-auto w-[590px]">
<Card.Header> <Card.Header>
<Card.Title>Konfigurera kortkommandon</Card.Title> <Card.Title>Konfigurera kortkommandon</Card.Title>
<Card.Description></Card.Description> <Card.Description
>Work in progress: Än så länge är det här bara en referens över befintliga kommandon.
</Card.Description>
</Card.Header> </Card.Header>
<Card.Content class="mx-auto"></Card.Content> <Card.Content class="mx-auto"></Card.Content>
<div class="grid grid-cols-5 gap-2"> <div class="mx-2 grid grid-cols-5 gap-2">
{#each hotkeys as hotkey} {#each hotkeys as hotkey}
<div class="col-span-4"> <div class="col-span-4">
<Input class="w-[290px]" readonly bind:value={hotkey[1].name} /> <Input readonly bind:value={hotkey[1].name} />
</div> </div>
<div> <div>
<Input class="w-[100px]" bind:value={hotkey[0]} /> <Input class="mx-" readonly bind:value={hotkey[0]} />
</div> </div>
{/each} {/each}
</div> </div>

View File

@ -110,3 +110,19 @@ hotkeys.set("Escape", {
appState.open = "" appState.open = ""
} }
}) })
hotkeys.set("CTRL+0", {
name: "Visa 'Välj förkortningslistor'",
action: (e) => {
e.preventDefault();
appState.open = "selectLists";
}
})
hotkeys.set("CTRL+K", {
name: "Visa 'Konfigurera kortkommandon'",
action: (e) => {
e.preventDefault();
appState.open = "hotkeys";
}
});

View File

@ -9,7 +9,7 @@
import Menu from '../components/menu.svelte'; import Menu from '../components/menu.svelte';
import { Button } from '$lib/components/ui/button'; import { Button } from '$lib/components/ui/button';
import { appState, shortforms } from '$lib/stores.svelte'; import { appState, shortforms } from '$lib/stores.svelte';
import { initHotkeys, registerAllHotkeys, registerHotkeys } from '$lib/hotkeys'; import { initHotkeys, registerAllHotkeys, registerHotkey } from '$lib/hotkeys';
let loaded = false; let loaded = false;
$effect(() => { $effect(() => {
appState.open; appState.open;
@ -35,25 +35,16 @@
import { Toaster } from '$lib/components/ui/sonner'; import { Toaster } from '$lib/components/ui/sonner';
import { onDestroy, onMount } from 'svelte'; import { onDestroy, onMount } from 'svelte';
import { preventDefault } from 'svelte/legacy'; import { preventDefault } from 'svelte/legacy';
import { hotkeys } from '$lib/hotkey-actions';
let textarea: HTMLTextAreaElement | undefined = $state(); let textarea: HTMLTextAreaElement | undefined = $state();
onMount(() => { onMount(() => {
appState.open = 'hotkeys'; appState.open = 'hotkeys';
initHotkeys({ scope: 'main', filterInputs: false }); initHotkeys({ scope: 'main', filterInputs: false });
registerHotkeys( hotkeys.forEach((handler, key) => {
{ console.log(key, handler.action);
'ctrl+0': (e) => { registerHotkey(key, handler.action, { scope: 'main', preventDefault: true });
console.log('ctrl+0'); });
e.preventDefault();
appState.open = 'selectLists';
},
'ctrl+k': (e) => {
e.preventDefault();
appState.open = 'hotkeys';
}
},
{ scope: 'main', preventDefault: true }
);
}); });
onDestroy(() => { onDestroy(() => {
registerAllHotkeys(); registerAllHotkeys();